Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Three.js: add light to camera

Tags:

three.js

I want to move and rotate the camera but keep a PointLight on the same position relative to the camera. I've read a bunch of threads saying that you can add the light object to the camera instead of the scene. Like so:

pointLight = new THREE.PointLight( 0xffffff );
pointLight.position.set(1,1,2);
camera.add(pointLight);

However this does not seem to work for me. Instead I now when the camera changes set the light's position by applying the cameras matrixWorld to my desired relative light position. This works, but adding the light to the camera seems like a cleaner solution.

I'm a doing something wrong or is adding light object to the camera deprecated?

Thanks!

like image 834
Sebastian Avatar asked Sep 09 '14 08:09

Sebastian


1 Answers

You need to add the camera to the scene if the camera has a child object, such as a `PointLight'.

scene.add( camera );

three.js r.68

like image 56
WestLangley Avatar answered Oct 21 '22 17:10

WestLangley