From ad8f0c839e46c2ed3bf4f110bc07d0a17a3e6a81 Mon Sep 17 00:00:00 2001 From: Justin Carpentier Date: Tue, 16 Jul 2024 11:01:53 +0200 Subject: [PATCH 1/7] python/meschat: fix Dae support --- bindings/python/pinocchio/visualize/meshcat_visualizer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bindings/python/pinocchio/visualize/meshcat_visualizer.py b/bindings/python/pinocchio/visualize/meshcat_visualizer.py index 38d6af9926..475f9a492b 100644 --- a/bindings/python/pinocchio/visualize/meshcat_visualizer.py +++ b/bindings/python/pinocchio/visualize/meshcat_visualizer.py @@ -739,7 +739,7 @@ def loadMeshFromFile(self, geometry_object): # Get file type from filename extension. _, file_extension = os.path.splitext(geometry_object.meshPath) if file_extension.lower() == ".dae": - obj = DaeMeshGeometry(geometry_object.meshPath) + obj = mg.DaeMeshGeometry.from_file(geometry_object.meshPath) elif file_extension.lower() == ".obj": obj = mg.ObjMeshGeometry.from_file(geometry_object.meshPath) elif file_extension.lower() == ".stl": @@ -832,7 +832,7 @@ def to_material_color(rgba) -> int: material.specular = to_material_color(geom_material.meshSpecularColor) material.shininess = geom_material.meshShininess * 100.0 - if isinstance(obj, DaeMeshGeometry): + if isinstance(obj, mg.DaeMeshGeometry): obj.path = meshcat_node.path if geometry_object.overrideMaterial: obj.material = material From e12492e41c6a85a9f215e0072298d16e3083c5df Mon Sep 17 00:00:00 2001 From: Justin Carpentier Date: Tue, 16 Jul 2024 11:05:49 +0200 Subject: [PATCH 2/7] changelog: sync --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5decbe56fc..91e3a9dba9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ 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)) From 45b23d866498b8bf8fc4f4eb744029aa19ff8c85 Mon Sep 17 00:00:00 2001 From: Justin Carpentier Date: Tue, 16 Jul 2024 11:53:15 +0200 Subject: [PATCH 3/7] python: enforce the use of MeshCat viewer --- bindings/python/pinocchio/robot_wrapper.py | 8 ++++---- examples/anymal-simulation.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bindings/python/pinocchio/robot_wrapper.py b/bindings/python/pinocchio/robot_wrapper.py index 5d8aa45973..906a49bf5f 100644 --- a/bindings/python/pinocchio/robot_wrapper.py +++ b/bindings/python/pinocchio/robot_wrapper.py @@ -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, @@ -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): diff --git a/examples/anymal-simulation.py b/examples/anymal-simulation.py index 6a2bef0194..8f25a1fe37 100644 --- a/examples/anymal-simulation.py +++ b/examples/anymal-simulation.py @@ -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 From ae4853e0dfc3fba785983cf1e3c0286c9c80f9ea Mon Sep 17 00:00:00 2001 From: Justin Carpentier Date: Tue, 16 Jul 2024 16:35:55 +0200 Subject: [PATCH 4/7] python/meshcat: fix scaling for DaeMeshGeometry --- .../pinocchio/visualize/meshcat_visualizer.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/bindings/python/pinocchio/visualize/meshcat_visualizer.py b/bindings/python/pinocchio/visualize/meshcat_visualizer.py index 475f9a492b..18c0b557b4 100644 --- a/bindings/python/pinocchio/visualize/meshcat_visualizer.py +++ b/bindings/python/pinocchio/visualize/meshcat_visualizer.py @@ -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) @@ -164,6 +165,7 @@ def lower(self) -> Dict[str, Any]: "format": "dae", "data": self.dae_raw, "resources": self.img_resources, + "matrix": list(self.intrinsic_transform.flatten()), }, }, } @@ -171,6 +173,9 @@ def lower(self) -> Dict[str, Any]: 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): @@ -739,7 +744,7 @@ def loadMeshFromFile(self, geometry_object): # Get file type from filename extension. _, file_extension = os.path.splitext(geometry_object.meshPath) if file_extension.lower() == ".dae": - obj = mg.DaeMeshGeometry.from_file(geometry_object.meshPath) + obj = DaeMeshGeometry(geometry_object.meshPath) elif file_extension.lower() == ".obj": obj = mg.ObjMeshGeometry.from_file(geometry_object.meshPath) elif file_extension.lower() == ".stl": @@ -832,15 +837,18 @@ def to_material_color(rgba) -> int: material.specular = to_material_color(geom_material.meshSpecularColor) material.shininess = geom_material.meshShininess * 100.0 - if isinstance(obj, mg.DaeMeshGeometry): + 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) From 0fa35325d1703056fd390ab93c3407653f743c9d Mon Sep 17 00:00:00 2001 From: Justin Carpentier Date: Tue, 16 Jul 2024 16:36:22 +0200 Subject: [PATCH 5/7] python/examples: remove the use of gepetto-gui --- examples/anymal-simulation.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/examples/anymal-simulation.py b/examples/anymal-simulation.py index 8f25a1fe37..9e0a1f3ac5 100644 --- a/examples/anymal-simulation.py +++ b/examples/anymal-simulation.py @@ -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] From eb9c8a383921012285acbd52a9dce4d22a70567c Mon Sep 17 00:00:00 2001 From: Justin Carpentier Date: Tue, 16 Jul 2024 17:06:20 +0200 Subject: [PATCH 6/7] changelog: sync --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 91e3a9dba9..77593c5da9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### 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 From b6d950467ee84fb80f1e13ac341ece83213f44ad Mon Sep 17 00:00:00 2001 From: Justin Carpentier Date: Tue, 16 Jul 2024 17:39:32 +0200 Subject: [PATCH 7/7] python/examples: remove manual scaling --- examples/meshcat-viewer-dae.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/examples/meshcat-viewer-dae.py b/examples/meshcat-viewer-dae.py index 8ad9d6fa70..78e832fada 100644 --- a/examples/meshcat-viewer-dae.py +++ b/examples/meshcat-viewer-dae.py @@ -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.