【Interactive 3D Graphics】Exercise: Vertex Attributes

题目主要是写补全一些代码来实现彩色的三角形。

完成的效果如下:
【Interactive 3D Graphics】Exercise: Vertex Attributes_第1张图片

代码很简单,只是因为是JavaScript的缘故,真的很容易打错变量。

	geometry.vertices.push(new THREE.Vector3(100,0,0));
	geometry.vertices.push(new THREE.Vector3(0,100,0));
	geometry.vertices.push(new THREE.Vector3(0,0,100));
	geometry.faces.push(new THREE.Face3(0,1,2));
	var color1=THREE.Color(0xff0000);
	var color2=THREE.Color(0x00ff00);
	var color3=THREE.Color(0x0000ff);

	geometry.faces[0].vertexColors=[color1,color2,color3];

不过最后的一段代码挺好的,别人写的以后可以时常这么用

try {
	init();
	fillScene();
	addToDOM();
	animate();
} catch(e) {
	var errorReport = "Your program encountered an unrecoverable error, can not draw on canvas. Error was:<br/><br/>";
	$('#container').append(errorReport+e);
}

这样有时候JavaScript有错误无法运行的时候,会显示错误信息。

你可能感兴趣的:(【Interactive 3D Graphics】Exercise: Vertex Attributes)