-
-
Notifications
You must be signed in to change notification settings - Fork 35.7k
Raycaster.setFromCamera: Position the ray origin such that it is on the camera near plane #28027
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
const camera = new PerspectiveCamera( 90, 1, 1, 1000 ); | ||
const camera = new PerspectiveCamera( 90, 1, 0.1, 1000 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously the ray direction was being calculated with the "origin" being calculated as "0, 0, 0" which is used to calculate a delta vector in the setFromCamera
function. With the change in this PR the origin is at the near plane which is 1 unit from the camera origin resulting in a higher epsilon which Number.EPSILON was not high enough to test for. Lowering the near value lowers the values used in the origin vector and therefore the error in the calculations. From the MDN page on Number.EPSILON:
The Number.EPSILON static data property represents the difference between 1 and the smallest floating point number greater than 1.
Although the reason for the PR is sound, this is not how we should address it. We don't make changes to the ray origin of the raycaster, we change the places where we are erroneously projecting the e.g Lines 167 to 175 in 2ff77e4
As you can see, we are already trying to reproject |
The easiest way of fixing this without major reworks, is to keep But when we use I can't say whether or not changing Raycaster's |
There's nothing erroneous about the current Raycaster near/far implementation - it's working as intended. Raycaster has many other use cases beyond being used with a camera projection. The near and far value are designed to specify the distance along the ray, useful for things like only intersecting things nearby a VR controller for interaction, for example. Setting the near / far to projected distances in setFromCamera is something I've considered but it will not work for negative orthographic camera near values which I'm feeling should be valid. |
I'm fairly certain I wasn't clear, I apologize. I'll try to explain the 2 different problems here. The first one is that setting the raycaster origin projected to the near plane on Lines 167 to 170 in 2ff77e4
We are already attempting to do a similar thing inside some raycast functions, which means that we would first project the origin towards the near plane, and afterwards we would move along the ray direction yet again. Now, the confusion might be here, with the default raycaster.near value of 0, this doesn't make a difference. With other values - it breaks the logic. All I'm saying is that this PR isn't compatible with other functions reliant on Raycaster .
Aside from that, there is arguably a different problem, one might expect that after calling Since it might not be obvious to users how to guarantee frustum confinement, we can either implement it by default on |
This feels like manufacturing a problem. Near / far raycaster values were not added with the intent of solving this camera bounds issue (as in setting them directly doesn't work). I guess what you're saying is that peoples existing projects may incorrectly set the near value to fix this and now this will double the distance but I'm not convinced this is happening in real cases. Setting the near value in the setFromCamera also newly overrides any user settings. Either way in some cases this is a breaking change users may need to be aware of. Generally I don't agree the approach in this PR is incompatible with these other settings, though. It's just placing the ray origin at the near plane which is what I expected when using this. You're free to disagree but there's no objectively right answer here.
|
Negative values are not supported for raycaster.near |
Ok, I decided to review what's happening after a night of sleep, and I did misinterpret the original purpose for the PR. My bad, that's probably why we had apparently conflicting views about what's going on. I really wasn't trying to "manufacture a problem" haha. I interpreted the change of With that being said, If I understand correctly, the Eitherway it is subjective, whether or not my proposal is better or not than yours. As both introduce some form of breaking change.
edit: Ok, you probably mean copying the camera's Personally, I think introducing a boolean parameter to Sorry for the confusion. |
Fix #28026
Description
Adjust
Raycaster.setFromCamera
so the origin is placed on the camera near plane.