mikedh / trimesh

Python library for loading and using triangular meshes.
https://trimesh.org
MIT License
3.02k stars 583 forks source link

Applying transformations to Trimesh breaks intersects_location with embree #2324

Open Willy19921992 opened 1 week ago

Willy19921992 commented 1 week ago

After importing a mesh and applying a transformation, embree suddenly stops returning any hits. I've made a simple program that replicates the issue.

import numpy as np
import trimesh

mesh = trimesh.load_mesh('model.obj', validate=True, use_embree=True)
mesh.apply_scale(1/64)
mesh2 = trimesh.load_mesh('model.obj', validate=True, use_embree=False)
mesh2.apply_scale(1/64)

point = np.array([64/64, 24/64, 64/64])
dir = np.array([0, 0, 1])

print(mesh.ray.intersects_location([point], [dir], multiple_hits=False))
print(mesh2.ray.intersects_location([point], [dir], multiple_hits=False))

Which prints the following:

(array([], shape=(0, 3), dtype=float64), array([], dtype=int64), array([], dtype=int32))
(array([[ 1.   ,  0.375, 19.   ]]), array([0]), array([1]))

If i remove the apply_scale call, embree starts working again. I've also tried to scale the model in Blender, then importing the scaled model and embree works just fine. Setting multiple_hits to True doesn't change the behaviour.

Im using Python 3.12.7, Trimesh 4.5.2, rtree 1.3.0, embree 4.3.3 and embreex 2.17.7.post5.