gkjohnson / three-mesh-bvh

A BVH implementation to speed up raycasting and enable spatial queries against three.js meshes.
https://gkjohnson.github.io/three-mesh-bvh/example/bundle/raycast.html
MIT License
2.38k stars 247 forks source link

Edge Projection Example: The derived overlaps do not account for triangle intersections #464

Open gkjohnson opened 1 year ago

gkjohnson commented 1 year ago

This code needs to account for edges the intersect the triangle since the overlaps need to just specify the range that is overlapped below the triangle.

https://github.com/gkjohnson/three-mesh-bvh/blob/0f2d01ba520282c12276753f70e07b0d5044a4b4/example/edgeProjection.js#L307-L313

Issue may be able to be reproduced with a box at this euler rotation:

x : 1.2254020312644092
y : - 0.9092266413635247
z : 2.2823000160928824

image

gkjohnson commented 1 year ago

It seems that the problem may be with trimming lines when the line intersects the triangle at a corner (see getEdgeOverlaps function)

Jittering the triangle points here in some random direction fixes this in quite a few cases, it seems.