Skip to content

Commit

Permalink
slightly improved ply loading
Browse files Browse the repository at this point in the history
  • Loading branch information
jimy-byerley committed May 8, 2022
1 parent 06ca708 commit 290240a
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions madcad/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,14 @@ def ply_read(file, **opts):
mesh = Mesh()

data = PlyData.read(file)
index = {}
for i,e in enumerate(data.elements):
index[e.name] = i
if 'vertex' not in index: raise FileFormatError('file must have a vertex buffer')
if 'face' not in index: raise FileFormatError('file must have a face buffer')
if 'vertex' not in data: raise FileFormatError('file must have a vertex buffer')
if 'face' not in data: raise FileFormatError('file must have a face buffer')

# collect points
mesh.points = typedlist(data.elements[index['vertex']].data.astype('f8, f8, f8'), dtype=vec3)
mesh.points = typedlist(data['vertex'].data.astype('f8, f8, f8'), dtype=vec3)

# collect faces
faces = data.elements[index['face']].data
faces = data['face'].data
if faces.dtype.names[0] == 'vertex_indices':
for face in faces['vertex_indices']:
#print(' ', type(face), face, face.dtype, face.strides)
Expand All @@ -127,7 +124,7 @@ def ply_read(file, **opts):
elif len(face) > 3: # quad or other extended face
mesh += triangulation.triangulation_outline(Wire(mesh.points, face))
else:
mesh.faces = numpy_to_typedlist(faces.astype('u4', copy=False), dtype=uvec4)
mesh.faces = numpy_to_typedlist(faces.astype('u4'), dtype=uvec3)

# collect tracks
if 'group' in faces.dtype.names:
Expand Down

0 comments on commit 290240a

Please sign in to comment.