我已经对Three.js库进行了一些测试,看了一下docs,并想出了一个创建一个盒子的简单脚本。一切都很好,直到这里。然后我试着添加一盏灯,它只是没有照亮我的盒子。 脚本:
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(90, window.innerWidth / window.innerHeight, 0.1, 1000);
var geometry = new THREE.BoxGeometry( 1, 1, 1 );
var material = new THREE.MeshBasicMaterial({ color: 0x000066 });
var cube = new THREE.Mesh(geometry, material);
scene.add(new THREE.AmbientLight(0x404040, 0.9));
var pointLight = new THREE.PointLight(0xFFFFFF, 1, 100);
pointLight.position.x = 0;
pointLight.position.y = 10;
pointLight.position.z = 0;
scene.add(pointLight);
scene.add(cube);
camera.position.z = 4;
camera.position.y = 1;
var renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
animate();
function animate() {
requestAnimationFrame(animate);
render();
}
function render(){
renderer.render(scene, camera);
}
帮助!