Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by MaxIzrinCubeUX · Feb 03, 2020 at 07:30 PM · verticesmarching cubesdynamic mesh

Marching Cubes Dynamic Mesh breaks above certain size

I've implemented the marching cubes algorithm, successfully.
However, it only works so long as the chunk is smaller than 19 x 19 x 19 in size.
For some reason, at that size, the vertices are not in the correct locations, the mesh is lopsided and broken.

Here's the correct output at 18^3:
18 Cubed
The broken output at 19^3:
19 Cubed
As the size increases, more and more of the vertices on one side are compressed into the other.

This is the code that creates the vertices for the mesh.
I tried replacing the algorithm with just filling the entire mesh with triangles to confirm the mesh volume, and that's it really is broken and it's not a mistake with the algorithm, I confirmed that much.
I'm completely lost at this point.
I don't really need the chunks to be that much larger, but I wish I could solve this bug.
Any help is appreciated.

  private Vector3[] InitSharedVertices() {
         var verts = new List<Vector3>();
         var vertsArr = new Vector3[12 * ((size.x - 1) * (size.y - 1) * (size.z - 1))];
 
         for (int i = 0; i < size.x - 1; i++) {
             for (int j = 0; j < size.y - 1; j++) {
                 for (int k = 0; k < size.z - 1; k++) {
                     // 12 points for each cube.
                     // The center of the current cube in local coordinates.
                     var c = new Vector3(halfCubeSize * (2 * i + 1), halfCubeSize * (2 * j + 1), halfCubeSize * (2 * k + 1));
 
                     // Note: Do not change this order.
                     // Bottom - back, left, front, right
                     verts.Add(c + new Vector3(0, -halfCubeSize, -halfCubeSize));
                     verts.Add(c + new Vector3(-halfCubeSize, -halfCubeSize, 0));
                     verts.Add(c + new Vector3(0, -halfCubeSize, halfCubeSize));
                     verts.Add(c + new Vector3(halfCubeSize, -halfCubeSize, 0));
                     // Middle - left back, left front, right front, right back
                     verts.Add(c + new Vector3(-halfCubeSize, 0, -halfCubeSize));
                     verts.Add(c + new Vector3(-halfCubeSize, 0, halfCubeSize));
                     verts.Add(c + new Vector3(halfCubeSize, 0, halfCubeSize));
                     verts.Add(c + new Vector3(halfCubeSize, 0, -halfCubeSize));
                     // Top - back, left, front, right
                     verts.Add(c + new Vector3(0, halfCubeSize, -halfCubeSize));
                     verts.Add(c + new Vector3(-halfCubeSize, halfCubeSize, 0));
                     verts.Add(c + new Vector3(0, halfCubeSize, halfCubeSize));
                     verts.Add(c + new Vector3(halfCubeSize, halfCubeSize, 0));
                 }
             }
         }
 
         return verts.ToArray();
     }


size18cubed.png (38.4 kB)
size19cubed.png (24.0 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Bunny83 · Feb 23, 2020 at 09:13 AM

You probably haven't set yout indexFormat to 32 bit. By default each mesh only has a 16 bit index buffer so a single mesh only supports up to 65536 vertices (in reality it always has been a bit lower). Unity now supports 32 bit index buffers but you have to set this manually before you assign your vertices / indices. Keep in mind that a 32 bit index buffer requires double the memory for the same amount of triangles / primitives.


Note that the indexFormat limits the number of vertices, not the number of triangles / primitives. Though you rarely have much more indices than vertices.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image MaxIzrinCubeUX · Feb 23, 2020 at 09:49 AM 0
Share

At 19 cubed, the mesh has 18 cubed, times 12, vertices: just over 69k. You may be correct, I'll test it in a few hours and get back to you. Thanks a bunch!

avatar image MaxIzrinCubeUX MaxIzrinCubeUX · Feb 23, 2020 at 12:29 PM 0
Share

That was it! Thank you very much!

avatar image Pangamini MaxIzrinCubeUX · Feb 23, 2020 at 12:57 PM 1
Share

I am surprised that you didn't get any error message about that though

avatar image
1

Answer by HotRhodium · Feb 23, 2020 at 10:29 PM

This is a couple weeks old but I think I might have an answer for you. It looks like you are adding every vertex weather it is being used or not. you can only use 65,536 vertices in one mesh. looks like you are adding 12 verts per cube and that is what you would expect but that puts you past 65,536 in one 19X19X19 block. ie 19X19X19X2X6 = 82,308. You still pass 65,536 with your 18X18X18 grid but the errors are either inside the block on on the back of the block. Even if you make chunks of 17X17X17 you may hit some serious performance issues just because of the nature of 3D arrays. Make chunks and see if that helps but 17 is the largest you can go in one mesh but while you are there go for an even 16 (programming joke there).

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image MaxIzrinCubeUX · Feb 26, 2020 at 07:10 AM 0
Share

The 16 bit limit was the problem, but you can surpass it by setting the indexFormat to 32 bit, as the chosen answer points out. As for adding all the vertices, indeed, it's a dynamic mesh that needs to change based on user input, the triangles array is going to change often so those vertices could be used at some point.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

121 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Marching Cubes algorithm help 1 Answer

Dynamic Mesh - Multiple Meshes 0 Answers

why is Unity got more vertices than 3dsmax 1 Answer

Small Vert/Tris count still generating more draw calls than expected 1 Answer

How to add vertices to a cube 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges