IndexedGeometry3.js 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. /**
  2. * @author mrdoob / http://mrdoob.com/
  3. */
  4. THREE.IndexedGeometry3 = function ( indices, size ) {
  5. THREE.BufferGeometry.call( this );
  6. var verticesBuffer = new ArrayBuffer( size * 3 * 4 );
  7. var normalsBuffer = new ArrayBuffer( size * 3 * 4 );
  8. var uvsBuffer = new ArrayBuffer( size * 2 * 4 );
  9. this.indices = new Uint16Array( indices );
  10. this.vertices = [];
  11. this.normals = [];
  12. this.uvs = [];
  13. for ( var i = 0; i < size; i ++ ) {
  14. this.vertices.push( new Float32Array( verticesBuffer, i * 3 * 4, 3 ) );
  15. this.normals.push( new Float32Array( normalsBuffer, i * 3 * 4, 3 ) );
  16. this.uvs.push( new Float32Array( uvsBuffer, i * 2 * 4, 2 ) );
  17. }
  18. this.attributes[ 'index' ] = { array: this.indices, itemSize: 1 };
  19. this.attributes[ 'position' ] = { array: new Float32Array( verticesBuffer, 0, size * 3 ), itemSize: 3 };
  20. this.attributes[ 'normal' ] = { array: new Float32Array( normalsBuffer, 0, size * 3 ), itemSize: 3 };
  21. this.attributes[ 'uv' ] = { array: new Float32Array( uvsBuffer, 0, size * 2 ), itemSize: 2 };
  22. };
  23. THREE.Geometry3.prototype = Object.create( THREE.BufferGeometry.prototype );