Skip to content

Commit

Permalink
re-added updated version of mesh normals drawing methods
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvanmele committed Aug 22, 2024
1 parent cdfa243 commit c1da384
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 63 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Changed `compas_rhino.scene.RhinoMeshObject` to keep track of element-guid pairs in dicts.
* Changed `compas.scene.Scene._guids` to a default value of `[]`.
* Fixed bug due to missing import in `compas_rhino.scene.graphobject`.
* Changed `compas_rhino.scene.RhinoMeshObject.draw_vertexnormals` to use the same selection of vertices as `draw_vertices`.
* Changed `compas_rhino.scene.RhinoMeshObject.draw_vertexnormals` to use the corresponding vertex color if no color is specified.
* Changed `compas_rhino.scene.RhinoMeshObject.draw_facenormals` to use the same selection of vertices as `draw_faces`.
* Changed `compas_rhino.scene.RhinoMeshObject.draw_facenormals` to use the corresponding face color if no color is specified.

### Removed

Expand Down
139 changes: 76 additions & 63 deletions src/compas_rhino/scene/meshobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import scriptcontext as sc # type: ignore

import compas_rhino.objects
from compas.colors import Color
from compas.geometry import Line
from compas.geometry import Point
from compas.geometry import centroid_points
from compas.scene import MeshObject
from compas_rhino.conversions import line_to_rhino
Expand Down Expand Up @@ -447,86 +450,96 @@ def draw_facelabels(self, text, color=None, group=None, fontheight=10, fontface=
# draw normals
# ==========================================================================

# def draw_vertexnormals(self, vertices=None, color=(0, 255, 0), scale=1.0, group=None):
# """Draw the normals at the vertices of the mesh.
def draw_vertexnormals(self, color=None, scale=1.0, group=None):
"""Draw the normals at the vertices of the mesh.
# Parameters
# ----------
# vertices : list[int], optional
# A selection of vertex normals to draw.
# Default is to draw all vertex normals.
# color : tuple[int, int, int] | tuple[float, float, float] | :class:`compas.colors.Color`, optional
# The color specification of the normal vectors.
# scale : float, optional
# Scale factor for the vertex normals.
# group : str, optional
# The name of a group to join the created Rhino objects in.
Parameters
----------
color : tuple[int, int, int] | tuple[float, float, float] | :class:`compas.colors.Color`, optional
The color specification of the normal vectors.
If no color is specified, the color of the corresponding vertex is used.
scale : float, optional
Scale factor for the vertex normals.
group : str, optional
The name of a group to join the created Rhino objects in.
# Returns
# -------
# list[System.Guid]
# The GUIDs of the created Rhino objects.
Returns
-------
list[System.Guid]
The GUIDs of the created Rhino objects.
# """
# guids = []
"""
guids = []

# color = Color.coerce(color)
vertices = list(self.mesh.vertices()) if self.show_vertices is True else self.show_vertices or []
transformation = transformation_to_rhino(self.worldtransformation)

# for vertex in vertices or self.mesh.vertices(): # type: ignore
# name = "{}.vertex.{}.normal".format(self.mesh.name, vertex) # type: ignore
# attr = self.compile_attributes(name=name, color=color)
color = Color.coerce(color)

# point = self.mesh.vertex_point(vertex)
# normal = self.mesh.vertex_normal(vertex) # type: ignore
for vertex in vertices:
name = "{}.vertex.{}.normal".format(self.mesh.name, vertex) # type: ignore
attr = self.compile_attributes(name=name, color=color or self.vertexcolor[vertex]) # type: ignore

# guid = sc.doc.Objects.AddLine(point_to_rhino(point), point_to_rhino(point + normal * scale), attr)
# guids.append(guid)
point = self.mesh.vertex_point(vertex)
normal = self.mesh.vertex_normal(vertex) # type: ignore
line = Line.from_point_and_vector(point, normal)

# if group:
# self.add_to_group(group, guids)
geometry = line_to_rhino(line)
geometry.Transform(transformation)

# self._guids_vertexnormals = guids
# self._guids += guids
# return guids
guid = sc.doc.Objects.AddLine(geometry, attr)
guids.append(guid)

# def draw_facenormals(self, faces=None, color=(0, 255, 255), scale=1.0, group=None):
# """Draw the normals of the faces.
if group:
self.add_to_group(group, guids)

# Parameters
# ----------
# faces : list[int], optional
# A selection of face normals to draw.
# Default is to draw all face normals.
# color : tuple[int, int, int] | tuple[float, float, float] | :class:`compas.colors.Color`, optional
# The color specification of the normal vectors.
# scale : float, optional
# Scale factor for the face normals.
# group : str, optional
# The name of a group to join the created Rhino objects in.
self._guids_vertexnormals = guids
self._guids += guids
return guids

# Returns
# -------
# list[System.Guid]
# The GUIDs of the created Rhino objects.
def draw_facenormals(self, color=None, scale=1.0, group=None):
"""Draw the normals of the faces.
# """
# guids = []
Parameters
----------
color : tuple[int, int, int] | tuple[float, float, float] | :class:`compas.colors.Color`, optional
The color specification of the normal vectors.
If no color is specified, the color of the corresponding face is used.
scale : float, optional
Scale factor for the face normals.
group : str, optional
The name of a group to join the created Rhino objects in.
Returns
-------
list[System.Guid]
The GUIDs of the created Rhino objects.
"""
guids = []

# color = Color.coerce(color)
faces = list(self.mesh.faces()) if self.show_faces is True else self.show_faces or []
transformation = transformation_to_rhino(self.worldtransformation)

# for face in faces or self.mesh.faces(): # type: ignore
# name = "{}.face.{}.normal".format(self.mesh.name, face) # type: ignore
# attr = self.compile_attributes(name=name, color=color)
color = Color.coerce(color)

# point = Point(*centroid_points([self.vertex_xyz[vertex] for vertex in self.mesh.face_vertices(face)])) # type: ignore
# normal = self.mesh.face_normal(face) # type: ignore
for face in faces:
name = "{}.face.{}.normal".format(self.mesh.name, face) # type: ignore
attr = self.compile_attributes(name=name, color=color or self.facecolor[face]) # type: ignore

# guid = sc.doc.Objects.AddLine(point_to_rhino(point), point_to_rhino(point + normal * scale), attr)
# guids.append(guid)
point = self.mesh.face_centroid(face)
normal = self.mesh.face_normal(face)
line = Line.from_point_and_vector(point, normal)

# if group:
# self.add_to_group(group, guids)
geometry = line_to_rhino(line)
geometry.Transform(transformation)

# self._guids_facenormals = guids
guid = sc.doc.Objects.AddLine(geometry, attr)
guids.append(guid)

# return guids
if group:
self.add_to_group(group, guids)

self._guids_facenormals = guids

return guids

0 comments on commit c1da384

Please sign in to comment.