Skip to content

Commit

Permalink
Add the possibility to pass the color as a float if the user wants to…
Browse files Browse the repository at this point in the history
… specify just the alpha channel in meshcat_visualizer.py
  • Loading branch information
GiulioRomualdi committed Oct 25, 2022
1 parent b678127 commit b37c71c
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions bindings/python/visualize/meshcat_visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def __primitive_geometry_exists(self, geometry_name: str):
return geometry_name in self.primitive_geometries_names

def __add_model_geometry_to_viewer(
self, model_geometry: idyn.ModelSolidShapes, model_name: str, color: list
self, model_geometry: idyn.ModelSolidShapes, model_name: str, color
):
import meshcat

Expand Down Expand Up @@ -226,8 +226,23 @@ def __add_model_geometry_to_viewer(
# Set material color from URDF, converting for triplet of doubles to a single int.
if color is None:
mesh_color = solid_shape.getMaterial().color()
elif isinstance(color, float):
mesh_color = solid_shape.getMaterial().color()
mesh_color[3] = color
elif isinstance(color, list):
if len(color) == 4:
mesh_color = color
elif len(color) == 3:
mesh_color = color
mesh_color.append(1.0)
else:
mesh_color = [1.0, 1.0, 1.0, 1.0]
msg = "Non compatible color type. Please pass a list if you want to specify the rgb and the alpha or just a float to specify the alpha channel."
warnings.warn(msg, category=UserWarning, stacklevel=2)
else:
mesh_color = color
mesh_color = [1.0, 1.0, 1.0, 1.0]
msg = "Non compatible color type. Please pass a list if you want to specify the rgb and the alpha or just a float to specify the alpha channel."
warnings.warn(msg, category=UserWarning, stacklevel=2)

material.color = (
int(mesh_color[0] * 255) * 256 ** 2
Expand Down

0 comments on commit b37c71c

Please sign in to comment.