feat: les couleurs :O
This commit is contained in:
parent
fbaf17a81f
commit
45c8130749
46
main.py
46
main.py
|
@ -575,43 +575,44 @@ class MAPS(obja.Model):
|
||||||
# Check if point is in triangle
|
# Check if point is in triangle
|
||||||
return (u >= 0) and (v >= 0) and (u + v < 1)
|
return (u >= 0) and (v >= 0) and (u + v < 1)
|
||||||
|
|
||||||
def truc(self, output):
|
def debug(self, output):
|
||||||
|
|
||||||
self.update()
|
self.update()
|
||||||
priorities = self.compute_priority()
|
priorities = self.compute_priority()
|
||||||
# min_p = min(priorities)
|
|
||||||
# priorities = [p - min_p for p in priorities]
|
|
||||||
# max_p = max(priorities)
|
|
||||||
colors = [priorities[face.a] + priorities[face.b] +
|
colors = [priorities[face.a] + priorities[face.b] +
|
||||||
priorities[face.c] if face is not None else 0.0 for face in self.faces]
|
priorities[face.c] if face is not None else 0.0 for face in self.faces]
|
||||||
min_c = min(colors)
|
min_c = min(colors)
|
||||||
colors = [c - min_c for c in colors]
|
colors = [c - min_c for c in colors]
|
||||||
max_c = max(colors)
|
max_c = max(colors)
|
||||||
|
|
||||||
operations = []
|
operations = []
|
||||||
for i, face in enumerate(self.faces):
|
for i, face in enumerate(self.faces):
|
||||||
if face != None:
|
if face is None:
|
||||||
|
continue
|
||||||
r, g, b = colors[i] / max_c, 1.0, 1.0
|
r, g, b = colors[i] / max_c, 1.0, 1.0
|
||||||
c = 0
|
|
||||||
for x in (face.a, face.b, face.c):
|
|
||||||
for feature_edge in self.feature_edges:
|
for feature_edge in self.feature_edges:
|
||||||
if x in feature_edge:
|
face_vertices = (face.a, face.b, face.c)
|
||||||
c += 1
|
if feature_edge.a in face_vertices and feature_edge.b in face_vertices:
|
||||||
break
|
|
||||||
if c > 1:
|
|
||||||
r, g, b = 1.0, 0.0, 0.0
|
r, g, b = 1.0, 0.0, 0.0
|
||||||
operations.append(('fc', i, (r, g, b), 0, 0, 0))
|
break
|
||||||
operations.append(('af', i, face, 0, 0, 0))
|
|
||||||
|
operations.append(('fc', i, (r, g, b)))
|
||||||
|
operations.append(('af', i, face.to_obja()))
|
||||||
|
|
||||||
for i, vertex in enumerate(self.vertices):
|
for i, vertex in enumerate(self.vertices):
|
||||||
if vertex is None:
|
if vertex is None:
|
||||||
# r, g, b = priorities[i] / max_p , 1.0, 1.0
|
continue
|
||||||
operations.append(('av', i, vertex, 1.0, 1.0, 1.0))
|
operations.append(('av', i, vertex.to_obja()))
|
||||||
operations.reverse()
|
operations.reverse()
|
||||||
|
|
||||||
# Write the result in output file
|
# Write the result in output file
|
||||||
output_model = obja.Output(output)
|
output_model = obja.Output(output)
|
||||||
|
|
||||||
for (op, index, value, r, g, b) in operations:
|
for (op, index, value) in operations:
|
||||||
if op == 'av':
|
if op == 'av':
|
||||||
output_model.add_vertex_rgb(index, value, r, g, b)
|
output_model.add_vertex(index, value)
|
||||||
elif op == 'af':
|
elif op == 'af':
|
||||||
output_model.add_face(index, value)
|
output_model.add_face(index, value)
|
||||||
elif op == 'ev':
|
elif op == 'ev':
|
||||||
|
@ -627,7 +628,7 @@ class MAPS(obja.Model):
|
||||||
file=output
|
file=output
|
||||||
)
|
)
|
||||||
|
|
||||||
def compress(self, output: io.TextIOWrapper, level: int, final_only: bool) -> None:
|
def compress(self, output: io.TextIOWrapper, level: int, final_only: bool, debug: bool) -> None:
|
||||||
""" Compress the 3d model
|
""" Compress the 3d model
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
@ -675,6 +676,10 @@ class MAPS(obja.Model):
|
||||||
('av', v_index, self.vertices[v_index].to_obja()))
|
('av', v_index, self.vertices[v_index].to_obja()))
|
||||||
self.vertices[v_index] = None
|
self.vertices[v_index] = None
|
||||||
|
|
||||||
|
if debug:
|
||||||
|
self.debug(output)
|
||||||
|
return
|
||||||
|
|
||||||
# Register remaining vertices and faces
|
# Register remaining vertices and faces
|
||||||
for i, face in enumerate(self.faces):
|
for i, face in enumerate(self.faces):
|
||||||
if face is not None:
|
if face is not None:
|
||||||
|
@ -718,9 +723,7 @@ def main(args):
|
||||||
model.parse_file(args.input)
|
model.parse_file(args.input)
|
||||||
|
|
||||||
with open(args.output, 'w') as output:
|
with open(args.output, 'w') as output:
|
||||||
model.compress(output, args.level, args.final)
|
model.compress(output, args.level, args.final or args.debug, args.debug)
|
||||||
# with open(args.output, 'w') as output:
|
|
||||||
# model.truc(output)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -730,6 +733,7 @@ if __name__ == '__main__':
|
||||||
parser.add_argument('-o', '--output', type=str, required=True)
|
parser.add_argument('-o', '--output', type=str, required=True)
|
||||||
parser.add_argument('-l', '--level', type=int, required=True)
|
parser.add_argument('-l', '--level', type=int, required=True)
|
||||||
parser.add_argument('-f', '--final', type=bool, default=False)
|
parser.add_argument('-f', '--final', type=bool, default=False)
|
||||||
|
parser.add_argument('-d', '--debug', type=bool, default=False)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
main(args)
|
main(args)
|
||||||
|
|
Loading…
Reference in a new issue