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


pinocchio
Author(s):
autogenerated on Fri Jun 23 2023 02:38:29