Hi dearest community,
I’ve encountered some strange behaviour: Sometimes raycastAll hits the wrong faces.
- raycastFirst on mesh with triangles exported: WORKS
- raycastFirst on mesh with quads exported: WORKS
- raycastAll on mesh with triangles exported: WORKS SOME TIMES?
- raycastAll on mesh with quads exported: WORKS
Internally, the physics should convert the quads into triangles, which makes the behaviour even weirder.
Please find the sample project here: https://playcanvas.com/project/722719/overview/forum-raycasting-quads
Maybe I’ve found a strange bug here, or maybe I just need some more sleep.
Anyways, any hints appreciated.
Have a great day,
Rene
EDIT:
raycastAll also returns one additional raycast result at the backface. The returned results are not sorted by distance, so one could do it manually like this (sample position is the start position of the raycast):
Raycaster.prototype._getNearestResult = function(samplePosition, results)
{
var nearestDistance = Number.MAX_VALUE;
var nearestResult = null;
for(var i=0; i<results.length; i++)
{
var distance = samplePosition.clone().sub(results[i].point).lengthSq();
if(distance < nearestDistance)
{
nearestResult = results[i];
nearestDistance = distance;
}
}
return nearestResult;
};
This works for me, but I’m still curious why it returns a result on an outward facing normal and sorts the results differently on quads…