SpotLight在three.js中旋转

时间:2012-06-21 17:29:58

标签: javascript 3d three.js

我正在尝试旋转聚光灯。我的代码是:

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 );

我想知道我做错了什么。聚光灯不会改变其旋转,与我放置的值无关。

2 个答案:

答案 0 :(得分:4)

light.target确定聚光灯的阴影相机方向。例如,如果场景中有一个名为myObject的对象,则可以执行以下操作:

light.target = myObject;

请注意,light.targetObject3D,而不是位置向量。

Three.js r.49

答案 1 :(得分:1)

因此,您可以通过直接分配来定位光目标:

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

或者通过定义光目标对象属性:

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