• 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 ProgramYourFace · Sep 20, 2013 at 05:31 AM · terrainoptimizationvertexvoxel

Optimization problems

So i am having this really bad optimization problem and i was thinking people on the forums could help.alt text

Note: the inside the mesh its empty its just the out side. it would be nice to reduce the verts by like 5000. This is the script i use to generate a face for a chunk. public void DrawBrick(int x, int y, int z, byte block) {

         Vector3 start = new Vector3(x, y, z);
         Vector3 offset1, offset2;
         
         if (IsTransparent(x, y - 1, z))
         {
             offset1 = Vector3.left;
             offset2 = Vector3.back;
             DrawFace(start + Vector3.right, offset1, offset2, block);
         }
         
         if (IsTransparent(x, y + 1, z))
         {
             offset1 = Vector3.right;
             offset2 = Vector3.back;
             DrawFace(start + Vector3.up, offset1, offset2, block);
         }
         
         if (IsTransparent(x - 1, y, z))
         {
             offset1 = Vector3.back;
             offset2 = Vector3.down;
             DrawFace(start + Vector3.up, offset1, offset2, block);
         }
         
         if (IsTransparent(x + 1, y, z))
         {
             offset1 = Vector3.forward;
             offset2 = Vector3.down;
             DrawFace(start + Vector3.right + Vector3.up + Vector3.back, offset1, offset2, block);
         }
         
         
         if (IsTransparent(x, y, z - 1))
         {
             offset1 = Vector3.right;
             offset2 = Vector3.down;
             DrawFace(start + Vector3.back + Vector3.up, offset1, offset2, block);
         }
         
         
         if (IsTransparent(x, y, z + 1))
         {
             offset1 = Vector3.left;
             offset2 = Vector3.down;
             DrawFace(start + Vector3.up + Vector3.right, offset1, offset2, block);
         }
         
         
     }
     
     
     public void DrawFace(Vector3 start, Vector3 offset1, Vector3 offset2, byte block)
     {
         int index = verts.Count;
         
         verts.Add (start);
         verts.Add (start + offset1);
         verts.Add (start + offset2);
         verts.Add (start + offset1 + offset2);
         
         BlockType blockType = Terrain.blocks.GetBlock(block);
         float zoom = 0.125F;
         
         Vector2 uvBase = blockType.uv;
         
         if(blockType.sideTexture == true)
         {
             if ((offset2 == Vector3.down))
             {
                 uvBase = blockType.side;
             }
         }
         if(blockType.bottomTexture == true)
         {
             if (!(offset2 == Vector3.down) && !(offset1 == Vector3.right))
             {
                 uvBase = blockType.bottom;
             }
         }
         
         uv.Add(uvBase);
         uv.Add(uvBase + new Vector2(-zoom , 0F));
         uv.Add(uvBase + new Vector2(0F , zoom));
         uv.Add(uvBase + new Vector2(-zoom , zoom));
         
         tris.Add (index + 0);
         tris.Add (index + 1);
         tris.Add (index + 2);
         tris.Add (index + 3);
         tris.Add (index + 2);
         tris.Add (index + 1);
     }

Thank you.

screenshot (2).png (469.6 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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by DaveA · Sep 20, 2013 at 05:34 AM

You may want to look into the Marching Cubes algorithm (google that) which is used in many voxel (minecraft-like) programs. Also I think there's at least one plugin in the Asset Store that can optimize such meshes.

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 ProgramYourFace · Sep 20, 2013 at 03:26 PM 0
Share

Thank you. I'm going to check it out.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

16 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

Related Questions

[Optimization] How can i optimize this voxel terrain more? 2 Answers

Unity Voxel Terrain and structures 0 Answers

Cube World Terrain generation 2 Answers

How to optimize custom grass? 1 Answer

Texture mapping procedural mesh with texture atlas? (Minecraft style terrain gen) 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