-
-
Notifications
You must be signed in to change notification settings - Fork 35.6k
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
Directional light target position cannot be updated #10220
Comments
I don't think thats a good idea. The scene object represents a so called More about this concept: Scene Graph Maybe we could enhance the scene docs with some of these information. |
#10218 refers to the same topic... |
@Mugen87 the issue is that the DirectionalLight is instantiated with a target, which is used in calculating the direction, but which is not automatically updated unless it's added to the scene graph along with the light. Most users would reasonably expect otherwise, so this behaviour is quite unintuitive. A better solution would be for the default DirectionalLight to be untargeted and have its direction set by its rotation. |
If something is not added to the scene, it doesn't exist in that scene (obviously ... ) |
@mrdumb that's not correct, all Object3D's and derived classes have a .matrixWorld whether or not they are in the scene. It's used to show the transform of the object relative to its parent, and if it doesn't have a parent will be identical to its local .matrix You can manually call DirectionalLight.target.updateMatrixWorld() and it updates the matrixWorld fine even though it's not in the scene. The issue here is that an object that is added to the scene (and thus has its matrixWorld automatically updated) relies in its calculations on an object that is not by default added to the scene (and thus doesn't have its matrixWorld automatically updated), leading to unintuitive behaviour. I'm just wondering what the best way to deal with this is - whether to just document and forget about it, or if we can make the process automatic so that people using the library are not faced with this issue. |
Can you estimate the height of someone if you don't see him? |
@mrdumb this is my point exactly - the DirectionalLight.target.matrixWorld is being used to calculate the direction of the DirectionalLight without the DirectionalLight.target being part of the scene... |
Related thread: #5555 |
Could you add an updateMatrixWorld() method to the light, which calls the base object3d updateMatrixWorld and updates the light target? Transparent to user, downside is the target gets updated twice if part of scene. |
personally I found "target" to be more of a distraction that something useful on "Directional" light. I have a wrapper around it that only reasons in terms of "direction" and never "target". Even "position" of a directed light is not a meaningful concept as there is no source in the strictest sense, if you wanted to model one - it would be a plane negative infinite distance along the direction vector. |
Lights require a
The
The target is a property of the light, not a child of the light. Also, I think the current best solution is to continue to do what we have been recommending for a long time: make a note to the user to add the target to the scene graph -- at least until |
@WestLangley what do you think of the idea of adding a lookAt function to the light as discussed in #5555? It seems like this would be relatively straightforward, it would just have to set the target's position and call target.updateMatrixWorld() ( plus a few checks for the situation where the target has been changed to a different object). |
@WestLangley I was suggesting that updateMatrixWorld() for the light basically did: Object3D.prototype.updateMatrixWorld.call (this); I wasn't thinking it was a child, Do the same issues effect SpotLight? |
@looeee @aardgoose Yes, that seems to be a reasonable approach to consider, but @mrdoob has been advocating removing Until then, some comments in the docs advising the user to add the target to the scene graph is appropriate. |
@WestLangley |
Added information on light targets the docs, and there are many similar open issues to this one, closing. |
The directional light calculates its direction based on its position and the position of its target, which is an empty Object3D set by default at the origin.
It uses the matrixWorld property of its target for calculation, so if the position of the target is updated the target.matrixWorld needs to be updated too, and this doesn't happen automatically unless it is added to the scene. See #10218
So if I do this:
Then do this:
I would expect the light to switch to shining from the bottom up. However nothing happens because the light.target.matrixWorld doesn't get updated.
One possible fix is to add the target to the scene alongside the light:
Now things work as expected. I can update the docs to reflect this requirement if people think it's the best approach.
But it would be great if it was automatic. Perhaps the Object3d.add() function could be extended to check if an object has a .target and if so add that too?
The text was updated successfully, but these errors were encountered: