-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
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
Make Light targets optional #14658
base: dev
Are you sure you want to change the base?
Make Light targets optional #14658
Conversation
In simpler terms, after this PR there would be two ways to change the direction of these lights:
I think that this would be an improvement over the current situation which causes a lot of confusion. On the other hand, at least for In the case of #5079 a |
3e2eb41
to
e7c597c
Compare
PR updated : item 2 moved to its own PR #14663. Thanks @looeee for the pointers, I was not aware that the removal of the target feature had been debated ! So my proposal is a smoother breaking change than complete removal : instead of removing the feature, it is only disabled by default (the user has to create the target object to enable it).
If I got it right, it is more than that : the shadow camera will get exactly the matrixWorld of the light object and the light direction is extracted from this matrixWorld (as it is already done currently for the position). Thus setting it with lookAt is only one option, the user may manipulate the light object as any object3D (position, rotation...), similar to how a regular camera may be moved. |
@mbredif see also #13373 and my comment there. One compelling reason for removing the target completely is that three.js is the odd one out - nearly every other app doesn't have targets for their directional lights. I'm not sure what the situation is for spot lights. Your solution look like it may give us the best of both worlds though, we can set the light's rotation directly as other apps do and have a target if we want it. |
c166e46
to
9ab0e93
Compare
srcI have reworked the approach and I am now quite satisfied with having
examplesI have tried to update all examples, by :
Results look good and I see no errors left, but I find it hard to verify all examples by hand. Is there an automated way of doing it ? test
|
Unfortunately, that is a pretty inefficient method. I would avoid using it. Maybe try something like this: spotlight._target = new THREE.Object3D();
spotlight._target.position.set( 0, 0, 1 );
spotlight.add( _target ); You can then get the world direction of the spotlight from the world matrices of |
Good point, but IMHO that only means that the current getWorldDirection implementation is suboptimal... Provided matrixWorld is in sync, isn't it just a matter of reading the 3rd column ?
I can do another PR for that. |
Yes, that is much better. Normalize it, though, because the matrix may be scaled. |
40b6feb
to
9350a77
Compare
See #14677 for the getWorldDirection optimization. Any clue on the test correction and on the example verification ? |
9ebdbd4
to
e54fd2a
Compare
Ok I figured out to fix the test (this.matrix was out of sync). This PR is now ready for testing/review ! |
ddbdbaa
to
4ff4805
Compare
As discussed in #14688, use |
4ff4805
to
8558967
Compare
Well, if we are ok with a breaking change here in order to be in line with other apps, that seems like the better option rather than removing the target completely. That way when people have to update their code that uses a light target, they just have to add 'light.targeted = true'. If we remove the target completely then they may have to do considerable refactoring. |
Up ! |
ded7295
to
8beeea2
Compare
As @WestLangley said: Removing targets from lights was suggested by @mrdoob years ago. @mbredif has invested a lot of effort implementing @mrdoob's suggestion. I think @mbredif is entitled to a response to #14658 (comment). @Mugen87 Would you also be willing to provide your feedback? (I expect you will have to read the entire thread carefully because a lot of issues were discussed.) I see @donmccurdy may also support this. In light of the discussion in #14935, perhaps you have a preferred implementation. // Please also see #14621. |
One approach to maintain backwards compatibility would be by doing something like this:
I took the "Free Spot Light" name from 3D Studio Max but open to better names. |
What would you think of reversed naming?
The latter could be moved to |
@mbredif Can you please update the PR? |
Still an issue! I think the target properties are about the soon-be-deprecated for at least 5 years now 🥲 |
@mrdoob @donmccurdy do you think you can agree on a naming for new light types? If so, which? |
Personally I'm fine with any of these proposals, but perhaps happiest if we have a solution compatible with moving the targeting logic (maybe, eventually) move into One more idea to throw into the hat, add a import { SpotLight } from 'three';
import { LightTarget } from 'three/addons/lights/LightTarget.js';
const light = new SpotLight();
light.position.set( 2, 1.5, 3 );
scene.add( light );
const target = new LightTarget().bind( light );
target.position.set( 0, 0, 0 );
scene.add( target ); |
Multiple times I've played around with the idea of changing the current way My latest branch where I have tested removing targets from light is here: Mugen87@2361111 There are two options: a) Removing targets from lights completely. Both of them result in more code in In the meanwhile, I have the feeling targeted lights actually make it easier to setup typical lit scenes (especially for beginners). I would not vote to completely remove targeted lights from In fact, directional and spot lights can already be "untargeted" by using the following setup: light.target.position.set( 0, 0, - 1 );
light.add( light.target ); Now you can rotate the light by changing its For testing: https://jsfiddle.net/ouqwsp64/2/ Maybe we can put the above code in new convenient methods for |
Does that "untargeting" approach work with three's scene serialization? Last time I checked the three.js editor always breaks when saving and opening a scene that has lights loaded from glTF because then they are targeted again and look in the wrong ways. (for the record, I'm still voting for untargeting by default as it is handled in all other 3D apps that I'm aware of) |
Not yet, but #28696 should add support for it. |
(This PR is the geometric counterpart of #14621)
This enables the use of custom user-provided OrthographicCameras for DirectionalLights and PerspectiveCameras for SpotLights, by making optional the 2 hardwired updates that were updating the cameras at each frame :
SpotLightShadow.update was modifying the shadowCamera to have (most notably) its fov fit its cone angle.Possible use-cases are, combined with #14621, to do image-based rendering by backprojecting images as textured lights, with photogrammetrically-estimated camera parameters, or to more simply implement a slide or video projector with user-provided intrinsics/extrinsics (focal, aspect, position, rotation...).
Proposals :
make cone fitting opt-out : SpotLightShadow.cameraAutoUpdate is introduced (default: true) to disable the cone fitting of the camera.WDYT?
--
Edit : item 2 moved to its own PR (#14663)