-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
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
SpotLightHelper: Fix offset when adjusting the scene / parent position #27487
Conversation
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
I understand this works but I'm a bit unhappy about the resulting complexity in |
The requirement to add helpers to the root scene has confused me countless times in the past. Asking users to add a helper to a specific parent so that it works betrays all expectation around the transform hierarchy works. This would be a significantly worse user experience for the helpers.
I don't agree that it's so complicated. These are matrix transformations that are used throughout the project. But either way this is a transformation that should be used across all helpers - BoxHelper, CameraHelper, DirectionalLightHelper, etc should all implement this the same way. If this is added then we should add a super class that shares an updateMatrixWorld implementation among all child helper classes. Can you elaborate on what you feel is complex? |
The need to overwrite My point is I favor an assumption like "spot light helper must be child of the light" if that makes the overall implementation easier. |
There are quite a few other classes that also overwrite
The transformation happening is no different than the one required for transforming an object into the camera frame. It's fundamental to rendering graphics. |
I'm okay with merging this new version. As long as we keep the current helper policy we should make sure to fix #27437 and that's what the PR does. |
What's the expectation for helpers? Some of them update themselves in |
If we want to refactor the world update matrix logic at some point, it would be good if |
src/helpers/SpotLightHelper.js
Outdated
|
||
} | ||
|
||
this.matrix.decompose( this.position, this.quaternion, this.scale ); |
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.
Why are you doing this -- instead of retaining this.matrixAutoUpdate = false
?
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.
I suppose I could do that. It would probably be best to se matrixWorldAutoUpdate
to false but tbh the matrix / matrixWorld update behavior is fairly confusing to me, now. For example the Object3D.lookAt
function will call updateWorldMatrix which will automatically update the objects matrixWorld even if matrixWorldAutoUpdate
is false.
It's not clear to me when they do and don't apply so I fallback to keeping all the values in sync which I think is more clear, anyway.
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.
I'd avoid unnecessarily calling matrix.decompose()
for this helper. JMO, of course.
if ( this.parent ) { | ||
|
||
this.matrix | ||
.copy( this.parent.matrixWorld ) |
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.
Is this matrix necessarily current?
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.
I suppose that's true - I can call this.parent.updateMatrixWorld
but it has the same caveats as mentioned in #27487 (comment) in that it will undermine the users parent.matrixWorldAutoUpdate
setting if it's set to false.
Fixed #27437
Description
Previously SpotLightHelper was just copying the target light's
matrixWorld
into its localmatrix
field resulting in offsets when the parent was not at 0, 0, 0. Now the target light transform is correctly transformed into the local frame that the helper exists in and it's no longer required to add the helpers to the root of the scene.This is for another PR but I'm wondering if "update" can just be removed and effectively called in "updateMatrixWorld"?