题目主要是写补全一些代码来实现彩色的三角形。
代码很简单,只是因为是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); }