I am running into a performance problem when I update the vertices of a mesh object (using RhinoCommon API) as per the logic below:
for(int vid = 0; vid < _displayMesh.Vertices.Count; vid++) {
Point3f displVert = _displayMesh.Vertices.ElementAt(vid);
Point3f baseVert = _baseMesh.Vertices.ElementAt(vid);
IS_ManagedVector displVec = displVerts.ElementAt(vid);
displVert.X = (float)(baseVert.X + displVec.GetX() * displScale);
displVert.Y = (float)(baseVert.Y + displVec.GetY() * displScale);
displVert.Z = (float)(baseVert.Z + displVec.GetZ() * displScale);
_displayMesh.Vertices.SetVertex(vid, displVert);
}
All the above objects except the displVec is a Rhino object. _displayMesh and _baseMesh are Rhino meshes. Basically I update the _displayMesh using the vertices of _baseMesh and a vector displVec scaled by displScale. The mesh has 33K vertices and 66K faces. The loop seems to be taking about 2 minutes.
I do have another piece of code which does something similar and updates the mesh normals. Even that is slow. It seems like the getters and setters of the mesh is the cause for the slowness, but I am not sure. Ideally it would be nice if the Mesh or the MeshVertexList class supported such point-wise transformations, so that they will be done natively in Rhino.
Any idea why it is so slow and how I can fix it?
Srini