question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Directional light target position cannot be updated

See original GitHub issue

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:

var light = new THREE.DirectionalLight( 0xfff000, 2 );
scene.add(light);

light.position.set(0, 1, 0);  // default; light from top shining down

//light.target.position is currently (0,0,0)

Then do this:

light.target.position.set( 0, 2, 0 );

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:

scene.add(light, light.target);

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?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:16 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
WestLangleycommented, Nov 25, 2016

@looeee lookAt() does not work correctly if the object has a rotated/translated parent, so it is restricted. See the inline comment. (The basic problem is getting it to work while still keeping the object “right-side-up” after lookAt() is called. A rotated parent can tilt the object.)

@aardgoose Yes, that seems to be a reasonable approach to consider, but updateMatrixWorld() would need to be fixed.

@mrdoob has been advocating removing target completely for some time. I am keeping an open-mind on that approach. Forcing the renderer to auto-update the target is also reasonable.

Until then, some comments in the docs advising the user to add the target to the scene graph is appropriate.

1reaction
WestLangleycommented, Nov 25, 2016
Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - can not update THREE.DirectionalLight's direction
I found that I have to use the light.target to specify the direction. see the documentation. The DirectionalLight points from its position ......
Read more >
DirectionalLight – three.js docs
The reason for this is to allow the light to cast shadows - the shadow camera needs a position to calculate shadows from....
Read more >
Target Directional Light | 3ds Max 2020
Directional lights are primarily used to simulate sunlight. You can adjust the color of the light and position and rotate the light in...
Read more >
Directional Light PropertyManager - 2016 - SOLIDWORKS Help
In the DisplayManager, click View Scene, Lights, and Cameras . Under Lights , right-click Directional and select Edit Directional Light. When PhotoView 360...
Read more >
Lights | Rhino 3-D modeling
The Lights command opens the Lights panel. ... Provides a strong, directional lighting effect depending on the settings in the Sun panel ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found