Question: THREE.JS Javasciprt assignment -> Write a program that renders a cube in which colors are assigned on a per-vertex basis. function createCube() { var geom

THREE.JS Javasciprt assignment -> Write a program that renders a cube in which colors are assigned on a per-vertex basis.

function createCube() { var geom = new THREE.CubeGeometry(2, 2, 2); var mat = new THREE.MeshFaceMaterial(); var colors = ["red", "green", "blue", "yellow", "cyan", "magenta"].map( function(colorname) {return new THREE.MeshBasicMaterial({color: colorname});}); for (var i = 0; i < 6; i++) mat.materials.push(colors[i]); for (var i = 0; i < 6; i++) for (var j = 0; j < 2; j++) geom.faces[2*i+j].materialIndex = i; var mesh = new THREE.Mesh(geom, mat); return mesh; } 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!