Thomas Turner
Thomas Turner

Reputation: 3042

three.js directional light following camera

I having a problem with Three.js and lighting following a camera.

I am using orbit control for the mouse movement/

In release number 66 the following use to work

    light = new THREE.DirectionalLight( 0xffffff, 1 );
    light.position = camera.position;
    scene.add(light);

However in release number 67 and 68 the lighting doesn't follow the camera. The light is only show on one face.

Upvotes: 4

Views: 9327

Answers (2)

Thomas Turner
Thomas Turner

Reputation: 3042

I got it to work with the help of above

controls = new THREE.OrbitControls(camera);
controls.addEventListener( 'change', light_update );

function light_update()
{
    light.position.copy( camera.position );
}

Thanks

Upvotes: 15

Leeft
Leeft

Reputation: 3837

Some of the Object3D properties have become immutable in r68, so copying to .position directly won't work anymore. Instead you need to use the various methods on these properties:

light.position.copy( camera.position );

I've not used these lights myself, but from the documentation I gather that they aren't supposed to automatically follow anything. Also, the position is irrelevant since they act like they're an infinite distance away; only the rotation matters.

Upvotes: 13

Related Questions