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 Intersect**** functions do not change target to null

See original GitHub issue

These targets are giving me the run around. But basically the issue i see is that ray intersect should make the target null if no intersect is found. Instead it returns unchanged target if no intersect is found. This makes it impossible to tell if target was the same or just not found or defeats the purpose of re-using target, since it has to be cleared all the time.

 var sphere = new THREE.Sphere( new THREE.Vector3(0,0,0), 5 )
 var ray = new THREE.Ray(new THREE.Vector3(0,10,0), new THREE.Vector3(0,1,0));
 var target = new THREE.Vector3();
 ray.intersectSphere(sphere,target);
console.log(target); // p {x: 0, y: 0, z: 0} !!!!!

fiddle

Three.js version
  • Dev
  • [x ] r92
Browser
  • All of them
  • Chrome
  • Firefox
  • Internet Explorer
OS
  • All of them
  • Windows
  • macOS
  • Linux
  • Android
  • iOS
Hardware Requirements (graphics card, VR Device, …)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
hccamposcommented, May 9, 2018

If there is an intersection, it fills the target with the intersection and returns it (no new object allocated). Otherwise, it just returns null. So you make your target once when the app starts and then you just reuse it afterwards.

1reaction
hccamposcommented, May 9, 2018

The targets are just to avoid unnecessary memory allocation and motivate people to reuse objects. If you are not in the hot path and don’t care about too much garbage being generated you can just do ray.intersectSphere(sphere, new THREE.Vector3()); and call it a day. It is equivalent to what it used to do when no target was provided.

Anyway, maybe this is moving towards territory that would better be served by a post in https://discourse.threejs.org/

Read more comments on GitHub >

github_iconTop Results From Across the Web

THREE.js Ray Intersect fails by adding div - Stack Overflow
intersectObjects returns null. I doubt that the vector that I am creating for ray is causing the problem. Here is the code.
Read more >
Raycaster#intersectObject – three.js docs
This field can be set manually or is set when calling "setFromCamera". Defaults to null. # .layers : Layers. Used by Raycaster to...
Read more >
intersect VEX function - Geometry - SideFX
Computes the first intersection of the specified ray with the geometry. To get all intersections along a vector, use intersect_all instead.
Read more >
GitHub - gkjohnson/three-mesh-bvh
Setting "firstHitOnly" to true means the Mesh.raycast function will use the // bvh ... Indicates the shape did not intersect the given bounding...
Read more >
Raycasts in Unity, made easy - Game Dev Beginner
Raycast in Unity is a Physics function that projects a Ray into the scene, returning a boolean value if a target was successfully...
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