three.js从相机直接发光到物体

时间:2017-07-11 16:27:45

标签: three.js camera directional-light

在我的三个js设置中,我对定向灯有以下设置:

private aLight: THREE.DirectionalLight;

this.aLight = new THREE.DirectionalLight(0xffffff, 1.0);
this.aLight.position.set(-5, 5, 5);

this.aScene.add(this.aLight);

为了使灯跟随我的相机并始终照亮我的网格,我在渲染功能中设置以下内容: 私人onRender(){

this.aLight.position.copy(this.aCamera.getWorldPosition());

window.requestAnimationFrame(_ => this.onRender());
this.aRenderer.render(this.aScene, this.aCamera);

现在,对象总是被照亮:

enter image description here enter image description here

但如果我放大对着相机的表面是黑暗的:

enter image description here

我想让我的灯始终从我的相机指向物体。我做错了什么?

1 个答案:

答案 0 :(得分:3)

如果您希望光源与相机重合,最简单的解决方案是使用点光源并将其添加为相机的子光源。你可以使用这样的模式:

camera.position.set( 10, 10, 10 );
scene.add( camera ); // required in this case since the camera will have a child

// ambient
scene.add( new THREE.AmbientLight( 0xffffff, 0.1 ) ); // optional

// light
var light = new THREE.PointLight( 0xffffff, 1 );
camera.add( light );

如果您使用定向灯,请记住定向灯具有target属性,Object3D。因此,如果放大,则可能需要更改target.position。如上所述,使用点光源更容易。

three.js r.86