diff --git a/CHANGELOG.md b/CHANGELOG.md index 9fb99a74e7..4f0dcc3c0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - CMake: Permit to explicitly specify Python installation directory by setting the `IDYNTREE_PYTHON_INSTALL_DIR` CMake variable (https://github.com/robotology/idyntree/pull/1124). +- MeshcatVisualizer: Add the possibility to remove a mesh from the visualizer (https://github.com/robotology/idyntree/pull/1138) + ### Fixed - Fixed compilation of pybind11 bindings (https://github.com/robotology/idyntree/pull/1128). 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)