three.js为相机添加了聚光灯

时间:2014-12-16 21:50:47

标签: javascript three.js

这里是我的代码我试图在相机上添加2个灯,以便它们随着轨道控制的使用而移动。由于我不知道的原因,灯/球不可见。有人能指出我在这里做错了什么吗?

var sphere1 = new THREE.Mesh( new THREE.SphereGeometry( 2000, 16, 16), new THREE.MeshBasicMaterial({color:0xff0000}) );
var cameraLight1 = new THREE.PointLight( this.options.lights.lightColor, this.options.lights.lightIntensity * 1.2, this.options.lights.lightRadious );

    sphere1.add( cameraLight1 );
    sphere1.position.set( -5000, -5000, -5000 );

this.camera.add( sphere1 );

var sphere2 = new THREE.Mesh( new THREE.SphereGeometry( 2000, 16, 16), new THREE.MeshBasicMaterial({color:0xff0000}) );
var cameraLight2 = new THREE.PointLight( this.options.lights.lightColor, this.options.lights.lightIntensity * 1.2, this.options.lights.lightRadious );

    sphere2.add( cameraLight2 );    
    sphere2.position.set( -5000, -5000, -5000 );

this.camera.add( sphere2 );

如果我在场景中添加球体/灯光,它们看起来很好。 不知道为什么这不起作用

PS:

相机初始位置:{x: 0, y: 5.510910596163089e-12, z: 90000}

更新

这也不起作用:

var cameraLight1 = new THREE.PointLight( this.options.lights.lightColor, this.options.lights.lightIntensity * 1.2, this.options.lights.lightRadious );

this.camera.add( cameraLight1 );
    cameraLight1.position.set( 0,0,-5000 );

var cameraLight2 = new THREE.PointLight( this.options.lights.lightColor, this.options.lights.lightIntensity * 1.2, this.options.lights.lightRadious );

this.camera.add( cameraLight2 );
    cameraLight2.position.set( 0,0,-5000 );

1 个答案:

答案 0 :(得分:0)

如果将子对象添加到摄像机,则还必须将摄像机添加到场景中。否则,子对象将不会成为场景图的一部分。

scene.add( camera ); // this is required...
camera.add( light ); // ... whenever you do this

three.js r.69