1 from ..
import pinocchio_pywrap
as pin
2 from ..shortcuts
import buildModelsFromUrdf, createDatas
3 from ..utils
import npToTuple
5 from .
import BaseVisualizer
11 WITH_HPP_FCL_BINDINGS =
True 13 WITH_HPP_FCL_BINDINGS =
False 16 """A Pinocchio display using Gepetto Viewer""" 19 """Return the name of the geometry object inside the viewer""" 20 if geometry_type
is pin.GeometryType.VISUAL:
22 elif geometry_type
is pin.GeometryType.COLLISION:
25 def initViewer(self, viewer=None, windowName="python-pinocchio", sceneName="world", loadModel=False):
26 """Init GepettoViewer by loading the gui and creating a window.""" 29 import gepetto.corbaserver
32 msg = (
"Error while importing the viewer client.\n" 33 "Check whether gepetto-gui is properly installed" 35 warnings.warn(msg, category=UserWarning, stacklevel=2)
38 self.
viewer = gepetto.corbaserver.Client()
if viewer
is None else viewer
42 window_l = gui.getWindowList()
43 if not windowName
in window_l:
49 scene_l = gui.getSceneList()
50 if sceneName
not in scene_l:
51 gui.createScene(sceneName)
53 gui.addSceneToWindow(sceneName, self.
windowID)
59 msg = (
"Error while starting the viewer client.\n" 60 "Check whether gepetto-viewer is properly started" 62 warnings.warn(msg, category=UserWarning, stacklevel=2)
68 meshColor = geometry_object.meshColor
70 geom = geometry_object.geometry
71 if isinstance(geom, hppfcl.Capsule):
72 return gui.addCapsule(meshName, geom.radius, 2. * geom.halfLength,
npToTuple(meshColor))
73 elif isinstance(geom, hppfcl.Cylinder):
74 return gui.addCylinder(meshName, geom.radius, 2. * geom.halfLength,
npToTuple(meshColor))
75 elif isinstance(geom, hppfcl.Box):
77 return gui.addBox(meshName, w, h, d,
npToTuple(meshColor))
78 elif isinstance(geom, hppfcl.Sphere):
79 return gui.addSphere(meshName, geom.radius,
npToTuple(meshColor))
80 elif isinstance(geom, hppfcl.Cone):
81 return gui.addCone(meshName, geom.radius, 2. * geom.halfLength,
npToTuple(meshColor))
82 elif isinstance(geom, hppfcl.Convex):
83 pts = [
npToTuple(geom.points(geom.polygons(f)[i]))
for f
in range(geom.num_polygons)
for i
in range(3) ]
84 gui.addCurve(meshName, pts,
npToTuple(meshColor))
85 gui.setCurveMode(meshName,
"TRIANGLES")
86 gui.setLightingMode(meshName,
"ON")
87 gui.setBoolProperty(meshName,
"BackfaceDrawing",
True)
89 elif isinstance(geom, hppfcl.ConvexBase):
90 pts = [
npToTuple(geom.points(i))
for i
in range(geom.num_points) ]
91 gui.addCurve(meshName, pts,
npToTuple(meshColor))
92 gui.setCurveMode(meshName,
"POINTS")
93 gui.setLightingMode(meshName,
"OFF")
96 msg =
"Unsupported geometry type for %s (%s)" % (geometry_object.name,
type(geom) )
97 warnings.warn(msg, category=UserWarning, stacklevel=2)
101 """Load a single geometry object""" 106 meshPath = geometry_object.meshPath
107 meshTexturePath = geometry_object.meshTexturePath
108 meshScale = geometry_object.meshScale
109 meshColor = geometry_object.meshColor
112 if WITH_HPP_FCL_BINDINGS
and isinstance(geometry_object.geometry, hppfcl.ShapeBase):
116 msg =
"Display of geometric primitives is supported only if pinocchio is build with HPP-FCL bindings." 117 warnings.warn(msg, category=UserWarning, stacklevel=2)
119 success = gui.addMesh(meshName, meshPath)
122 except Exception
as e:
123 msg =
"Error while loading geometry object: %s\nError message:\n%s" % (geometry_object.name, e)
124 warnings.warn(msg, category=UserWarning, stacklevel=2)
127 gui.setScale(meshName,
npToTuple(meshScale))
128 if geometry_object.overrideMaterial:
129 gui.setColor(meshName,
npToTuple(meshColor))
130 if meshTexturePath !=
'':
131 gui.setTexture(meshName, meshTexturePath)
134 """Create the scene displaying the robot meshes in gepetto-viewer""" 152 if self.collision_model
is not None:
153 for collision
in self.collision_model.geometryObjects:
156 self.
displayCollisions(self.collision_model
is not None and self.visual_model
is None)
158 if self.visual_model
is not None:
159 for visual
in self.visual_model.geometryObjects:
167 """Display the robot at configuration q in the viewer by placing all the bodies.""" 168 if 'viewer' not in self.__dict__:
174 pin.forwardKinematics(self.model,self.data,q)
177 pin.updateGeometryPlacements(self.model, self.data, self.collision_model, self.collision_data)
178 gui.applyConfigurations (
179 [ self.
getViewerNodeName(collision,pin.GeometryType.COLLISION)
for collision
in self.collision_model.geometryObjects ],
180 [ pin.SE3ToXYZQUATtuple(self.collision_data.oMg[self.collision_model.getGeometryId(collision.name)])
for collision
in self.collision_model.geometryObjects ]
184 pin.updateGeometryPlacements(self.model, self.data, self.visual_model, self.visual_data)
185 gui.applyConfigurations (
186 [ self.
getViewerNodeName(visual,pin.GeometryType.VISUAL)
for visual
in self.visual_model.geometryObjects ],
187 [ pin.SE3ToXYZQUATtuple(self.visual_data.oMg[self.visual_model.getGeometryId(visual.name)])
for visual
in self.visual_model.geometryObjects ]
193 """Set whether to display collision objects or not""" 196 if self.collision_model
is None:
return 199 visibility_mode =
"ON" 201 visibility_mode =
"OFF" 203 for collision
in self.collision_model.geometryObjects:
205 gui.setVisibility(nodeName,visibility_mode)
208 """Set whether to display visual objects or not""" 211 if self.visual_model
is None:
return 214 visibility_mode =
"ON" 216 visibility_mode =
"OFF" 218 for visual
in self.visual_model.geometryObjects:
220 gui.setVisibility(nodeName,visibility_mode)
222 __all__ = [
'GepettoVisualizer']
def loadViewerGeometryObject(self, geometry_object, geometry_type)
def initViewer(self, viewer=None, windowName="python-pinocchio", sceneName="world", loadModel=False)
def loadPrimitive(self, meshName, geometry_object)
def getViewerNodeName(self, geometry_object, geometry_type)
def displayVisuals(self, visibility)
def displayCollisions(self, visibility)
def loadViewerModel(self, rootNodeName="pinocchio")
def display(self, q=None)