Raycast weird intersections #1257
-
Hello guys, I'm trying to perform a basic ray casting to get some intersections, On the first glance everything looked fine, but once I dug it deeper, I found the intersection had a weird offset. On the image above you can see where I clicked, but the results appearing on the console suggests that I clicked in one of the lines geometry which are part of a group. Down below, the code I'm using (I know it's not the most efficient way to do it, but as of right now it's a POC, so it's 'good enough')
And finally the function which returns the objects I'm looking for:
I'm suspecting on the mouse coordinates I'm getting from useThree() hook, but I'm not sure.... Any advice here? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
the raycaster has a line threshold that you need to set, it's dependent on your fov and camera position. the default is 1 which could mean anything, in your case it positively hits that line. make it smaller and it won't. that's all just threejs doing its thing: https://threejs.org/docs/index.html?q=ray#api/en/core/Raycaster.params you can set these props directly on the canvas as a shortcut: <Canvas raycaster={{ params: { Line: { threshold: 0.1 } } }} btw i hope that's not how you raycast ... you should be doing: <mesh onPointerOver={e => ...}
<lineSegments onClick={e => ...} that is way more comfortable but also more efficient since its only hitting the objects that have handlers on them. |
Beta Was this translation helpful? Give feedback.
the raycaster has a line threshold that you need to set, it's dependent on your fov and camera position. the default is 1 which could mean anything, in your case it positively hits that line. make it smaller and it won't. that's all just threejs doing its thing: https://threejs.org/docs/index.html?q=ray#api/en/core/Raycaster.params
you can set these props directly on the canvas as a shortcut:
btw i hope that's not how you raycast ... you should be doing:
that is way more comfortable but also more efficient since its only hitting the objects that have handlers on them.