Skip to content
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

Fix Dae support in MeshCat #2331

Merged
merged 7 commits into from
Jul 17, 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

### Fixed
- Append pinocchio optional libraries into pkg-config file ([#2322](https://github.com/stack-of-tasks/pinocchio/pull/2322))
- Fixed support of DAE meshes with MeshCat ([#2331](https://github.com/stack-of-tasks/pinocchio/pull/2331))

### Added
- Add getMotionAxis method to helical, prismatic, revolute and ubounded revolute joint ([#2315](https://github.com/stack-of-tasks/pinocchio/pull/2315))

### Changed
- Use eigenpy to expose `GeometryObject::meshMaterial` variant ([#2315](https://github.com/stack-of-tasks/pinocchio/pull/2315))
- GepettoViewer is no more the default viewer for RobotWrapper ([#2331](https://github.com/stack-of-tasks/pinocchio/pull/2331))

## [3.1.0] - 2024-07-04

Expand Down
8 changes: 4 additions & 4 deletions bindings/python/pinocchio/robot_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,16 +385,16 @@ def getViewerNodeName(self, geometry_object, geometry_type):

def initViewer(self, share_data=True, *args, **kwargs):
"""Init the viewer"""
# Set viewer to use to gepetto-gui.
# Set viewer to use to MeshCat.
if self.viz is None:
from .visualize import GepettoVisualizer
from .visualize import MeshcatVisualizer

data, collision_data, visual_data = None, None, None
if share_data:
data = self.data
collision_data = self.collision_data
visual_data = self.visual_data
self.viz = GepettoVisualizer(
self.viz = MeshcatVisualizer(
self.model,
self.collision_model,
self.visual_model,
Expand All @@ -407,7 +407,7 @@ def initViewer(self, share_data=True, *args, **kwargs):
self.viz.initViewer(*args, **kwargs)

def loadViewerModel(self, *args, **kwargs):
"""Create the scene displaying the robot meshes in gepetto-viewer"""
"""Create the scene displaying the robot meshes in MeshCat"""
self.viz.loadViewerModel(*args, **kwargs)

def display(self, q):
Expand Down
10 changes: 9 additions & 1 deletion bindings/python/pinocchio/visualize/meshcat_visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def __init__(self, dae_path: str, cache: Optional[Set[str]] = None) -> None:
# Attributes to be specified by the user
self.path = None
self.material = None
self.intrinsic_transform = mg.tf.identity_matrix()

# Raw file content
dae_dir = os.path.dirname(dae_path)
Expand Down Expand Up @@ -164,13 +165,17 @@ def lower(self) -> Dict[str, Any]:
"format": "dae",
"data": self.dae_raw,
"resources": self.img_resources,
"matrix": list(self.intrinsic_transform.flatten()),
},
},
}
if self.material is not None:
self.material.lower_in_object(data)
return data

def set_scale(self, scale) -> None:
self.intrinsic_transform[:3, :3] = np.diag(scale)

# end code adapted from Jiminy

class Plane(mg.Geometry):
Expand Down Expand Up @@ -834,13 +839,16 @@ def to_material_color(rgba) -> int:

if isinstance(obj, DaeMeshGeometry):
obj.path = meshcat_node.path
scale = list(np.asarray(geometry_object.meshScale).flatten())
obj.set_scale(scale)
if geometry_object.overrideMaterial:
obj.material = material
meshcat_node.window.send(obj)
else:
meshcat_node.set_object(obj, material)

if is_mesh: # Apply the scaling
# Apply the scaling
if is_mesh and not isinstance(obj, DaeMeshGeometry):
scale = list(np.asarray(geometry_object.meshScale).flatten())
meshcat_node.set_property("scale", scale)

Expand Down
14 changes: 1 addition & 13 deletions examples/anymal-simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import hppfcl as fcl
import pinocchio
from example_robot_data import load
from pinocchio.visualize import GepettoVisualizer
from pinocchio.visualize import MeshcatVisualizer
from pinocchio import GeometryType
from time import sleep

Expand Down Expand Up @@ -45,18 +45,6 @@

robot.initViewer()
robot.loadViewerModel("pinocchio")
gui = robot.viewer.gui
robot.display(robot.q0)
window_id = robot.viewer.gui.getWindowID("python-pinocchio")

robot.viewer.gui.setBackgroundColor1(window_id, [1.0, 1.0, 1.0, 1.0])
robot.viewer.gui.setBackgroundColor2(window_id, [1.0, 1.0, 1.0, 1.0])
robot.viewer.gui.addFloor("hpp-gui/floor")

robot.viewer.gui.setScale("hpp-gui/floor", [0.5, 0.5, 0.5])
robot.viewer.gui.setColor("hpp-gui/floor", [0.7, 0.7, 0.7, 1.0])
robot.viewer.gui.setLightingMode("hpp-gui/floor", "OFF")

robot.display(robot.q0)

constraint_datas = [cm.createData() for cm in constraint_models]
Expand Down
7 changes: 0 additions & 7 deletions examples/meshcat-viewer-dae.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@
urdf_model_path, mesh_dir, pin.JointModelFreeFlyer()
)

# Currently, MeshCat is not able to retrieve the scaling from DAE files. Set it manually.
for geom in visual_model.geometryObjects:
s = geom.meshScale
s *= 0.01
geom.meshScale = s


# Start a new MeshCat server and client.
# Note: the server can also be started separately using the "meshcat-server" command in a terminal:
# this enables the server to remain active after the current script ends.
Expand Down
Loading