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  raise AttributeError("Viewer %s is not supported." % viz.__class__)
34 
35 
36 def addViewerSphere(viz, name, size, rgba):
37  if isinstance(viz, pin.visualize.MeshcatVisualizer):
38  import meshcat
39 
40  viz.viewer[name].set_object(
41  meshcat.geometry.Sphere(size), meshcat_material(*rgba)
42  )
43  elif isinstance(viz, pin.visualize.GepettoVisualizer):
44  viz.viewer.gui.addSphere(name, size, rgba)
45  else:
46  raise AttributeError("Viewer %s is not supported." % viz.__class__)
47 
48 
49 def applyViewerConfiguration(viz, name, xyzquat):
50  if isinstance(viz, pin.visualize.MeshcatVisualizer):
51  viz.viewer[name].set_transform(meshcat_transform(*xyzquat))
52  elif isinstance(viz, pin.visualize.GepettoVisualizer):
53  viz.viewer.gui.applyConfiguration(name, xyzquat)
54  viz.viewer.gui.refresh()
55  else:
56  raise AttributeError("Viewer %s is not supported." % viz.__class__)
57 
58 
59 """
60 
61 
62  viz.viewer['world/ball'].set_object(meshcat.geometry.Sphere(.1),
63  meshcat_material(.2, .2, 1., .5))
64 viz.viewer['world/box'].set_transform(meshcat_transform(.5, .2, .2, 1, 0, 0, 0))
65 viz.viewer['world/ball'].set_transform(meshcat_transform(-.5, .2, .2, 1, 0, 0, 0))
66 """
def meshcat_transform(x, y, z, q, u, a, t)
Definition: vizutils.py:16
def meshcat_material(r, g, b, a)
Definition: vizutils.py:7
def applyViewerConfiguration(viz, name, xyzquat)
Definition: vizutils.py:49
def addViewerSphere(viz, name, size, rgba)
Definition: vizutils.py:36
def addViewerBox(viz, name, sizex, sizey, sizez, rgba)
Definition: vizutils.py:23


tsid
Author(s): Andrea Del Prete, Justin Carpentier
autogenerated on Sun Jul 2 2023 02:21:51