From b31ee54eb7022a9a0209e31854d718a5ea53f4b2 Mon Sep 17 00:00:00 2001 From: Li Date: Sun, 14 Apr 2024 16:32:34 +0200 Subject: [PATCH] update for new rgba in viewer --- src/compas_ifc/brep/tessellatedbrepobject.py | 27 ++++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/compas_ifc/brep/tessellatedbrepobject.py b/src/compas_ifc/brep/tessellatedbrepobject.py index 8dd2efac..7ab5b3dd 100644 --- a/src/compas_ifc/brep/tessellatedbrepobject.py +++ b/src/compas_ifc/brep/tessellatedbrepobject.py @@ -1,6 +1,7 @@ from compas_viewer.scene import ViewerSceneObject from .tessellatedbrep import TessellatedBrep from compas.datastructures import Mesh +from compas.colors import Color import numpy as np @@ -9,34 +10,32 @@ def __init__(self, tessellatedbrep: TessellatedBrep, facecolors=None, **kwargs): super().__init__(item=tessellatedbrep, **kwargs) self.tessellatedbrep = tessellatedbrep self.facecolors = facecolors - self.use_rgba = True # TODO: it is not facecolors, it is verexcolor if not self.facecolors: - self.facecolors = [[0.5, 0.5, 0.5, 1.0] for _ in range(len(self.tessellatedbrep.faces) * 3)] + self.facecolors = [Color(0.5, 0.5, 0.5) for _ in range(len(self.tessellatedbrep.faces) * 3)] + + def _read_points_data(self): + pass def _read_lines_data(self): - positions = self.tessellatedbrep.vertices - elements = self.tessellatedbrep.edges - colors = [] - default_color = self.linescolor["_default"] - colors = np.full(shape=(len(elements), 3), fill_value=default_color) - return positions.tolist(), colors.tolist(), elements.tolist() + positions = self.tessellatedbrep.vertices.tolist() + elements = self.tessellatedbrep.edges.tolist() + colors = [Color(0.5, 0.5, 0.5)] * len(elements) + return positions, colors, elements def _read_frontfaces_data(self): positions = self.tessellatedbrep.vertices[self.tessellatedbrep.faces].reshape(-1, 3).tolist() elements = np.arange(len(positions) * 3).reshape(-1, 3).tolist() - colors = [color[:3] for color in self.facecolors] - opacities = [color[3] for color in self.facecolors] - return positions, colors, opacities, elements + colors = [Color(*color) for color in self.facecolors] + return positions, colors, elements def _read_backfaces_data(self): positions = self.tessellatedbrep.vertices[self.tessellatedbrep.faces].reshape(-1, 3).tolist() elements = np.arange(len(positions) * 3).reshape(-1, 3) elements = elements[:, ::-1].tolist() - colors = [color[:3] for color in self.facecolors] - opacities = [color[3] for color in self.facecolors] - return positions, colors, opacities, elements + colors = [Color(*color) for color in self.facecolors] + return positions, colors, elements def to_mesh(self): return Mesh.from_vertices_and_faces(self.tessellatedbrep.vertices, self.tessellatedbrep.faces)