question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ray.IntersectSphere returns a hit for NaN values

See original GitHub issue
Description of the problem

If the sphere in Ray.IntersectSphere has any null or NaN values, the function will return a modified target with its values set to NaN rather than returning null as expected for a non-intersection. When used in raycasting the result is that an object with invalid values is permanently added to the top of the list of current intersections.

The culprit is:

https://github.com/mrdoob/three.js/blob/dev/src/math/Ray.js#L266

As it is using a truthy condition to inditcate a miss. Reversing the comparison to:

if ( !(d2 <= radius2) ) return null;

Would instead return null if either value is invalid.

Three.js version
  • Dev
  • r93
Browser
  • All of them
  • Chrome
  • Firefox
  • Internet Explorer
OS
  • All of them
  • Windows
  • macOS
  • Linux
  • Android
  • iOS

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
WestLangleycommented, Jun 6, 2018

three.js expects valid data – not null, NaN, or missing; it is up to your application layer to ensure that.

If three.js accommodated invalid data in this method, it would have to do so in every method.

I’m extending the raycaster to support instanced geometry

Instanced geometry is very flexible, and it may be difficult to support instanced-raycasting in general, but a three.js example in which that is done would be awesome, if you are interested. 😃

0reactions
Mugen87commented, Jun 13, 2018

three.js expects valid data – not null, NaN, or missing; it is up to your application layer to ensure that.

Correct. Closing the issue since it’s an app related issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ray intersection with INFINITE number of spheres
My problem is that I have an infinite number of spheres that lie on a grid, with constant sized steps between them. I...
Read more >
Fast Ray Sphere collision code [closed]
UPDATE: The following sample returns the interval T along the ray and the point of intersection Q. You can calculate the normal of...
Read more >
Precision Improvements for Ray/Sphere Intersection
To find the intersection between the sphere and the ray we can replace P by ... These t-values can be plugged into the...
Read more >
A Minimal Ray-Tracer: Rendering Spheres - Scratchapixel
Once we know the value for t0 computing the position of the intersection or hit point is straightforward. We just need to use...
Read more >
raycast/sphere.cpp at master - GitHub
The function should return the parameter value for the intersection, ... float intersect_sphere(Point o, Vector ray, Spheres *sph, Point* hit).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found