Ray Intersect**** functions do not change target to null
See original GitHub issueThese 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} !!!!!
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:
- Created 5 years ago
- Comments:5
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
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/