添加灯光
====
本文的案例在上文的基础上完成,首先通过SpotLight构造一个灯光,添加到场景中,如下:
var spotLight = new THREE.SpotLight(0xffffff);
spotLight.position.set(-40, 60, -10);
spotLight.castShadow = true;
scene.add(spotLight);
构造光源时,参数表示光源的颜色,然后设置光源的位置为(-40,60,-10),这个坐标在三维坐标系的第6卦限中,同时设置castShadow为true,表示这个光源会产生阴影,不过单纯的添加光源,并不能使物体的颜色作出改变,还需要修改组件的材料,代码如下:
var planeGeometry = new THREE.PlaneGeometry(60, 20, 1, 1);
var planeMaterial = new THREE.MeshLambertMaterial({color: 0xcccccc});
var plane = new THREE.Mesh(planeGeometry, planeMaterial);
plane.rotation.x = -0.5 * Math.PI;
plane.position.set(15, 0, 0);
<