three.js不会渲染球体

时间:2015-09-26 18:25:59

标签: javascript three.js

我是一个THREE.js菜鸟。我复制了一些代码,但由于某种原因,我在中间的球体不会渲染。有人有想法吗?这是我的代码:



<canvas id='canvas' width='960' height='720'></canvas>
		<script src="https://ajax.googleapis.com/ajax/libs/threejs/r69/three.min.js"></script>
		<script>
		var T = THREE;
		var canvas = document.getElementById('canvas');
		var WIDTH = 960, HEIGHT = 720;
		var VIEW_ANGLE = 45, ASPECT = WIDTH / HEIGHT, NEAR = 0.1, FAR = 10000;
		var renderer = new T.WebGLRenderer({antialias:true});
		var camera = new T.PerspectiveCamera(VIEW_ANGLE, ASPECT, NEAR, FAR);
		var scene = new T.Scene();
		scene.add(camera);
		camera.position.z = 300;
		renderer.setSize(WIDTH, HEIGHT);

		var sphMat = new T.MeshLambertMaterial({color: 0x778B71});
		var sph = new T.Mesh(new T.SphereGeometry(5, 20, 20), sphMat);
		sph.position.x = 0;
		sph.position.y = 0;
		sph.position.z = 0;
		scene.add(sph);

		renderer.render(scene, camera);
		canvas.appendChild(renderer.domElement);
		</script>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:2)

请说明哪些方法不会呈现? 我不能无花果。你的代码中有一个光源,THREE.MeshLambert mat需要一盏灯。

测试使用MeshBasicMaterial:

http://threejs.org/docs/#Reference/Materials/MeshBasicMaterial或点亮场景: http://threejs.org/docs/#Reference/Lights/AmbientLight