Unity combine meshes and interact dynamically with them

Viewed 25

My question is focused around the interaction with meshes.

I have a large number of similar (but not completely identical) objects that I want to render. In addition, I would like to be able to color and move the objects individually.

What I have done so far:

I create cylinders of different length and size that initially have the same material (so they all got the same color,..). Since I create more than 10,000 of them, the render performance suffers. For this reason I combine the individual meshes with CombineInstance to a whole mesh. Now I want to interact with certain cylinders, e.g. move or recolor them.

What I am currently doing is saving the vertices Ids that belong to each individual mesh. This would allow me to move certain cylinders throughout the combined mesh. But with the current Standard Shader i can't use the vertex colors to color specific cylinders (individual meshes) of the combined mesh. So currently i doing something like in these [1], [2] posts. But these posts are pretty old, is there maybe a more performant way that still let me interact with multiple objects?

Short summary of the questions:

  • How should i render/represent many objects in Unity if i want to move/color them dynamically?
    • Would it be a good idea to remove objects that are currently in use from the combined mesh and display them as a separate gameobject and convert them back after interaction?
    • Is there a way to combine them and still have the meshes somehow independet from each other?
  • If i want to do it on a mobile device (i.e., Hololens 2 with MRTK) which has no acces to a high performant GPU, what tricks could i use to still interact in real time (high FPS)?
1 Answers

You could probably take advantage of Graphics.DrawMeshInstancedIndirect. The performance should be pretty much at the same level as mesh combination with the added benefit of being able to control different aspects of specific objects thru ComputeBuffers.

Related