Fixed (a little) OBJ Exporter

This commit is contained in:
Thomas FORGIONE 2016-11-30 11:47:21 +01:00
parent d58cabe658
commit 6dec2e79e1
No known key found for this signature in database
GPG Key ID: 2A210FFC062E00C3
1 changed files with 11 additions and 5 deletions

View File

@ -99,6 +99,7 @@ class OBJExporter(Exporter):
super().__init__(model) super().__init__(model)
def __str__(self): def __str__(self):
current_material = ''
string = "" string = ""
for vertex in self.model.vertices: for vertex in self.model.vertices:
@ -118,18 +119,23 @@ class OBJExporter(Exporter):
string += "\n" string += "\n"
for face in self.model.faces: faces = sum(map(lambda x: x.faces, self.model.parts), [])
for face in faces:
if face.material.name != current_material:
current_material = face.material.name
string += "usemtl " + current_material + "\n"
string += "f " string += "f "
arr = [] arr = []
for v in [face.a, face.b, face.c]: for v in [face.a, face.b, face.c]:
sub_arr = [] sub_arr = []
sub_arr.append(str(v.vertex + 1)) sub_arr.append(str(v.vertex + 1))
if v.normal is None: if v.normal is None:
if v.texture is not None: if v.tex_coord is not None:
sub_arr.append('') sub_arr.append('')
sub_arr.append(str(v.texture + 1)) sub_arr.append(str(v.tex_coord + 1))
elif v.texture is not None: elif v.tex_coord is not None:
sub_arr.append(str(v.texture + 1)) sub_arr.append(str(v.tex_coord + 1))
if v.normal is not None: if v.normal is not None:
sub_arr.append(str(v.normal + 1)) sub_arr.append(str(v.normal + 1))
arr.append('/'.join(sub_arr)) arr.append('/'.join(sub_arr))