我正在尝试Three.js,我正在尝试将SpotLight定位在相机的位置。我使用以下代码(剥离窗口创建):
$(document).ready(function() {
init();
});
function init() {
var camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 1000 );
camera.position.set(50, 10, 0);
camera.lookAt(new THREE.Vector3(0, 0, 0));
var spotLight = new THREE.SpotLight( 0xffffff );
spotLight.position = camera.position;
console.log(camera.position);
console.log(spotLight.position);
}
我得到的输出是camera.position是50,10,0(如预期的那样)但是spotLight.position是0,1,0 - 甚至很难我只是将它设置为指向相同的值?
答案 0 :(得分:1)
尝试
spotLight.position.set(camera.position.x, camera.position.y, camera.position.z)
位置是只读的
答案 1 :(得分:0)
由于SpotLight和Camera是对象(Object3D),您只需将聚光灯添加到相机即可。用相机移动,旋转灯光等,无需进一步复印。在这种情况下,您必须相对于相机定位灯光:
camera.add(spotLight);
spotLight.position.set(0,0,1);
spotLight.target = camera;