I know how to create a mesh with mutliple submeshes at runtime, but if I want to modify a submesh, I think I have to clear all of the mesh's geometry.
I found no obvious way to clear one single submesh. Is there any? And if not: What's the point in submeshes then, only the multiple materials?
And how do I do objects with a lot of individually changing parts then? Creating one mesh for each part just kills my performance.
Thanks so far! More details: I'm not trying to animate something. The mesh in question is my game level: It represents a cube of earth, composed of many smaller blocks (e.g. 16x16x16 blocks) in which the player can dig in, thus removing some blocks. Each block has geometry according to its neighbouring blocks - to put it easy: there is a wall on every of its six sides where there is no solid neighbour block. Everytime a block is removed, I change the mesh/submesh of the removed block and its neighbour blocks to depict the new state. I tried several approaches:
having one mesh for every block - total overkill, bad overall fps
having one mesh for every layer of blocks - worked so far, but bad fps on a change
having one mesh for the entire cube, with an own submesh for each block - can't clear submeshes, so that's pointless
Maybe I should try an octree approach with a mesh for each cluster of 2x2x2 blocks. The ability to clear a submesh would just make it so much easier for me. Is this a feature we can expect to be added to Unity sometime in the near future?
Yes, the main point of sub-meshes is to be able to use different Materials on different parts of the mesh.
If your goal is really to "delete a submesh" then yes, the only way to do this is to re-write the vertex list to omit those vertices used by that submesh, and re-write the face list using SetTriangles to omit the faces used by that submesh.
However, I suspect that if you described what you're trying to achieve in a broader sense, it may turn out that there's a better way of reaching your goal. If you have an object with lots of individually changing parts, you'll need to describe in more detail exactly what this object is, and how and why the individually moving parts need to change. We could then suggest the best ways of achieving this. Is it simply that you're trying to do vertex animation on a very large number of models?
More detail please! (then we might be able to help you!)
With imported models that contain submeshes, each submesh is a GameObject. Is that not the case with the submeshes you are creating? If it is, you can either enable/disable the submesh's game object using their active property, or you could just destroy them altogether.
i think there is no way to that that.
you can create multiple meshes and then combine them into a single mesh with meshcombiner script found in unity's standard assets or a more advanced one for skinned meshes found in unify community wiki here . if you want to make customizable avatars or things like that see the example project for how to combine meshes in multiple gameobjects and parrenting.
This might be what you want, to create a new mesh from one mesh's subMesh, and then assign the new mesh to your renderer. I've put a sample code of creating new mesh from some mesh's subMesh in the wiki: