display-shapes-meshcat.py
Go to the documentation of this file.
1 import sys
2 
3 import numpy as np
4 import pinocchio as pin
5 
6 try:
7  import hppfcl
8 except ImportError:
9  print("This example requires hppfcl")
10  sys.exit(0)
11 from pinocchio.visualize import MeshcatVisualizer
12 
13 model = pin.Model()
14 
15 geom_model = pin.GeometryModel()
16 geometries = [
17  hppfcl.Capsule(0.1, 0.8),
18  hppfcl.Sphere(0.5),
19  hppfcl.Box(1, 1, 1),
20  hppfcl.Cylinder(0.1, 1.0),
21  hppfcl.Cone(0.5, 1.0),
22 ]
23 for i, geom in enumerate(geometries):
24  placement = pin.SE3(np.eye(3), np.array([i, 0, 0]))
25  geom_obj = pin.GeometryObject(f"obj{i}", 0, 0, geom, placement)
26  color = np.random.uniform(0, 1, 4)
27  color[3] = 1
28  geom_obj.meshColor = color
29  geom_model.addGeometryObject(geom_obj)
30 
31 viz = MeshcatVisualizer(model, geom_model, geom_model)
32 
33 # Initialize the viewer.
34 try:
35  viz.initViewer(open=True)
36 except ImportError as error:
37  print(error)
38  sys.exit(0)
39 
40 try:
41  viz.loadViewerModel("shapes")
42 except AttributeError as error:
43  print(error)
44  sys.exit(0)
45 
46 viz.display(np.zeros(0))
47 input("press enter to continue")
pinocchio.visualize
Definition: bindings/python/pinocchio/visualize/__init__.py:1
pinocchio.visualize.meshcat_visualizer.MeshcatVisualizer
Definition: meshcat_visualizer.py:540


pinocchio
Author(s):
autogenerated on Fri Nov 1 2024 02:41:43