You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.0 KiB

#!/usr/bin/env python
import obja
import numpy as np
import sys
class Decimater(obja.Model):
A simple class that decimates a 3D model stupidly.
def __init__(self):
self.deleted_faces = set()
def contract(self, output):
Decimates the model stupidly, and write the resulting obja in output.
operations = []
for (vertex_index, vertex) in enumerate(self.vertices):
operations.append(('ev', vertex_index, vertex + 0.25))
# Iterate through the vertex
for (vertex_index, vertex) in enumerate(self.vertices):
# Iterate through the faces
for (face_index, face) in enumerate(self.faces):
# Delete any face related to this vertex
if face_index not in self.deleted_faces:
if vertex_index in [face.a,face.b,face.c]:
# Add the instruction to operations stack
operations.append(('face', face_index, face))
# Delete the vertex
operations.append(('vertex', vertex_index, vertex))
# To rebuild the model, run operations in reverse order
# Write the result in output file
output_model = obja.Output(output, random_color=True)
for (ty, index, value) in operations:
if ty == "vertex":
output_model.add_vertex(index, value)
elif ty == "face":
output_model.add_face(index, value)
output_model.edit_vertex(index, value)
def main():
Runs the program on the model given as parameter.
np.seterr(invalid = 'raise')
model = Decimater()
with open('exemple/suzanne.obja', 'w') as output:
if __name__ == '__main__':