IndexedGeometry5.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /**
  2. * @author mrdoob / http://mrdoob.com/
  3. */
  4. THREE.IndexedGeometry5 = function ( indices, size ) {
  5. THREE.BufferGeometry.call( this );
  6. var verticesBuffer = new Float32Array( size * 3 );
  7. var normalsBuffer = new Float32Array( size * 3 );
  8. var uvsBuffer = new Float32Array( size * 2 );
  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 THREE.TypedVector3( verticesBuffer, i * 3 ) );
  15. this.normals.push( new THREE.TypedVector3( normalsBuffer, i * 3 ) );
  16. this.uvs.push( new THREE.TypedVector2( uvsBuffer, i * 2 ) );
  17. }
  18. this.attributes[ 'index' ] = { array: this.indices, itemSize: 1 };
  19. this.attributes[ 'position' ] = { array: verticesBuffer, itemSize: 3 };
  20. this.attributes[ 'normal' ] = { array: normalsBuffer, itemSize: 3 };
  21. this.attributes[ 'uv' ] = { array: uvsBuffer, itemSize: 2 };
  22. };
  23. THREE.IndexedGeometry5.prototype = Object.create( THREE.BufferGeometry.prototype );
  24. THREE.TypedVector2 = function ( array, offset ) {
  25. this.array = array;
  26. this.offset = offset;
  27. };
  28. THREE.TypedVector2.prototype = Object.create( THREE.Vector2.prototype );
  29. Object.defineProperties( THREE.TypedVector2.prototype, {
  30. 'x': {
  31. get: function () { return this.array[ this.offset ]; },
  32. set: function ( v ) { this.array[ this.offset ] = v; }
  33. },
  34. 'y': {
  35. get: function () { return this.array[ this.offset + 1 ]; },
  36. set: function ( v ) { this.array[ this.offset + 1 ] = v; }
  37. }
  38. } );
  39. THREE.TypedVector3 = function ( array, offset ) {
  40. this.array = array;
  41. this.offset = offset;
  42. };
  43. THREE.TypedVector3.prototype = Object.create( THREE.Vector3.prototype );
  44. Object.defineProperties( THREE.TypedVector3.prototype, {
  45. 'x': {
  46. get: function () { return this.array[ this.offset ]; },
  47. set: function ( v ) { this.array[ this.offset ] = v; }
  48. },
  49. 'y': {
  50. get: function () { return this.array[ this.offset + 1 ]; },
  51. set: function ( v ) { this.array[ this.offset + 1 ] = v; }
  52. },
  53. 'z': {
  54. get: function () { return this.array[ this.offset + 2 ]; },
  55. set: function ( v ) { this.array[ this.offset + 2 ] = v; }
  56. }
  57. } );