Closed ToyboxZach closed 10 hours ago
This is the reality of raycasting exactly on a shared edge of two triangles, I think. You'll see that three.js' raycaster.interectObject
exhibits the same issue. A raycast here will either have to produce two hits for the same point or none, and the implementation three.js has chose returns none. In the case of duplicate points you could deduplicate them by checking if it's a point that lies on an identical edge but the "correct" thing to do isn't necessarily obvious, I don't think.
Either way this project aims to return the same results that three.js returns so you may want to raise this in the three.js repo, instead.
Hmm maybe there is some confusion about what it should be hitting.
Here is an updated fiddle: https://jsfiddle.net/ers18ca5/59/
I compare it to the ray caster from threejs to show that in this case it is different. I also rendered the line so you can see what it is hitting.
The fiddle isn't comparing the same calculations. Three.js' Mesh class transforms the ray by the inverted world matrix (in this case an identity matrix) which will still have a small effect on the ray values even if the mesh has identity transform values. The acceleratedRaycast
function in this project does the same.
Here's a cleaned up and fixed fiddle showing that if you multiply an identity matrix in before calling raycastFirst you get the same results.
Ah, I see. I didn’t realize threejs was doing an extra calculation. It does seem there is a threejs bug.
I fixed my case by just doing two ray casts with slightly different numbers, but I do still hit one case that I think might be bvh related since I’m not at the edge of a face but I’m casting right through the object.
It’s in the middle of a bigger calculation but Im going to try to isolate it better and see where the problem arises and I’ll close this issue if its unrelated
Describe the bug I am getting some weird behavior when probably due to floating point precision when dealing with raycasts.
I am trying to investigate some three-bvh-csg issues and I'm getting into a weird case where my raycast is failing to hit a flat plane sometimes.
Code
Live example https://jsfiddle.net/8w0ukx4o/53/
Expected behavior I would expect all my casts to either succeed or all to fail, I'm not sure which, but moving the origin just a small delta from my initial cast can make it hit. Even in multiple directions
Screenshots
This is the line, so its not right on the edge of the face or anything:
My analysis of it might be off, but I hit this case pretty deep into an algorithm, and this should be hitting this face