Skip to content

Commit 93e7c3a

Browse files
authored
Merge pull request #2503 from jorisv/topic/fix-meshcat-examples
Fix meshcat examples
2 parents c0d4225 + 5927c44 commit 93e7c3a

5 files changed

+28
-7
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1313
- Fix mjcf parsing of armature and of the default tag in models ([#2477](https://github.com/stack-of-tasks/pinocchio/pull/2477))
1414
- Fix undefined behavior when using the site attribute in mjcf ([#2477](https://github.com/stack-of-tasks/pinocchio/pull/2477))
1515
- Fix the type of image paths when loading textures in the meshcat visualizer ([#2478](https://github.com/stack-of-tasks/pinocchio/pull/2478))
16+
- Fix meshcat examples ([#2503])[https://github.com/stack-of-tasks/pinocchio/pull/2503]
1617

1718
### Changed
1819
- On GNU/Linux and macOS, hide all symbols by default ([#2469](https://github.com/stack-of-tasks/pinocchio/pull/2469))

examples/append-urdf-model-with-another-model.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import math
22
import sys
3+
import time
34
from pathlib import Path
45

56
import hppfcl as fcl
@@ -91,3 +92,4 @@
9192
model.upperPositionLimit.fill(+math.pi / 2)
9293
q = pin.randomConfiguration(model)
9394
viz.display(q)
95+
time.sleep(1.0)

examples/collision-with-point-clouds.py

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# pip install --user meshcat
55

66
import sys
7+
import time
78
from pathlib import Path
89

910
import hppfcl as fcl
@@ -123,3 +124,4 @@
123124

124125
print("Found a configuration in collision:", q)
125126
viz.display(q)
127+
time.sleep(1.0)

examples/meshcat-viewer-octree.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# pip install --user meshcat
44

55
import sys
6+
import time
67

78
import hppfcl as fcl
89
import numpy as np
@@ -47,4 +48,4 @@
4748
sys.exit(0)
4849

4950
viz.loadViewerModel()
50-
viz.clearDefaultLights()
51+
time.sleep(1.0)

examples/meshcat-viewer-solo.py

+21-6
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,25 @@
33
hppfcl.HeightField.
44
"""
55

6+
import time
7+
from pathlib import Path
8+
69
import numpy as np
710
import pinocchio as pin
8-
from example_robot_data import load
911
from pinocchio.visualize import MeshcatVisualizer
1012

11-
robot = load("solo12")
13+
# Load the URDF model.
14+
# Conversion with str seems to be necessary when executing this file with ipython
15+
pinocchio_model_dir = Path(__file__).parent.parent / "models"
16+
17+
model_path = pinocchio_model_dir / "example-robot-data/robots"
18+
mesh_dir = pinocchio_model_dir
19+
urdf_filename = "solo12.urdf"
20+
urdf_model_path = model_path / "solo_description/robots" / urdf_filename
21+
22+
model, collision_model, visual_model = pin.buildModelsFromUrdf(
23+
urdf_model_path, mesh_dir, pin.JointModelFreeFlyer()
24+
)
1225

1326
q_ref = np.array(
1427
[
@@ -35,9 +48,8 @@
3548
)
3649

3750

38-
model = robot.model
39-
vizer = MeshcatVisualizer(model, robot.collision_model, robot.visual_model)
40-
vizer.initViewer(loadModel=True)
51+
vizer = MeshcatVisualizer(model, collision_model, visual_model)
52+
vizer.initViewer(open=True)
4153

4254

4355
def ground(xy):
@@ -66,11 +78,14 @@ def vizGround(viz, elevation_fn, space, name="ground", color=[1.0, 1.0, 0.6, 0.8
6678
obj = pin.GeometryObject("ground", 0, pl, heightField)
6779
obj.meshColor[:] = color
6880
viz.addGeometryObject(obj)
69-
viz.viewer.open()
7081

7182

83+
# Load the robot in the viewer.
84+
vizer.loadViewerModel()
85+
7286
colorrgb = [128, 149, 255, 200]
7387
colorrgb = np.array(colorrgb) / 255.0
7488
vizGround(vizer, ground, 0.02, color=colorrgb)
7589

7690
vizer.display(q_ref)
91+
time.sleep(1.0)

0 commit comments

Comments
 (0)