From 44d5fc9435dae63e75501fab1cc5ffdf089ad861 Mon Sep 17 00:00:00 2001 From: Michael Dawson-Haggerty Date: Tue, 21 Jan 2025 14:56:17 -0500 Subject: [PATCH] add test for #2332 --- tests/test_bounds.py | 10 ++++++---- tests/test_texture.py | 4 ++++ trimesh/exchange/obj.py | 6 +++++- trimesh/visual/material.py | 4 +--- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/tests/test_bounds.py b/tests/test_bounds.py index ce8453192..f4649be3d 100644 --- a/tests/test_bounds.py +++ b/tests/test_bounds.py @@ -9,18 +9,20 @@ def setUp(self): meshes = [g.get_mesh(i) for i in ["large_block.STL", "featuretype.STL"]] self.meshes = g.np.append(meshes, list(g.get_meshes(5))) - def test_obb_mesh_large(self): """Test the OBB functionality on really large sets of vertices.""" - torus_mesh = g.trimesh.creation.torus(major_radius=5, minor_radius=1, major_sections=512, minor_sections=256) + torus_mesh = g.trimesh.creation.torus( + major_radius=5, minor_radius=1, major_sections=512, minor_sections=256 + ) start = g.timeit.default_timer() g.trimesh.bounds.oriented_bounds(torus_mesh.vertices) stop = g.timeit.default_timer() # Make sure oriented bound estimation runs within 30 seconds. - assert stop - start < 30, f"Took {stop - start} seconds to estimate the oriented bounding box." - + assert ( + stop - start < 30 + ), f"Took {stop - start} seconds to estimate the oriented bounding box." def test_obb_mesh(self): """ diff --git a/tests/test_texture.py b/tests/test_texture.py index 44be47c6c..76f74ab12 100644 --- a/tests/test_texture.py +++ b/tests/test_texture.py @@ -23,6 +23,10 @@ def test_uv_to_color(self): def test_bad_uv(self): # get a textured OBJ m = g.get_mesh("fuze.obj", force="mesh") + + # check that we saved the original file path + assert m.visual.material.image.info["file_path"].endswith("fuze uv.obj") + # add malformed UV coordinates m.visual.uv = m.visual.uv[:100] m.merge_vertices() diff --git a/trimesh/exchange/obj.py b/trimesh/exchange/obj.py index 54e5af1e5..756563b42 100644 --- a/trimesh/exchange/obj.py +++ b/trimesh/exchange/obj.py @@ -1,3 +1,4 @@ +import os import re from collections import defaultdict, deque @@ -352,7 +353,10 @@ def parse_mtl(mtl, resolver=None): # an image file name material["image"] = Image.open(util.wrap_as_stream(file_data)) # also store the original map_kd file name - material[key] = file_name + material["image"].info["file_path"] = os.path.abspath( + os.path.join(getattr(resolver, "parent", ""), file_name) + ) + except BaseException: log.debug("failed to load image", exc_info=True) diff --git a/trimesh/visual/material.py b/trimesh/visual/material.py index 15d2fd0de..12acbbcb6 100644 --- a/trimesh/visual/material.py +++ b/trimesh/visual/material.py @@ -249,9 +249,7 @@ def __hash__(self): hash : int Xor hash of the contained materials. """ - hashed = int(np.bitwise_xor.reduce([hash(m) for m in self.materials])) - - return hashed + return int(np.bitwise_xor.reduce([hash(m) for m in self.materials])) def __iter__(self): return iter(self.materials)