diff --git a/bindings/python/visualize/meshcat_visualizer.py b/bindings/python/visualize/meshcat_visualizer.py index 054776452b..32db85a2d0 100644 --- a/bindings/python/visualize/meshcat_visualizer.py +++ b/bindings/python/visualize/meshcat_visualizer.py @@ -511,3 +511,19 @@ def load_box(self, x, y, z, shape_name="iDynTree", color=None): self.load_primitive_geometry( solid_shape=box, shape_name=shape_name, color=color ) + + def delete(self, shape_name="iDynTree"): + if self.__primitive_geometry_exists(shape_name): + self.viewer[shape_name].delete() + self.primitive_geometries_names.remove(shape_name) + elif self.__arrow_exists(shape_name): + self.viewer[shape_name].delete() + self.arrow_names.remove(shape_name) + elif self.__model_exists(shape_name): + self.viewer[shape_name].delete() + del self.model[shape_name] + del self.traversal[shape_name] + del self.link_pos[shape_name] + else: + msg = "The object named: " + name + " does not exist." + warnings.warn(msg, category=UserWarning, stacklevel=2)