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
0
Question by FortisVenaliter · Oct 07, 2015 at 05:06 PM · c#meshdynamic mesh

Is there a memory-efficient solution to dynamic index count in a mesh?

I am implementing a ROAM terrain algorithm which, by it's nature, generates a mesh with frequently changing vertex/index count.

With vertices, I can store an array of the largest used count, and ignore any unused vertices.

With indices, however, there's no way to set the count when applying them to the mesh... you have to have an exact-count array, which requires me to instantiate one every time I apply indices to the mesh.

I know in most DirectX wrappers, you can send an array with an additional count int that tells it how many to actually use. If this were the case, I could work like vertices, where I just have an array big enough for the maximum size. Is there something like this in Unity that I'm not seeing?

For example, this is what I currently have:

 int[] Indices;
 List<int> indices = new List<int>();
 for (int i = 0; i < NextTriangleID; i++)
 {
     if (Triangles.ContainsKey(i))
     {
         Triangle t = Triangles[i];
         if (t.CT0 < 0 && t.CT1 < 0)
         {
             indices.Add(t.V0);
             indices.Add(t.V1);
             indices.Add(t.V2);
         }
     }
 }
 Indices = indices.ToArray();
 Mesh.SetIndices(Indices, MeshTopology.Triangles, 0);

And this is what I'd like to have:

 int[] Indices;
 int IndexCount = 0;
 for (int i = 0; i < NextTriangleID; i++)
 {
     if (Triangles.ContainsKey(i))
     {
         Triangle t = Triangles[i];
         if (t.CT0 < 0 && t.CT1 < 0)
         {
             Indices[IndexCount] = t.V0;
             IndexCount++;
             Indices[IndexCount] = t.V1;
             IndexCount++;
             Indices[IndexCount] = t.V2;
             IndexCount++;
         }
     }
 }
 Mesh.SetIndices(Indices, IndexCount, MeshTopology.Triangles, 0);
Comment
Add comment · Show 3
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 FortisVenaliter · Oct 07, 2015 at 05:12 PM 0
Share

I see now that $$anonymous$$esh.SetTriangles takes in a list... but I don't know if that will just do the same array unboxing in the background?

avatar image Dave-Carlile · Oct 07, 2015 at 05:46 PM 0
Share

As an aside, is there a reason you chose ROA$$anonymous$$? It's not really the best approach for terrain when using modern GPUs - modern as in the past decade - since it's very CPU intensive. You're often better off just throwing all of the triangles at the GPU or using a method more suited to the GPU such as geomipmapping or geoclipmapping.

avatar image FortisVenaliter Dave-Carlile · Oct 07, 2015 at 05:55 PM 0
Share

I'm using ROA$$anonymous$$ on a planetary scale. So, it needs basically infinite precision and procedural elevation generation. Think similar to $$anonymous$$erbal Space Program's planets. Good from close up and afar.

I'm pretty sure those techniques you mentioned require an absolute highest resolution to base off of, but I don't have a maximum there.

0 Replies

· Add your reply
  • Sort: 

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

32 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Converting a mesh to terrain 2 Answers

Spawned Object Gradient Mesh Colors? 2 Answers

Algorithm for automatic mesh creation 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