Skip to content

Making directional light follow the camera (fix some code in Viewer) #450

@trusktr

Description

@trusktr

//this.directionalLight.position = this.camera.localToWorld(new THREE.Vector3(-1, 1, 0));

This is how:

this.directionalLight.position.copy(this.camera.localToWorld(new THREE.Vector3(-1, 1, 0)));

But there is a much easier way that makes more sense: make the directional light a child of the camera, and make sure the camera is added to the scene. So removing that from the draw() method, we would instead replace the this in the constructor,

		this.scene.add(this.directionalLight);

with this,

		this.scene.add(this.camera);
		this.camera.add(this.directionalLight);

. Now the light will move wherever the camera goes, without having to do any procedure to sync one matrix to the other.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions