Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Draw a box with triangles in three.js
// the box geometry to initialise
var box=new THREE.Geometry();
// the trick to make all faces: vectors i, j and k have the coordinates of the triangles in the box
var i="011010111111100101000000001011110100".split('').map(c=>(c=='0')?0:1),
j="000000011010111111100101011010011010".split('').map(c=>(c=='0')?0:1),
k="001011001011001011001011000000111111".split('').map(c=>(c=='0')?0:1);
// this function multiplies each of the coordinates by a transformation matrix that turns them
// into an arbitrary box
i.map(function(v,n){
var vec=MRI.multMatVec(mat,[i[n],j[n],k[n]]);
box.vertices.push(newVector(vec))
});
// faces are added to the box
for(l=0;l<12;l++)
box.faces.push(new THREE.Face3(l*3,l*3+1,l*3+2));
var material=new THREE.MeshBasicMaterial({wireframe:true});
// the final object is added to the scene
mesh=new THREE.Mesh(box,material);
scene.add(mesh);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.