ros3djs
ros3djs copied to clipboard
Making directional light follow the camera (fix some code in Viewer)
https://github.com/RobotWebTools/ros3djs/blob/530f7ec63778c83eaba4382395ee68b2dbc15808/src/visualization/Viewer.js#L131
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.
I assume the reason for this is so that the directional light's shadow projection frustum moves with the camera, so objects that are in range of the camera always have the directional light. That's the only one I could think of.
This worked well for me, we should use this.