Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by timcommandeur · May 15, 2013 at 01:59 PM · meshrenderingvoxels

Voxels engine chunk mesh max vertices problem

Hey all,

I'm currently working on a voxel engine like minecraft in Unity. Right now i have a chunk that contains creates a mesh based on the cubes inside. The problem is that a mesh cannot contain more than 65000 vertices, this disallows the chunk to have more than somewhere like 12x12x12 cubes.

My question is if there is a way around this or if I have to take a different approach than having the entire chunk be one mesh (Mobs etc. will not be included in the chunk mesh, it's just the cubes.).

The mesh creating part of the chunk looks as follows:

     /// 
     /// Creates the mesh.
     /// 
     public void CreateMesh()
     {
         int x;
         int y;
         int z;
         
         for (x = 0; x < CHUNK_SIZE; ++x)
         {
             for (y = 0; y < CHUNK_SIZE; ++y)
             {
                 for (z = 0; z < CHUNK_SIZE; ++z)
                 {
                     // If the block is inactive it should not be drawn.
                     if (blocks[x,y,z].IsActive == false)
                     {
                         continue;
                     }
                     
                     CreateCube(x, y, z);
                 }
             }
         }
         
         mesh.vertices = positions.ToArray();
         mesh.triangles = indices.ToArray();
         mesh.uv = uvs.ToArray();
         mesh.RecalculateNormals();
         
         Color[] colors = new Color[mesh.vertexCount];
         for (int i = 0; i < colors.Length; i++)
         {
             colors[i] = new Color(1.0f, 1.0f, 1.0f);
         }
         mesh.colors = colors;
     }
     
     /// 
     /// Updates the mesh.
     /// 
     public void UpdateMesh()
     {
         mesh.Clear();
         CreateMesh();
     }
     
     /// 
     /// Creates a cube.
     /// 
     /// <param>
     /// X.
     /// 
     /// <param>
     /// Y.
     /// 
     /// <param>
     /// Z.
     /// 
     public void CreateCube(int x, int y, int z)
     {
         x = (x * BLOCK_RENDER_SIZE) + chunkX * CHUNK_RENDER_SIZE;
         y = (y * BLOCK_RENDER_SIZE) + chunkY * CHUNK_RENDER_SIZE;
         z = (z * BLOCK_RENDER_SIZE) + chunkZ * CHUNK_RENDER_SIZE;
         
         Vector3 p1 = new Vector3(x - (BLOCK_RENDER_SIZE / 2), y - (BLOCK_RENDER_SIZE / 2), z + (BLOCK_RENDER_SIZE / 2));
         Vector3 p2 = new Vector3(x + (BLOCK_RENDER_SIZE / 2), y - (BLOCK_RENDER_SIZE / 2), z + (BLOCK_RENDER_SIZE / 2));
         Vector3 p3 = new Vector3(x + (BLOCK_RENDER_SIZE / 2), y + (BLOCK_RENDER_SIZE / 2), z + (BLOCK_RENDER_SIZE / 2));
         Vector3 p4 = new Vector3(x - (BLOCK_RENDER_SIZE / 2), y + (BLOCK_RENDER_SIZE / 2), z + (BLOCK_RENDER_SIZE / 2));
         Vector3 p5 = new Vector3(x + (BLOCK_RENDER_SIZE / 2), y - (BLOCK_RENDER_SIZE / 2), z - (BLOCK_RENDER_SIZE / 2));
         Vector3 p6 = new Vector3(x - (BLOCK_RENDER_SIZE / 2), y - (BLOCK_RENDER_SIZE / 2), z - (BLOCK_RENDER_SIZE / 2));
         Vector3 p7 = new Vector3(x - (BLOCK_RENDER_SIZE / 2), y + (BLOCK_RENDER_SIZE / 2), z - (BLOCK_RENDER_SIZE / 2));
         Vector3 p8 = new Vector3(x + (BLOCK_RENDER_SIZE / 2), y + (BLOCK_RENDER_SIZE / 2), z - (BLOCK_RENDER_SIZE / 2));
         
         int v1;
         int v2;
         int v3;
         int v4;
         int v5;
         int v6;
         int v7;
         int v8;
         
         // Front.
         v1 = addVertex(p1);
         v2 = addVertex(p2);
         v3 = addVertex(p3);
         v4 = addVertex(p4);
         
         indices.Add(v1);
         indices.Add(v2);
         indices.Add(v3);
         indices.Add(v1);
         indices.Add(v3);
         indices.Add(v4);
         
         // Back.
         v5 = addVertex(p5);
         v6 = addVertex(p6);
         v7 = addVertex(p7);
         v8 = addVertex(p8);
         
         indices.Add(v5);
         indices.Add(v6);
         indices.Add(v7);
         indices.Add(v5);
         indices.Add(v7);
         indices.Add(v8);
         
         // Right.
         v2 = addVertex(p2);
         v5 = addVertex(p5);
         v8 = addVertex(p8);
         v3 = addVertex(p3);
         
         indices.Add(v2);
         indices.Add(v5);
         indices.Add(v8);
         indices.Add(v2);
         indices.Add(v8);
         indices.Add(v3);
         
         // Left.
         v6 = addVertex(p6);
         v1 = addVertex(p1);
         v4 = addVertex(p4);
         v7 = addVertex(p7);
         
         indices.Add(v6);
         indices.Add(v1);
         indices.Add(v4);
         indices.Add(v6);
         indices.Add(v4);
         indices.Add(v7);
         
         // Top.
         v4 = addVertex(p4);
         v3 = addVertex(p3);
         v8 = addVertex(p8);
         v7 = addVertex(p7);
         
         indices.Add(v4);
         indices.Add(v3);
         indices.Add(v8);
         indices.Add(v4);
         indices.Add(v8);
         indices.Add(v7);
         
         // Bottom.
         v6 = addVertex(p6);
         v5 = addVertex(p5);
         v2 = addVertex(p2);
         v1 = addVertex(p1);
         
         indices.Add(v6);
         indices.Add(v5);
         indices.Add(v2);
         indices.Add(v6);
         indices.Add(v2);
         indices.Add(v1);
     }
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

1 Reply

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

Answer by Ebil · May 15, 2013 at 02:15 PM

Hey you should check the Marching Cubes algorithmus http://de.wikipedia.org/wiki/Marching_Cubes

Comment
Add comment · Show 2 · 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 Bunny83 · May 15, 2013 at 02:30 PM 0
Share

Yes, basically you only need to add those faces which aren't occluded by a neighbor block. However if you want to implement transparent blocks (like in $$anonymous$$ecraft) the worst case scenario is that you have a full chunk. That means you have to split a chunk into smaller pieces if the count gets too high.

Take a look at the $$anonymous$$inecraft starter package

avatar image timcommandeur · May 15, 2013 at 06:41 PM 0
Share

Thanks guys :)

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

15 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

Related Questions

How to split a large textured mesh of a campus in unity using LOD(Level of Detail) management ,and/or visibility culling? 0 Answers

Unknow verticles when look down 1 Answer

Plane is not rendered when look up 1 Answer

Performance Question 1 Answer

A mesh behind other meshes appears above depending on viewing distance. 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