Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ray_pyembree.intersects_any and ray_pyembree.intersects_id produce incorrect results #1496

Open
YuanWenqing opened this issue Feb 15, 2022 · 1 comment

Comments

@YuanWenqing
Copy link
Contributor

YuanWenqing commented Feb 15, 2022

I'm trying to test whether a bigger mesh is blocked by a small mesh and I found that ray test results are weird in some cases.

I compared results of intersects_any and intersects_id in both of ray_pyembree and ray_triangle. Results by ray_pyembree does not match while results by ray_triangle do match as expected. Meanwhile in some case ray_pyembree.intersects_any also gives incorrect result.

I don't know whether this bug is from pyembree or trimesh.ray.ray_pyembree. But it seems that all rays mis-checked by ray_pyembree pass through some vertices or edges of the small mesh. So I guess the bug may be a precision issue.

I tried this code below to reproduce my issue. Every ray passes through some vertices or edges of the small mesh and still some rays are mis-checked in intersects_id.

ray=trimesh.ray.ray_pyembree
# ray=trimesh.ray.ray_triangle

small=trimesh.creation.box(extents=np.full(3,40)).subdivide_to_size(20)
big=trimesh.creation.box(extents=np.full(3,60)).subdivide_to_size(20)
print('small:',small)
print('big:',big)
small.export('/tmp/small.obj')
big.export('/tmp/big.obj')

origin=np.zeros(3)
intersector = ray.RayMeshIntersector(small)
ray_origins=np.tile(origin, (len(big.vertices),1))
ray_directions=big.vertices-origin
intersected=intersector.intersects_any(ray_origins,ray_directions)
ray_idx=intersector.intersects_id(ray_origins,ray_directions,multiple_hits=False)[1]

reserved=np.reshape(np.in1d(big.faces.ravel(),ray_idx),(-1,3)).all(axis=1)
filtered1=trimesh.Trimesh(big.vertices,big.faces[reserved])
filtered1.export('/tmp/filtered1.obj')

reserved=np.all(intersected[big.faces],axis=1)
filtered2=trimesh.Trimesh(big.vertices,big.faces[reserved])
filtered2.export('/tmp/filtered2.obj')

print('intersects_any:',intersected.shape)
print('intersects_id:',ray_idx.shape)

Results:

small: <trimesh.Trimesh(vertices.shape=(98, 3), faces.shape=(192, 3))>
big: <trimesh.Trimesh(vertices.shape=(386, 3), faces.shape=(768, 3))>
intersects_any: (386,)
intersects_id: (373,)

Visual small mesh, big mesh, filtered1 mesh(by intersects_id) and rays:

image

Visual small mesh, big mesh, filtered2 mesh(intersects_any) and rays:
image

@YuanWenqing YuanWenqing changed the title ray test results do not match by ray_pyembree.intersects_any and ray_pyembree.intersects_id ray_pyembree.intersects_any and ray_pyembree.intersects_id produce incorrect results Feb 15, 2022
@mikedh
Copy link
Owner

mikedh commented Feb 15, 2022

Hey, yeah unfortunately embree doesn't make particularly strong promises:
RenderKit/embree#188
RenderKit/embree#174
RenderKit/embree#181

I'm hoping at some point to get some of the variants/forks of #1108 merged, and the upstream embree-3 package set up with cibuildwheel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants