/** * @author mr.doob / http://mrdoob.com/ * @author kile / http://kile.stravaganza.org/ */ THREE.Geometry = function () { this.vertices = []; this.faces = []; this.uvs = []; }; THREE.Geometry.prototype = { computeCentroids: function () { var f, fl, face; for ( f = 0, fl = this.faces.length; f < fl; f++ ) { face = this.faces[ f ]; face.centroid.set( 0, 0, 0 ); if ( face instanceof THREE.Face3 ) { face.centroid.addSelf( this.vertices[ face.a ].position ); face.centroid.addSelf( this.vertices[ face.b ].position ); face.centroid.addSelf( this.vertices[ face.c ].position ); face.centroid.divideScalar( 3 ); } else if ( face instanceof THREE.Face4 ) { face.centroid.addSelf( this.vertices[ face.a ].position ); face.centroid.addSelf( this.vertices[ face.b ].position ); face.centroid.addSelf( this.vertices[ face.c ].position ); face.centroid.addSelf( this.vertices[ face.d ].position ); face.centroid.divideScalar( 4 ); } } }, computeNormals: function () { var v, vl, vertex, f, fl, face, vA, vB, vC, cb = new THREE.Vector3(), ab = new THREE.Vector3(); for ( v = 0, vl = this.vertices.length; v < vl; v++ ) { vertex = this.vertices[ v ]; vertex.normal.set( 0, 0, 0 ); } for ( f = 0, fl = this.faces.length; f < fl; f++ ) { face = this.faces[ f ]; vA = this.vertices[ face.a ]; vB = this.vertices[ face.b ]; vC = this.vertices[ face.c ]; cb.sub( vC.position, vB.position ); ab.sub( vA.position, vB.position ); cb.crossSelf( ab ); if ( !cb.isZero() ) { cb.normalize(); } face.normal.copy( cb ); } }, toString: function () { return 'THREE.Geometry ( vertices: ' + this.vertices + ', faces: ' + this.faces + ' )'; } };