Ray collision fails when origin in a face #759

Closed
danielribeiro opened this Issue Nov 15, 2011 · 8 comments

Projects

None yet

4 participants

@danielribeiro
Contributor

Hi,

When I cast a ray with origin point inside the face of a Mesh, it won't detect a collision. Quick example (a modified version of examples/canvas_interactive_cubes.html from r45): https://gist.github.com/1366114

Noting that,

var V = THREE.Vector3;

changing the line 159 of the gist, from

var origin = new V(20, 20, 20);

to

var origin = new V(19.5, 19.5, 19.5);

shows that the collision will work fine.

@mrdoob
Owner
mrdoob commented Nov 15, 2011

Your code didn't seem to work with r46.

However, using this code I can indeed reproduce the issue:

var origin = new THREE.Vector3(0, 0, 10);
var direction = new THREE.Vector3( 0, 0, -1);
var ray = new THREE.Ray( origin, direction );
@danielribeiro
Contributor

Ah, that's good. Sorry I forgot to mention, but the bug did happened on r46 and dev branch, and it was coded for dev branch using the Ray.js from the dev branch (the Three.js build doesn't seem to use the latest Ray.js, this is why I included under the name newray.js).

But I'm glad you managed to reproduce it.

@mrdoob
Owner
mrdoob commented Oct 18, 2013

Is this still happening?

@danielribeiro
Contributor

I'll try to repro it.

@jotinha
Contributor
jotinha commented Oct 20, 2013

I think this still happens. The culprit is a few lines in Raycaster that look like this

if ( distance < precision || distance < raycaster.near || distance > raycaster.far ) continue;

So, apparently, if the origin is too close to a plane (distance is zero), it will abort the intersection test. I'm not sure what was the original intended behavior here.

@danielribeiro
Contributor

@mrdoob Yes, it still happens. jsFiddle showing it:

http://jsfiddle.net/9CczQ/3/

The original webgl_interactive_cubes (for comparison's sake) is http://jsfiddle.net/9CczQ/1

@kevanstannard
Contributor

@mrdoob do you think this might be resolved now? I created a simple test and it seems to be working correctly, but not sure if I understood the original problem properly.

https://jsfiddle.net/sveom5ay/1/

@mrdoob
Owner
mrdoob commented Jan 28, 2017

@kevanstannard Seems to be. Thanks!

@mrdoob mrdoob closed this Jan 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment