IndexedGeometry5.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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.IndexedGeometry5.prototype.constructor = THREE.IndexedGeometry5;
  25. THREE.TypedVector2 = function ( array, offset ) {
  26. this.array = array;
  27. this.offset = offset;
  28. };
  29. THREE.TypedVector2.prototype = Object.create( THREE.Vector2.prototype );
  30. THREE.TypedVector2.prototype.constructor = THREE.TypedVector2;
  31. Object.defineProperties( THREE.TypedVector2.prototype, {
  32. 'x': {
  33. get: function () { return this.array[ this.offset ]; },
  34. set: function ( v ) { this.array[ this.offset ] = v; }
  35. },
  36. 'y': {
  37. get: function () { return this.array[ this.offset + 1 ]; },
  38. set: function ( v ) { this.array[ this.offset + 1 ] = v; }
  39. }
  40. } );
  41. THREE.TypedVector3 = function ( array, offset ) {
  42. this.array = array;
  43. this.offset = offset;
  44. };
  45. THREE.TypedVector3.prototype = Object.create( THREE.Vector3.prototype );
  46. THREE.TypedVector3.prototype.constructor = THREE.TypedVector3;
  47. Object.defineProperties( THREE.TypedVector3.prototype, {
  48. 'x': {
  49. get: function () { return this.array[ this.offset ]; },
  50. set: function ( v ) { this.array[ this.offset ] = v; }
  51. },
  52. 'y': {
  53. get: function () { return this.array[ this.offset + 1 ]; },
  54. set: function ( v ) { this.array[ this.offset + 1 ] = v; }
  55. },
  56. 'z': {
  57. get: function () { return this.array[ this.offset + 2 ]; },
  58. set: function ( v ) { this.array[ this.offset + 2 ] = v; }
  59. }
  60. } );