Hi I have a project where I have a lot of morphed objects. So each frame I am (as the documentation says to) reading the current vertices from the mesh, updating them and then writing them back to the mesh. Same with the normals. This works perfectly and gives the result I want.
The problem is that each frame I am creating the number of vertices worth of Vector3’s x4 (Two source meshes each with vertices and normals). As the number of morphing objects goes up I am finding that the garbage collector shows as quite large spikes in the Inspector as it cleans up these objects and is having a noticeable effect on the performance of my application - making it slightly jerky.
What I would like to do is basically edit the vertices of the mesh directly rather than having to work on a copy of the vertices returned by Mesh.vertices which is discarded each frame.
v0 = m_Meshes[srcIndex].vertices; // these verts are a copy
n0 = m_Meshes[srcIndex].normals;// these norms are a copy
v1 = m_Meshes[dstIndex].vertices;// these verts are a copy
n1 = m_Meshes[dstIndex].normals;// these norms are a copy
for (i=0; i<vdst.Length; i++)
{
vdst[i] = Vector3.Lerp(v0[i], v1[i], t);
ndst[i] = Vector3.Lerp(n0[i], n1[i], t);
}
m_Mesh.vertices = vdst;
m_Mesh.normals = ndst;
m_Mesh.RecalculateBounds();
Thanks in advance
Tom Mulder