I have not been able to decipher how to use mesh.Vertices.GetEnumerator in the following code to speed up copying the vertices of one mesh into another mesh. I use this code to combine several meshes.
import rhinoscriptsyntax as rs
from Rhino.Geometry import Mesh, Point3f
from scriptcontext import doc
P3f = Point3f
# Part 1 Works using .Add to add vertices to new_mesh which is used to combine several meshes.
# Define very simple mesh.
meshGeo = Mesh()
meshGeo.Vertices.Add(P3f(0.0,0.0,0.0))
meshGeo.Vertices.Add(P3f(1.0,1.0,0.0))
meshGeo.Vertices.Add(P3f(1.0,-1.0,0.0))
meshGeo.Faces.AddFace(0,1,2)
meshGeo.Vertices.Add(P3f(1.0,1.0,0.0))
meshGeo.Vertices.Add(P3f(2.0,0.0,0.0))
meshGeo.Vertices.Add(P3f(1.0,-1.0,0.0))
meshGeo.Faces.AddFace(3,4,5)
vertices = meshGeo.Vertices
vcount = vertices.Count
faces = meshGeo.Faces
# At start, set offset to 0. For each following mesh to be combined, set offset to sum of vcount of prior combined meshes.
offset = 0
# Define new mesh for combining several meshes (with only 1 combined in this example).
new_meshGeo = Mesh()
new_vertices = new_meshGeo.Vertices
new_faces = new_meshGeo.Faces
for i in xrange(vcount): new_vertices.Add(vertices[i])
f_indices = faces.ToIntArray(True)
for i in xrange(faces.Count):
ii = 3*i
i1,i2,i3 = f_indices[ii+offset], f_indices[ii+1+offset], f_indices[ii+2+offset]
new_faces.AddFace(i1,i2,i3)
print new_meshGeo.IsValid
doc.Objects.AddMesh(new_meshGeo)
[rs.ViewDisplayMode(view, 'Wireframe') for view in rs.ViewNames()]
# Part 2 Fails using .AddVertices with ienumberator obtained from mesh to be added to new_mesh
# Define very simple mesh.
meshGeo = Mesh()
meshGeo.Vertices.Add(P3f(3.0,0.0,0.0))
meshGeo.Vertices.Add(P3f(4.0,1.0,0.0))
meshGeo.Vertices.Add(P3f(4.0,-1.0,0.0))
meshGeo.Faces.AddFace(0,1,2)
meshGeo.Vertices.Add(P3f(4.0,1.0,0.0))
meshGeo.Vertices.Add(P3f(5.0,0.0,0.0))
meshGeo.Vertices.Add(P3f(4.0,-1.0,0.0))
meshGeo.Faces.AddFace(3,4,5)
vertices = meshGeo.Vertices
vcount = vertices.Count
faces = meshGeo.Faces
new_meshGeo = Mesh()
new_vertices = new_meshGeo.Vertices
new_faces = new_meshGeo.Faces
# Get Ienumerator for vertices.
ienumerator = vertices.GetEnumerator()
print ienumerator
new_vertices.AddVertices(ienumerator) # This line fails with message: expected IEnumerable[Point3f], got <GetEnumerator>d__72
f_indices = faces.ToIntArray(True)
for i in xrange(faces.Count):
ii = 3*i
i1,i2,i3 = f_indices[ii+offset], f_indices[ii+1+offset], f_indices[ii+2+offset]
new_faces.AddFace(i1,i2,i3)
print new_meshGeo.IsValid
doc.Objects.AddMesh(new_meshGeo)
[rs.ViewDisplayMode(view, 'Wireframe') for view in rs.ViewNames()]
The code in Part 2 above fails for the line:
new_vertices.AddVertices(ienumerator)
with the message:
Message: expected IEnumerable[Point3f], got <GetEnumerator>d__72
Does someone know how to fix this?
Regards,
Terry.