Added support for colors in binary ply

This commit is contained in:
Thomas FORGIONE 2017-01-18 10:41:41 +01:00
parent 1113c6d137
commit 9e7d4be17c
No known key found for this signature in database
GPG Key ID: 2A210FFC062E00C3
1 changed files with 37 additions and 4 deletions

View File

@ -325,8 +325,37 @@ class PLYLittleEndianContentParser:
# Add element # Add element
if self.current_element.name == 'vertex': if self.current_element.name == 'vertex':
self.parent.add_vertex(Vertex().from_array(property_values))
vertex = Vertex()
red = None
green = None
blue = None
alpha = None
offset = 0
for property in self.current_element.properties:
if property[0] == 'x':
vertex.x = property_values[offset]
elif property[0] == 'y':
vertex.y = property_values[offset]
elif property[0] == 'z':
vertex.z = property_values[offset]
elif property[0] == 'red':
red = property_values[offset] / 255
elif property[0] == 'green':
green = property_values[offset] / 255
elif property[0] == 'blue':
blue = property_values[offset] / 255
elif property[0] == 'alpha':
alpha = property_values[offset] / 255
offset += 1
self.parent.add_vertex(vertex)
if red is not None:
self.parent.add_color(Color(red, blue, green))
elif self.current_element.name == 'face': elif self.current_element.name == 'face':
@ -356,10 +385,14 @@ class PLYLittleEndianContentParser:
face = Face(*list(map(lambda x: FaceVertex(x), vertex_indices))) face = Face(*list(map(lambda x: FaceVertex(x), vertex_indices)))
counter = 3 counter = 3
if len(tex_coords) > 0:
for face_vertex in [face.a, face.b, face.c]: for face_vertex in [face.a, face.b, face.c]:
face_vertex.tex_coord = len(self.parent.tex_coords) - counter face_vertex.tex_coord = len(self.parent.tex_coords) - counter
counter -= 1 counter -= 1
if material is None and len(self.parent.materials) == 1:
material = self.parent.materials[0]
face.material = material face.material = material
self.parent.add_face(face) self.parent.add_face(face)