Skip to content

Commit

Permalink
update for new rgba in viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
Licini committed Apr 14, 2024
1 parent d3526d5 commit b31ee54
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions src/compas_ifc/brep/tessellatedbrepobject.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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)

0 comments on commit b31ee54

Please sign in to comment.