Reputation: 91
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.
Upvotes: 6
Views: 12335
Reputation: 1
Try this
Add a empty Object3D into SpotLight as a child
const targetObject = new THREE.Object3D()
scene.add(targetObject)
spotLight.add(targetObject)
targetObject.position.set(0,-1,0)
spotLight.target = targetObject
and then you just control spotLight's rotation
Upvotes: 0
Reputation: 19276
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;
Upvotes: 3
Reputation: 104823
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
Upvotes: 4