Hello,
I am using Metashape in python as part of a bigger python project.
I would like to access to the Models attributes (vertices, faces, texture coordinates) in numpy ndarrays.
For the moment, I loop over the vertices/faces/texture_coords like so:
# Vertices
verts = []
for v in model.vertices:
c = v.coord
verts.append([c.x, c.y, c.z])
verts = np.array(verts)
# Faces
tris = []
for f in model.faces:
tris .append(f.vertices)
tris = np.array(tris )
# Texture coordinates
uvs= []
for tv in model.tex_vertices:
uvs.append(tv.coord)
uvs= np.array(uvs)
But it is not optimized at all, so I would like to know if there is a way to access this data in faster way ?
As subsidiary question, when aligning the chunks for example :
doc.alignChunks(reference=0, method=2, fit_scale=True)
the vertices of the Model are not affected by the alignment.
In fact, I have to apply the transforms manually, vertex by vertex :
for chunk in doc.chunks:
model = chunk.models[0]
matrix = chunk.transform.matrix
for i, v in enumerate(model.vertices):
model.vertices[i].coord = matrix.mulp(v.coord)
Is there a better solution for this too ?
Thanks,
Glenn