Search code examples
javascriptthree.jslight

three.js update light OrbitControls


I'm using threejs to display an object and OrbitControls to control movment of the scene with my mouse. My scene also inclues a DirectionalLight.

When the scene first renders, the DirectionalLight lights my object in the way I expect. However, when I modify the scene by rotating using my mouse the DirectionalLight source does not update and 'shine' the light from the new angle as I expect.

Can someone explain how I can update my scene so the light updates based on my rotation with OrbitControls?


Solution

  • If you want the relationship between the light direction and the camera view to remain constant, I suggest that you add the light to the CAMERA, not the SCENE.

    So instead of, say scene.add(dirLight) you use camera.add(dirLight)