Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
trusktr opened this issue Oct 5, 2021 · 2 comments
Open

Comments

@trusktr
Copy link

trusktr commented Oct 5, 2021

//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.

@trusktr
Copy link
Author

trusktr commented Oct 5, 2021

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.

k-aguete pushed a commit to k-aguete/ros3djs that referenced this issue Oct 21, 2022
Bumps [karma](https://github.com/karma-runner/karma) from 6.3.3 to 6.3.4.
- [Release notes](https://github.com/karma-runner/karma/releases)
- [Changelog](https://github.com/karma-runner/karma/blob/master/CHANGELOG.md)
- [Commits](karma-runner/karma@v6.3.3...v6.3.4)

---
updated-dependencies:
- dependency-name: karma
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
@akashjinandra
Copy link

This worked well for me, we should use this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants