vizutils.py
Go to the documentation of this file.
1 import numpy as np
2 import pinocchio as pin
3 
4 # Meshcat utils
5 
6 
7 def meshcat_material(r, g, b, a):
8  import meshcat
9 
10  material = meshcat.geometry.MeshPhongMaterial()
11  material.color = int(r * 255) * 256**2 + int(g * 255) * 256 + int(b * 255)
12  material.opacity = a
13  return material
14 
15 
16 def meshcat_transform(x, y, z, q, u, a, t):
17  return np.array(pin.XYZQUATToSE3([x, y, z, q, u, a, t]))
18 
19 
20 # Gepetto/meshcat abstraction
21 
22 
23 def addViewerBox(viz, name, sizex, sizey, sizez, rgba):
24  if isinstance(viz, pin.visualize.MeshcatVisualizer):
25  import meshcat
26 
27  viz.viewer[name].set_object(
28  meshcat.geometry.Box([sizex, sizey, sizez]), meshcat_material(*rgba)
29  )
30  elif isinstance(viz, pin.visualize.GepettoVisualizer):
31  viz.viewer.gui.addBox(name, sizex, sizey, sizez, rgba)
32  else:
33  msg = f"Viewer {viz.__class__} is not supported."
34  raise AttributeError(msg)
35 
36 
37 def addViewerSphere(viz, name, size, rgba):
38  if isinstance(viz, pin.visualize.MeshcatVisualizer):
39  import meshcat
40 
41  viz.viewer[name].set_object(
42  meshcat.geometry.Sphere(size), meshcat_material(*rgba)
43  )
44  elif isinstance(viz, pin.visualize.GepettoVisualizer):
45  viz.viewer.gui.addSphere(name, size, rgba)
46  else:
47  msg = f"Viewer {viz.__class__} is not supported."
48  raise AttributeError(msg)
49 
50 
51 def applyViewerConfiguration(viz, name, xyzquat):
52  if isinstance(viz, pin.visualize.MeshcatVisualizer):
53  viz.viewer[name].set_transform(meshcat_transform(*xyzquat))
54  elif isinstance(viz, pin.visualize.GepettoVisualizer):
55  viz.viewer.gui.applyConfiguration(name, xyzquat)
56  viz.viewer.gui.refresh()
57  else:
58  msg = f"Viewer {viz.__class__} is not supported."
59  raise AttributeError(msg)
60 
61 
62 """
63 
64 
65  viz.viewer['world/ball'].set_object(meshcat.geometry.Sphere(.1),
66  meshcat_material(.2, .2, 1., .5))
67 viz.viewer['world/box'].set_transform(meshcat_transform(.5, .2, .2, 1, 0, 0, 0))
68 viz.viewer['world/ball'].set_transform(meshcat_transform(-.5, .2, .2, 1, 0, 0, 0))
69 """
vizutils.meshcat_transform
def meshcat_transform(x, y, z, q, u, a, t)
Definition: vizutils.py:16
vizutils.applyViewerConfiguration
def applyViewerConfiguration(viz, name, xyzquat)
Definition: vizutils.py:51
vizutils.addViewerBox
def addViewerBox(viz, name, sizex, sizey, sizez, rgba)
Definition: vizutils.py:23
vizutils.meshcat_material
def meshcat_material(r, g, b, a)
Definition: vizutils.py:7
vizutils.addViewerSphere
def addViewerSphere(viz, name, size, rgba)
Definition: vizutils.py:37


tsid
Author(s): Andrea Del Prete, Justin Carpentier
autogenerated on Thu Apr 3 2025 02:47:16