3D SpotLight rotation

I'm trying to turn the 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 does not change its rotation regardless of the value that I set.

+4
source share
3 answers

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

 light.target = myObject; 

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

Three.js r. 49

+3
source

Thus, you must position the light target either for its intended purpose:

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

Or by defining the properties of the target light object:

 myLight.target.position.x = 10; myLight.target.position.y = 20; myLight.target.position.z = 30; 
0
source

For the latest version 74!

 function SPOT_CLASS(pointIntensity) { ROOT.sunLight= new THREE.SpotLight(0x0000ff,pointIntensity,2000,Math.PI,1); ROOT.sunLight.position.set( 100, 200 , 0 ); // HERE ROOT.PILOT = new THREE.Object3D( 0, 0, 0 ); ROOT.sunLight.target = ROOT.PILOT; ROOT.sunLight.castShadow = true; ROOT.sunLight.shadow.bias = 1; ROOT.sunLight.shadow.camera.far =5000; ROOT.sunLight.shadow.camera.near = 800; ROOT.sunLight.shadow.camera.fov = 70; // SHADOW CAMERA HELPER var shadowCameraHelper = new THREE.CameraHelper( ROOT.sunLight.shadow.camera ); shadowCameraHelper.visible = true; ROOT.sunLight.add( shadowCameraHelper ); // try other combination scene.add( ROOT.sunLight ); scene.add( ROOT.PILOT ); } 

Make such instances:

var LIGHTS = new SPOT_CLASS (15);

then try in the console: LIGHTS.PILOT.position.x = 200;

Make this object -> LIGHTS.PILOT.position for rotation in the update or rendering cycle ...

ROOT.sunLight.target = LIGHTS.PILOT; or maybe better ROOT.sunLight.lookAt (LIGHTS.PILOT);

0
source

All Articles