From 45c813074981eee783cb128428126accccbbeb7f Mon Sep 17 00:00:00 2001 From: gdamms Date: Tue, 18 Oct 2022 00:06:57 +0200 Subject: [PATCH] feat: les couleurs :O --- main.py | 50 +++++++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/main.py b/main.py index b1dcafa..856bc03 100644 --- a/main.py +++ b/main.py @@ -575,43 +575,44 @@ class MAPS(obja.Model): # Check if point is in triangle return (u >= 0) and (v >= 0) and (u + v < 1) - def truc(self, output): + def debug(self, output): + self.update() 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] + priorities[face.c] if face is not None else 0.0 for face in self.faces] min_c = min(colors) colors = [c - min_c for c in colors] max_c = max(colors) + operations = [] for i, face in enumerate(self.faces): - if face != None: - 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: - if x in feature_edge: - c += 1 - break - if c > 1: + if face is None: + continue + r, g, b = colors[i] / max_c, 1.0, 1.0 + + for feature_edge in self.feature_edges: + face_vertices = (face.a, face.b, face.c) + if feature_edge.a in face_vertices and feature_edge.b in face_vertices: r, g, b = 1.0, 0.0, 0.0 - operations.append(('fc', i, (r, g, b), 0, 0, 0)) - operations.append(('af', i, face, 0, 0, 0)) + break + + operations.append(('fc', i, (r, g, b))) + operations.append(('af', i, face.to_obja())) + for i, vertex in enumerate(self.vertices): if vertex is None: - # r, g, b = priorities[i] / max_p , 1.0, 1.0 - operations.append(('av', i, vertex, 1.0, 1.0, 1.0)) + continue + operations.append(('av', i, vertex.to_obja())) operations.reverse() # Write the result in output file output_model = obja.Output(output) - for (op, index, value, r, g, b) in operations: + for (op, index, value) in operations: if op == 'av': - output_model.add_vertex_rgb(index, value, r, g, b) + output_model.add_vertex(index, value) elif op == 'af': output_model.add_face(index, value) elif op == 'ev': @@ -627,7 +628,7 @@ class MAPS(obja.Model): 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 Args: @@ -675,6 +676,10 @@ class MAPS(obja.Model): ('av', v_index, self.vertices[v_index].to_obja())) self.vertices[v_index] = None + if debug: + self.debug(output) + return + # Register remaining vertices and faces for i, face in enumerate(self.faces): if face is not None: @@ -718,9 +723,7 @@ def main(args): model.parse_file(args.input) with open(args.output, 'w') as output: - model.compress(output, args.level, args.final) - # with open(args.output, 'w') as output: - # model.truc(output) + model.compress(output, args.level, args.final or args.debug, args.debug) if __name__ == '__main__': @@ -730,6 +733,7 @@ if __name__ == '__main__': parser.add_argument('-o', '--output', type=str, required=True) parser.add_argument('-l', '--level', type=int, required=True) parser.add_argument('-f', '--final', type=bool, default=False) + parser.add_argument('-d', '--debug', type=bool, default=False) args = parser.parse_args() main(args)