Updating decimation & adding examples
This commit is contained in:
parent
bd1ba14af7
commit
81b12ca77b
15
decimate.py
15
decimate.py
|
@ -18,14 +18,20 @@ 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:
|
||||||
|
if vertex_index in [face.a,face.b,face.c]:
|
||||||
self.deleted_faces.add(face_index)
|
self.deleted_faces.add(face_index)
|
||||||
|
# Add the instruction to operations stack
|
||||||
operations.append(('face', face_index, face))
|
operations.append(('face', face_index, face))
|
||||||
|
|
||||||
# Delete the vertex
|
# Delete the 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)
|
||||||
else:
|
elif ty == "face":
|
||||||
output_model.add_face(index, value)
|
output_model.add_face(index, value)
|
||||||
|
else:
|
||||||
|
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
3
obja.py
3
obja.py
|
@ -276,6 +276,9 @@ class Output:
|
||||||
"""
|
"""
|
||||||
Changes the coordinates of a vertex.
|
Changes the coordinates of a vertex.
|
||||||
"""
|
"""
|
||||||
|
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)
|
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