I'm creating a 3D mesh procedurally using Unity. I trying to search for ways to improve…
- User
I'm creating a 3D mesh procedurally using Unity. I trying to search for ways to improve performances of the mesh generation. I'm using the Mesh.CombineMeshes method to combine hundreds of CombineInstance with the same mesh, only their position, rotation and scale change. I'm frequently updating the mesh (mutiple times per second) and each time I need to entirly rebuild it using CombineMeshes. But only a small fraction of CombineInstance differ each time, some are removed, some are new and some see their scale change. There must be a way to optimize the mesh construction by "recycling" the part of the previous mesh that stay unmodified. Can you first rewrite my problem to see if you understood it well?
- Assistant
You're working on procedurally generating a 3D mesh in Unity and are currently using the
Mesh.CombineMeshesmethod to merge hundreds ofCombineInstanceobjects. Each instance consists of the same mesh but with distinct position, rotation, and scale transformations applied.Your mesh needs frequent updates, multiple times per second, which requires you to completely rebuild it with
CombineMeshes. However, with each update, only a subset of theCombineInstanceobjects is altered—some are added or removed while others have their scale changed. You're seeking a way to optimize this process by reusing the unchanged portions of the mesh from the previous state instead of completely regenerating it every time. - User
Exactly. Do you see a way to achieve this?
- Assistant
To optimize the mesh generation process in Unity and avoid the complete reconstruction of the mesh when only a small portion changes, you can consider the following strategies:
- User
Can you write me a script example of suggestion 1?
- Assistant
- User
Can you write me a script example of suggestion 3?
- Assistant