diff --git a/pyproject.toml b/pyproject.toml index 307b0a336..afc301cf7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ requires = ["setuptools >= 61.0", "wheel"] [project] name = "trimesh" requires-python = ">=3.7" -version = "4.0.7" +version = "4.0.8" authors = [{name = "Michael Dawson-Haggerty", email = "mikedh@kerfed.com"}] license = {file = "LICENSE.md"} description = "Import, export, process, analyze and view triangular meshes." diff --git a/tests/test_scenegraph.py b/tests/test_scenegraph.py index 56f900036..77e787f3e 100644 --- a/tests/test_scenegraph.py +++ b/tests/test_scenegraph.py @@ -65,6 +65,21 @@ def test_nodes(self): # should have dumped the cache and removed the node assert node not in graph.nodes + def test_remove_geometries(self): + # remove geometries from a scene graph + scene = g.get_mesh("cycloidal.3DXML") + + # only keep geometry instances of these + keep = {"disc_cam_A", "disc_cam_B", "vxb-6800-2rs"} + + assert len(scene.duplicate_nodes) == 12 + + # should remove instance references except `keep` + scene.graph.remove_geometries(set(scene.geometry.keys()).difference(keep)) + + # there should now be three groups of duplicate nodes + assert len(scene.duplicate_nodes) == len(keep) + def test_kwargs(self): # test the function that converts various # arguments into a homogeneous transformation diff --git a/trimesh/scene/transforms.py b/trimesh/scene/transforms.py index 9580391f0..bc9d54d56 100644 --- a/trimesh/scene/transforms.py +++ b/trimesh/scene/transforms.py @@ -1,5 +1,6 @@ import collections from copy import deepcopy +from typing import Sequence import numpy as np @@ -473,7 +474,7 @@ def geometry_nodes(self): res[attr["geometry"]].append(node) return res - def remove_geometries(self, geometries): + def remove_geometries(self, geometries: Sequence): """ Remove the reference for specified geometries from nodes without deleting the node. @@ -498,6 +499,7 @@ def remove_geometries(self, geometries): # but the only property using the geometry should be # nodes_geometry: if this becomes not true change this to clear! self._cache.cache.pop("nodes_geometry", None) + self.transforms._hash = None def __contains__(self, key): return key in self.transforms.node_data diff --git a/trimesh/typed.py b/trimesh/typed.py index 5527e3043..35a462753 100644 --- a/trimesh/typed.py +++ b/trimesh/typed.py @@ -1,3 +1,4 @@ +from pathlib import Path from typing import IO, Dict, List, Optional, Sequence, Tuple, Union # our default integer and floating point types @@ -11,7 +12,7 @@ # most loader routes take `file_obj` which can either be # a file-like object or a file path -Loadable = Union[str, IO] +Loadable = Union[str, Path, IO] __all__ = [ "NDArray",