Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SpotLight Rotation in three.js

I'm trying to rotate a spotlight. My code is:

var light   = new THREE.SpotLight( color, intensity, distance );
light.position.set( 0, 100, 0 );
light.rotation.set( 0, Math.PI, 0 );
light.shadowCameraFar = 50;
light.shadowCameraNear      = 0.01;     
light.castShadow        = true;
light.shadowDarkness        = 0.5;
light.shadowCameraVisible   = true;
light.shadowCameraFar = 800;
light.shadowCameraFov = 15;
scene.add( light );

I want to know what I'm doing wrong. The spotlight doesn't change its rotation independent the value I put.

like image 648
Nathalia Sautchuk Patricio Avatar asked Jun 21 '12 17:06

Nathalia Sautchuk Patricio


2 Answers

light.target determines the spotlight's shadow camera orientation. If, for example, you have an object in your scene called myObject, you could do something like this:

light.target = myObject;

Remember, light.target is an Object3D, not a position vector.

Three.js r.49

like image 120
WestLangley Avatar answered Oct 25 '22 15:10

WestLangley


So you would position the light target either by direct assignment:

myLight.target.position = new THREE.Object3D( 10, 20, 30 );

Or by defining the light target object properties:

myLight.target.position.x = 10;
myLight.target.position.y = 20;
myLight.target.position.z = 30;
like image 28
Oliver Schafeld Avatar answered Oct 25 '22 14:10

Oliver Schafeld