Skip to content

Commit c1da384

Browse files
committed
re-added updated version of mesh normals drawing methods
1 parent cdfa243 commit c1da384

File tree

2 files changed

+80
-63
lines changed

2 files changed

+80
-63
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2424
* Changed `compas_rhino.scene.RhinoMeshObject` to keep track of element-guid pairs in dicts.
2525
* Changed `compas.scene.Scene._guids` to a default value of `[]`.
2626
* Fixed bug due to missing import in `compas_rhino.scene.graphobject`.
27+
* Changed `compas_rhino.scene.RhinoMeshObject.draw_vertexnormals` to use the same selection of vertices as `draw_vertices`.
28+
* Changed `compas_rhino.scene.RhinoMeshObject.draw_vertexnormals` to use the corresponding vertex color if no color is specified.
29+
* Changed `compas_rhino.scene.RhinoMeshObject.draw_facenormals` to use the same selection of vertices as `draw_faces`.
30+
* Changed `compas_rhino.scene.RhinoMeshObject.draw_facenormals` to use the corresponding face color if no color is specified.
2731

2832
### Removed
2933

src/compas_rhino/scene/meshobject.py

Lines changed: 76 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
import scriptcontext as sc # type: ignore
77

88
import compas_rhino.objects
9+
from compas.colors import Color
10+
from compas.geometry import Line
11+
from compas.geometry import Point
912
from compas.geometry import centroid_points
1013
from compas.scene import MeshObject
1114
from compas_rhino.conversions import line_to_rhino
@@ -447,86 +450,96 @@ def draw_facelabels(self, text, color=None, group=None, fontheight=10, fontface=
447450
# draw normals
448451
# ==========================================================================
449452

450-
# def draw_vertexnormals(self, vertices=None, color=(0, 255, 0), scale=1.0, group=None):
451-
# """Draw the normals at the vertices of the mesh.
453+
def draw_vertexnormals(self, color=None, scale=1.0, group=None):
454+
"""Draw the normals at the vertices of the mesh.
452455
453-
# Parameters
454-
# ----------
455-
# vertices : list[int], optional
456-
# A selection of vertex normals to draw.
457-
# Default is to draw all vertex normals.
458-
# color : tuple[int, int, int] | tuple[float, float, float] | :class:`compas.colors.Color`, optional
459-
# The color specification of the normal vectors.
460-
# scale : float, optional
461-
# Scale factor for the vertex normals.
462-
# group : str, optional
463-
# The name of a group to join the created Rhino objects in.
456+
Parameters
457+
----------
458+
color : tuple[int, int, int] | tuple[float, float, float] | :class:`compas.colors.Color`, optional
459+
The color specification of the normal vectors.
460+
If no color is specified, the color of the corresponding vertex is used.
461+
scale : float, optional
462+
Scale factor for the vertex normals.
463+
group : str, optional
464+
The name of a group to join the created Rhino objects in.
464465
465-
# Returns
466-
# -------
467-
# list[System.Guid]
468-
# The GUIDs of the created Rhino objects.
466+
Returns
467+
-------
468+
list[System.Guid]
469+
The GUIDs of the created Rhino objects.
469470
470-
# """
471-
# guids = []
471+
"""
472+
guids = []
472473

473-
# color = Color.coerce(color)
474+
vertices = list(self.mesh.vertices()) if self.show_vertices is True else self.show_vertices or []
475+
transformation = transformation_to_rhino(self.worldtransformation)
474476

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

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

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

485-
# if group:
486-
# self.add_to_group(group, guids)
487+
geometry = line_to_rhino(line)
488+
geometry.Transform(transformation)
487489

488-
# self._guids_vertexnormals = guids
489-
# self._guids += guids
490-
# return guids
490+
guid = sc.doc.Objects.AddLine(geometry, attr)
491+
guids.append(guid)
491492

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

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

507-
# Returns
508-
# -------
509-
# list[System.Guid]
510-
# The GUIDs of the created Rhino objects.
500+
def draw_facenormals(self, color=None, scale=1.0, group=None):
501+
"""Draw the normals of the faces.
511502
512-
# """
513-
# guids = []
503+
Parameters
504+
----------
505+
color : tuple[int, int, int] | tuple[float, float, float] | :class:`compas.colors.Color`, optional
506+
The color specification of the normal vectors.
507+
If no color is specified, the color of the corresponding face is used.
508+
scale : float, optional
509+
Scale factor for the face normals.
510+
group : str, optional
511+
The name of a group to join the created Rhino objects in.
512+
513+
Returns
514+
-------
515+
list[System.Guid]
516+
The GUIDs of the created Rhino objects.
517+
518+
"""
519+
guids = []
514520

515-
# color = Color.coerce(color)
521+
faces = list(self.mesh.faces()) if self.show_faces is True else self.show_faces or []
522+
transformation = transformation_to_rhino(self.worldtransformation)
516523

517-
# for face in faces or self.mesh.faces(): # type: ignore
518-
# name = "{}.face.{}.normal".format(self.mesh.name, face) # type: ignore
519-
# attr = self.compile_attributes(name=name, color=color)
524+
color = Color.coerce(color)
520525

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

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

527-
# if group:
528-
# self.add_to_group(group, guids)
534+
geometry = line_to_rhino(line)
535+
geometry.Transform(transformation)
529536

530-
# self._guids_facenormals = guids
537+
guid = sc.doc.Objects.AddLine(geometry, attr)
538+
guids.append(guid)
531539

532-
# return guids
540+
if group:
541+
self.add_to_group(group, guids)
542+
543+
self._guids_facenormals = guids
544+
545+
return guids

0 commit comments

Comments
 (0)