Updating decimation & adding examples
This commit is contained in:
parent
bd1ba14af7
commit
81b12ca77b
19
decimate.py
19
decimate.py
|
@ -18,15 +18,21 @@ class Decimater(obja.Model):
|
||||||
"""
|
"""
|
||||||
operations = []
|
operations = []
|
||||||
|
|
||||||
|
for (vertex_index, vertex) in enumerate(self.vertices):
|
||||||
|
operations.append(('ev', vertex_index, vertex + 0.25))
|
||||||
|
|
||||||
# Iterate through the vertex
|
# Iterate through the vertex
|
||||||
for (vertex_index, vertex) in enumerate(self.vertices):
|
for (vertex_index, vertex) in enumerate(self.vertices):
|
||||||
|
|
||||||
|
# Iterate through the faces
|
||||||
for (face_index, face) in enumerate(self.faces):
|
for (face_index, face) in enumerate(self.faces):
|
||||||
|
|
||||||
# Delete any face that depends on this vertex
|
# Delete any face related to this vertex
|
||||||
if face_index not in self.deleted_faces:
|
if face_index not in self.deleted_faces:
|
||||||
self.deleted_faces.add(face_index)
|
if vertex_index in [face.a,face.b,face.c]:
|
||||||
operations.append(('face', face_index, face))
|
self.deleted_faces.add(face_index)
|
||||||
|
# Add the instruction to operations stack
|
||||||
|
operations.append(('face', face_index, face))
|
||||||
|
|
||||||
# Delete the vertex
|
# Delete the vertex
|
||||||
operations.append(('vertex', vertex_index, vertex))
|
operations.append(('vertex', vertex_index, vertex))
|
||||||
|
@ -34,13 +40,16 @@ class Decimater(obja.Model):
|
||||||
# To rebuild the model, run operations in reverse order
|
# To rebuild the model, run operations in reverse order
|
||||||
operations.reverse()
|
operations.reverse()
|
||||||
|
|
||||||
output_model = obja.Output(output)
|
# Write the result in output file
|
||||||
|
output_model = obja.Output(output, random_color=True)
|
||||||
|
|
||||||
for (ty, index, value) in operations:
|
for (ty, index, value) in operations:
|
||||||
if ty == "vertex":
|
if ty == "vertex":
|
||||||
output_model.add_vertex(index, value)
|
output_model.add_vertex(index, value)
|
||||||
|
elif ty == "face":
|
||||||
|
output_model.add_face(index, value)
|
||||||
else:
|
else:
|
||||||
output_model.add_face(index, value)
|
output_model.edit_vertex(index, value)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""
|
"""
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
3461
exemple/suzanne.obja
3461
exemple/suzanne.obja
File diff suppressed because it is too large
Load Diff
5
obja.py
5
obja.py
|
@ -276,7 +276,10 @@ class Output:
|
||||||
"""
|
"""
|
||||||
Changes the coordinates of a vertex.
|
Changes the coordinates of a vertex.
|
||||||
"""
|
"""
|
||||||
print('ev {} {} {} {}'.format(self.vertex_mapping[index] + 1, vertex[0], vertex[1],vertex[2]), file = self.output)
|
if len(self.vertex_mapping) == 0:
|
||||||
|
print('ev {} {} {} {}'.format(index, vertex[0], vertex[1],vertex[2]), file = self.output)
|
||||||
|
else:
|
||||||
|
print('ev {} {} {} {}'.format(self.vertex_mapping[index] + 1, vertex[0], vertex[1],vertex[2]), file = self.output)
|
||||||
|
|
||||||
def add_face(self, index, face):
|
def add_face(self, index, face):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue