Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def loadViewerGeometryObject(self, geometry_object,geometry_type, color=None):
"""Load a single geometry object"""
import meshcat.geometry
viewer_name = self.getViewerNodeName(geometry_object, geometry_type)
if geometry_object.meshPath == "":
raise IOError("{} mesh file not found for link {}.".format(str(geometry_type).lower(),geometry_object.name))
# Get file type from filename extension.
_, file_extension = os.path.splitext(geometry_object.meshPath)
if file_extension.lower() == ".dae":
obj = meshcat.geometry.DaeMeshGeometry.from_file(geometry_object.meshPath)
elif file_extension.lower() == ".obj":
obj = meshcat.geometry.ObjMeshGeometry.from_file(geometry_object.meshPath)
elif file_extension.lower() == ".stl":
obj = meshcat.geometry.StlMeshGeometry.from_file(geometry_object.meshPath)
else:
raise ImportError("Unknown mesh file format: {}.".format(geometry_object.meshPath))
material = meshcat.geometry.MeshPhongMaterial()
# Set material color from URDF, converting for triplet of doubles to a single int.
if color is None:
meshColor = geometry_object.meshColor
else:
meshColor = color
material.color = int(meshColor[0] * 255) * 256**2 + int(meshColor[1] * 255) * 256 + int(meshColor[2] * 255)
# Add transparency, if needed.
if float(meshColor[3]) != 1.0:
material.transparent = True
material.opacity = float(meshColor[3])
self.viewer[viewer_name].set_object(obj, material)