Skip to content

Commit

Permalink
Merge pull request #2104 from mikedh/release/removegeom
Browse files Browse the repository at this point in the history
Release: Remove Geometries Fix And Pathlib
  • Loading branch information
mikedh authored Dec 23, 2023
2 parents 7c90a94 + 9ed2aa0 commit 1d0f548
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[email protected]"}]
license = {file = "LICENSE.md"}
description = "Import, export, process, analyze and view triangular meshes."
Expand Down
15 changes: 15 additions & 0 deletions tests/test_scenegraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion trimesh/scene/transforms.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import collections
from copy import deepcopy
from typing import Sequence

import numpy as np

Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion trimesh/typed.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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",
Expand Down

0 comments on commit 1d0f548

Please sign in to comment.