我正在尝试用 3 种不同的颜色在 three.js 中为立方体着色,但似乎我在可以添加到场景中的 THREE.DirectionalLight 对象的数量上达到了一些上限。在文档中,我没有看到任何提到这样的限制,所以我想知道这是否真的如此,或者我是否遗漏了其他东西?
var renderer = new THREE.WebGLRenderer();
renderer.setSize( 800, 600 );
document.body.appendChild( renderer.domElement );
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(
35, // Field of view
800 / 600, // Aspect ratio
0.1, // Near plane
10000 // Far plane
);
camera.position.set( -15, 10, 10 );
camera.lookAt( scene.position );
scene.add( camera );
var cube = new THREE.Mesh(
new THREE.CubeGeometry( 5, 5, 5 ),
new THREE.MeshLambertMaterial( { color: 0xFFFFFF } )
);
scene.add( cube );
// top
light = new THREE.DirectionalLight( 0x0DEDDF );
light.position.set( 0, 1, 0 );
scene.add( light );
// bottom
light = new THREE.DirectionalLight( 0x0DEDDF );
light.position.set( 0, -1, 0 );
scene.add( light );
// back
light = new THREE.DirectionalLight( 0xB685F3 );
light.position.set( 1, 0, 0 );
scene.add( light );
// front
light = new THREE.DirectionalLight( 0xB685F3 );
light.position.set( -1, 0, 0 );
scene.add( light );
// right
light = new THREE.DirectionalLight( 0x89A7F5 );
light.position.set( 0, 0, 1 );
scene.add( light );
// left
light = new THREE.DirectionalLight( 0x89A7F5 );
light.position.set( 0, 0, -1 );
scene.add( light );
renderer.render( scene, camera );
</p>
在这里,您将看到被着色的侧面:顶部、底部、前部、后部、左侧和右侧。前四个会平局,后两个不会。重新排序并查看。有什么想法吗?