Model Loader Demo
Er, JavaScript doesn't seem to be running, so basically all you're going to see is the bare code...
var loader=new THREE.STLLoader(); loader.load('models/headXYZ.stl', /* everything below is one big callback function */ function(g) { // Geometry comes in too big--scale back vertices for (var i=0;i
/** Matrix preliminaries **/ // Assign this column of the matrix from this vector. THREE.Matrix4.prototype.setCol=function(col,v) { this.elements[col*4+0]=v.x; this.elements[col*4+1]=v.y; this.elements[col*4+2]=v.z; } // Extract this column of the matrix, and return it. THREE.Matrix4.prototype.getCol=function(col) { return new vec3(this.elements[col*4+0], this.elements[col*4+1], this.elements[col*4+2]); } // Normalize the vec3 making up this column. THREE.Matrix4.prototype.normCol=function(col) { var v=this.getCol(col); v.normalize(); this.setCol(col,v); } // Normalize the XYZ axes, so they have unit length. THREE.Matrix4.prototype.normalize=function() { this.normCol(0); this.normCol(1); this.normCol(2); } // Make the XYZ axes orthogonal, so they are 90 deg apart. THREE.Matrix4.prototype.ortho=function() { this.setCol(2,this.getCol(0).cross(this.getCol(1))); this.setCol(0,this.getCol(1).cross(this.getCol(2))); //this.setCol(1,this.getCol(2).cross(this.getCol(0))); } // Do time integration: add v*dt to each element. THREE.Matrix4.prototype.integrate=function(v,dt) { var te=this.elements; var ve=v.elements; // loop ends early, so we don't mess up W. for (var i=0;i<15;i++) te[i]+=ve[i]*dt; }; // User Interface and camera control var rot=new vec3(); // user-applied torques // X control via J and L if (lib.key['j']) rot.pe(new vec3(-1,0,0)); if (lib.key['l']) rot.pe(new vec3(+1,0,0)); // Y control via I and K if (lib.key['i']) rot.pe(new vec3(0,+1,0)); if (lib.key['k']) rot.pe(new vec3(0,-1,0)); // Z control via U and M if (lib.key['u']) rot.pe(new vec3(0,0,+1)); if (lib.key['m']) rot.pe(new vec3(0,0,-1)); // Per-object rotation physics for (var i=0;i
0.0) { // we hit the boundary s.P.pe(N.t(-d)); // move inside var dV=s.V.dot(N); if (dV>0.0) { // flip velocity s.V.pe(N.t(-1.8*dV )); s.V.te(0.99); // drag } // Compute contact point's relative velocity: // sum of linear and angular velocities var RV=s.V.p(N.clone().cross(s.W)); // Collision torque -> angular momentum s.W.pe(RV.cross(N).te(-100*lib.dt)); } } // Linear bounce physics for (var i=0;i
// Camera control could go here. if (lib.key['d']) camera.position.x+=10.0*lib.dt;