Skip to content

Commit

Permalink
add test for #2332
Browse files Browse the repository at this point in the history
  • Loading branch information
mikedh committed Jan 21, 2025
1 parent 63e06b9 commit 44d5fc9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
10 changes: 6 additions & 4 deletions tests/test_bounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
4 changes: 4 additions & 0 deletions tests/test_texture.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 5 additions & 1 deletion trimesh/exchange/obj.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import re
from collections import defaultdict, deque

Expand Down Expand Up @@ -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)

Expand Down
4 changes: 1 addition & 3 deletions trimesh/visual/material.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 44d5fc9

Please sign in to comment.