Skip to content

Commit

Permalink
fix mesh for GH and put back labels
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvanmele committed Aug 22, 2024
1 parent daabaa3 commit 88b748e
Show file tree
Hide file tree
Showing 2 changed files with 154 additions and 141 deletions.
57 changes: 34 additions & 23 deletions src/compas_ghpython/scene/meshobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ class MeshObject(GHSceneObject, BaseMeshObject):
def __init__(self, disjoint=False, **kwargs):
super(MeshObject, self).__init__(**kwargs)
self.disjoint = disjoint
self._guid_mesh = None
self._guid_face = {}
self._guid_edge = {}
self._guid_vertex = {}

def draw(self):
"""Draw the mesh.
Expand All @@ -50,45 +54,38 @@ def draw(self):
self._guids = []

if self.show_faces is True:

vertexcolors = []
if len(self.vertexcolor):
vertexcolors = [self.vertexcolor[vertex] for vertex in self.mesh.vertices()]
if len(self.vertexcolor): # type: ignore
vertexcolors = [self.vertexcolor[vertex] for vertex in self.mesh.vertices()] # type: ignore

facecolors = []
if len(self.facecolor):
facecolors = [self.facecolor[face] for face in self.mesh.faces()]

color = None
if not vertexcolors and not facecolors:
color = self.color
if len(self.facecolor): # type: ignore
facecolors = [self.facecolor[face] for face in self.mesh.faces()] # type: ignore

vertex_index = self.mesh.vertex_index()
vertex_xyz = self.vertex_xyz

vertices = [vertex_xyz[vertex] for vertex in self.mesh.vertices()]
vertices = [self.mesh.vertex_attributes(vertex, "xyz") for vertex in self.mesh.vertices()]
faces = [[vertex_index[vertex] for vertex in self.mesh.face_vertices(face)] for face in self.mesh.faces()]

geometry = conversions.vertices_and_faces_to_rhino(
vertices,
faces,
color=color,
color=self.color,
vertexcolors=vertexcolors,
facecolors=facecolors,
disjoint=self.disjoint,
)

# geometry.Transform(conversions.transformation_to_rhino(self.worldtransformation))
geometry.Transform(conversions.transformation_to_rhino(self.worldtransformation))

self._guids.append(geometry)

elif self.show_faces:
self._guids += self.draw_faces()
self.draw_faces()

if self.show_vertices:
self._guids += self.draw_vertices()

if self.show_edges:
self._guids += self.draw_edges()
self.draw_vertices()
self.draw_edges()

return self.guids

Expand All @@ -104,9 +101,13 @@ def draw_vertices(self):

vertices = list(self.mesh.vertices()) if self.show_vertices is True else self.show_vertices or []

transformation = conversions.transformation_to_rhino(self.worldtransformation)

if vertices:
for vertex in vertices:
points.append(conversions.point_to_rhino(self.vertex_xyz[vertex]))
geometry = conversions.point_to_rhino(self.mesh.vertex_attributes(vertex, "xyz"))
geometry.Transform(transformation)
points.append(geometry)

return points

Expand All @@ -122,9 +123,14 @@ def draw_edges(self):

edges = list(self.mesh.edges()) if self.show_edges is True else self.show_edges or []

transformation = conversions.transformation_to_rhino(self.worldtransformation)

if edges:
for edge in edges:
lines.append(conversions.line_to_rhino((self.vertex_xyz[edge[0]], self.vertex_xyz[edge[1]])))
line = self.mesh.edge_line(edge)
geometry = conversions.line_to_rhino(line)
geometry.Transform(transformation)
lines.append(geometry)

return lines

Expand All @@ -140,12 +146,17 @@ def draw_faces(self):

faces = list(self.mesh.faces()) if self.show_faces is True else self.show_faces or []

transformation = conversions.transformation_to_rhino(self.worldtransformation)

if faces:
for face in faces:
color = self.facecolor[face]
vertices = [self.vertex_xyz[vertex] for vertex in self.mesh.face_vertices(face)]
color = self.facecolor[face] # type: ignore
vertices = [self.mesh.vertex_attributes(vertex, "xyz") for vertex in self.mesh.face_vertices(face)] # type: ignore
facet = ngon(len(vertices))

if facet:
meshes.append(conversions.vertices_and_faces_to_rhino(vertices, [facet], color=color))
geometry = conversions.vertices_and_faces_to_rhino(vertices, [facet], color=color)
geometry.Transform(transformation)
meshes.append(geometry)

return meshes
Loading

0 comments on commit 88b748e

Please sign in to comment.