Skip to content

Commit

Permalink
Merge pull request #2350 from stephane-caron/feature/meshcat_colmodcol
Browse files Browse the repository at this point in the history
Separate collision_color in MeshcatVisualizer.loadViewerModel
  • Loading branch information
jcarpent committed Jul 27, 2024
2 parents 59dc0df + d5966e2 commit 43d9144
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Add getMotionAxis method to helical, prismatic, revolute and ubounded revolute joint ([#2315](https://github.com/stack-of-tasks/pinocchio/pull/2315))
- Add initial compatiblity with coal (coal needs `-DCOAL_BACKWARD_COMPATIBILITY_WITH_HPP_FCL=ON`) ([#2323](https://github.com/stack-of-tasks/pinocchio/pull/2323))
- Add compatibility with jrl-cmakemodules workspace ([#2333](https://github.com/stack-of-tasks/pinocchio/pull/2333))
- Add ``collision_color`` parameter to `MeshcatVisualizer.loadViewerModel` ([#2350](https://github.com/stack-of-tasks/pinocchio/pull/2350))

### Changed
- Use eigenpy to expose `GeometryObject::meshMaterial` variant ([#2315](https://github.com/stack-of-tasks/pinocchio/pull/2315))
Expand Down
36 changes: 31 additions & 5 deletions bindings/python/pinocchio/visualize/meshcat_visualizer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .. import pinocchio_pywrap_default as pin
from ..deprecation import DeprecatedWarning
from ..utils import npToTuple

from . import BaseVisualizer
Expand Down Expand Up @@ -852,13 +853,36 @@ def to_material_color(rgba) -> int:
scale = list(np.asarray(geometry_object.meshScale).flatten())
meshcat_node.set_property("scale", scale)

def loadViewerModel(self, rootNodeName="pinocchio", color=None):
def loadViewerModel(
self,
rootNodeName="pinocchio",
color=None,
collision_color=None,
visual_color=None,
):
"""Load the robot in a MeshCat viewer.
Parameters:
rootNodeName: name to give to the robot in the viewer
color: optional, color to give to the robot. This overwrites the color present in the urdf.
Format is a list of four RGBA floats (between 0 and 1)
color: deprecated and optional, color to give to both the collision
and visual models of the robot. This setting overwrites any color
specified in the robot description. Format is a list of four
RGBA floating-point numbers (between 0 and 1)
collision_color: optional, color to give to the collision model of
the robot. Format is a list of four RGBA floating-point numbers
(between 0 and 1)
visual_color: optional, color to give to the visual model of
the robot. Format is a list of four RGBA floating-point numbers
(between 0 and 1)
"""
if color is not None:
warnings.warn(
"The 'color' argument is deprecated and will be removed in a "
"future version of Pinocchio. Consider using "
"'collision_color' and 'visual_color' instead.",
category=DeprecatedWarning,
)
collision_color = color
visual_color = color

# Set viewer to use to gepetto-gui.
self.viewerRootNodeName = rootNodeName
Expand All @@ -869,15 +893,17 @@ def loadViewerModel(self, rootNodeName="pinocchio", color=None):
if self.collision_model is not None:
for collision in self.collision_model.geometryObjects:
self.loadViewerGeometryObject(
collision, pin.GeometryType.COLLISION, color
collision, pin.GeometryType.COLLISION, collision_color
)
self.displayCollisions(False)

# Visuals
self.viewerVisualGroupName = self.viewerRootNodeName + "/" + "visuals"
if self.visual_model is not None:
for visual in self.visual_model.geometryObjects:
self.loadViewerGeometryObject(visual, pin.GeometryType.VISUAL, color)
self.loadViewerGeometryObject(
visual, pin.GeometryType.VISUAL, visual_color
)
self.displayVisuals(True)

# Frames
Expand Down

0 comments on commit 43d9144

Please sign in to comment.