我要学习了three.js
。我已经library
从 github 下载了:three.js
我尝试在上面的链接中运行 three.js 的第一个示例。奇怪的问题是,它在 jsFiddle 中运行,但在我的计算机中却无法运行。
我在控制台中有这个错误:
TypeError: document.body is null
[Break On This Error]
document.body.appendChild( renderer.domElement );
jsFiddle Live Working Demo
这是我从上面的链接完全复制的代码:
是的,页面中包含的three.js。
var camera, scene, renderer;
var geometry, material, mesh;
init();
animate();
function init() {
camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 10000 );
camera.position.z = 1000;
scene = new THREE.Scene();
geometry = new THREE.CubeGeometry( 200, 200, 200 );
material = new THREE.MeshBasicMaterial( { color: 0xff0000, wireframe: true } );
mesh = new THREE.Mesh( geometry, material );
scene.add( mesh );
renderer = new THREE.CanvasRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
}
function animate() {
// note: three.js includes requestAnimationFrame shim
requestAnimationFrame( animate );
mesh.rotation.x += 0.01;
mesh.rotation.y += 0.02;
renderer.render( scene, camera );
}