Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

three.js SpotLight orientation (direction) issue

Well, here is the problem,

Actually what I try to achieve is to place, at some places, some spotlights in a basic three.js example.

Here is the way I try to set the spotlight target position :

var light = new THREE.SpotLight(0xFFFFFF);
light.position.set(0,130,0);
light.target.position.set(200,-130,400);
scene.add(light);

The spotlight (light) keeps lighting the point (0,0,0) even if, when I console.log the target.position.(x,y,z) it gives me the right values...

Here is a quick fiddle I did with my full example.

http://jsfiddle.net/1xfno37y/7/

like image 602
Julo0sS Avatar asked Aug 25 '15 12:08

Julo0sS


1 Answers

You have to update your light.target after changing (eg. setting position):

light.target.updateMatrixWorld();

Or just add your light.target to the scene:

scene.add( light.target );

Three.js r.71

http://jsfiddle.net/1xfno37y/19/

Further reading: Critical bug with spotLight.target.position #5555

like image 126
Falk Thiele Avatar answered Oct 23 '22 17:10

Falk Thiele