- Home /
Making a reference to specific vertices so i can manipulate them after used Mesh.CombineMesh
Im using Mesh.CombineMeshes with cube meshes to create a single Mesh for performance reasons.
When i assining the single meshes to the CombineInstance, is it possible to create a reference to the Mesh, so i can changing there values to recalculate or deleting single parts out of it?
CombineInstance[] combine = new CombineInstance[GameObjectArray.lenght];
for (int i = 0; i < GameObjectArray.lenght; i++)
{
MeshFilter mF = GameObjectArray[i].GetComponent<MeshFilter>();
combine[meshCount].mesh = mF.mesh;
combine[meshCount].transform = GameObjectArray[i].transform.localToWorldMatrix;
// can i somewhere here create a reference in any way to change single parts of the mesh afterwards
GameObject.Destroy(GameObjectArray[i]);
}
Mesh mesh = mesh.CombineMeshes(combine);
Comment
Best Answer
Answer by jonas-echterhoff · Jul 09, 2010 at 01:14 PM
What would probably work is to count the vertices in each source mesh and add them to get the start index of vertices in the destination mesh.
like this:
CombineInstance[] combine = new CombineInstance[GameObjectArray.lenght];
int[] vertexIndices = new int[ameObjectArray.lenght];
int vertexIndex = 0;
for (int i = 0; i < GameObjectArray.lenght; i++)
{
MeshFilter mF = GameObjectArray[i].GetComponent<MeshFilter>();
combine[meshCount].mesh = mF.mesh;
combine[meshCount].transform = GameObjectArray[i].transform.localToWorldMatrix;
vertexIndices = vertexIndex;
vertexIndex += mf.mesh.vertices.Length;
GameObject.Destroy(GameObjectArray[i]);
}
Mesh mesh = mesh.CombineMeshes(combine);
Then for each source mesh, you can edit the vertices at vertexIndices[i] in the destination Mesh.
Thanks for the answer! I will try this as soon as possible and tell you about my results. :)
Your answer
![](https://koobas.hobune.stream/wayback/20220613064223im_/https://answers.unity.com/themes/thub/images/avi.jpg)