Skip to content

Separate collision_color in MeshcatVisualizer.loadViewerModel #2350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading