TypedGeometry.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. THREE.TypedVector2 = function ( array, offset ) {
  2. this.array = array;
  3. this.offset = offset * 2;
  4. };
  5. THREE.TypedVector2.prototype = {
  6. constructor: THREE.TypedVector3,
  7. get x () {
  8. return this.array[ this.offset ];
  9. },
  10. set x ( value ) {
  11. this.array[ this.offset ] = value;
  12. },
  13. get y () {
  14. return this.array[ this.offset + 1 ];
  15. },
  16. set y ( value ) {
  17. this.array[ this.offset + 1 ] = value;
  18. },
  19. set: function ( x, y ) {
  20. this.array[ this.offset ] = x;
  21. this.array[ this.offset + 1 ] = y;
  22. return this;
  23. }
  24. };
  25. THREE.TypedVector3 = function ( array, offset ) {
  26. this.array = array;
  27. this.offset = offset * 3;
  28. };
  29. THREE.TypedVector3.prototype = {
  30. constructor: THREE.TypedVector3,
  31. get x () {
  32. return this.array[ this.offset ];
  33. },
  34. set x ( value ) {
  35. this.array[ this.offset ] = value;
  36. },
  37. get y () {
  38. return this.array[ this.offset + 1 ];
  39. },
  40. set y ( value ) {
  41. this.array[ this.offset + 1 ] = value;
  42. },
  43. get z () {
  44. return this.array[ this.offset + 2 ];
  45. },
  46. set z ( value ) {
  47. this.array[ this.offset + 2 ] = value;
  48. },
  49. set: function ( x, y, z ) {
  50. this.array[ this.offset ] = x;
  51. this.array[ this.offset + 1 ] = y;
  52. this.array[ this.offset + 2 ] = z;
  53. return this;
  54. },
  55. toString: function () {
  56. return '[' + this.array[ this.offset ] + ',' + this.array[ this.offset + 1 ] + ',' + this.array[ this.offset + 2 ] + ']';
  57. }
  58. };
  59. THREE.TypedFace = function ( positions, normals, uvs, offset ) {
  60. this.positions = positions;
  61. this.normals = normals;
  62. this.uvs = uvs;
  63. this.offset = offset * 3;
  64. };
  65. THREE.TypedFace.prototype = {
  66. constructor: THREE.TypedFace,
  67. vertex: function ( index ) {
  68. return new THREE.TypedVector3( this.positions, this.offset + index );
  69. },
  70. normal: function ( index ) {
  71. return new THREE.TypedVector3( this.normals, this.offset + index );
  72. },
  73. uv: function ( index ) {
  74. return new THREE.TypedVector2( this.uvs, this.offset + index );
  75. }
  76. }
  77. THREE.TypedGeometry = function ( size ) {
  78. this.id = THREE.GeometryIdCount ++;
  79. this.uuid = THREE.Math.generateUUID();
  80. this.name = '';
  81. this.positions = new Float32Array( size * 3 * 3 );
  82. this.normals = new Float32Array( size * 3 * 3 );
  83. this.uvs = new Float32Array( size * 3 * 2 );
  84. this.boundingBox = null;
  85. this.boundingSphere = null;
  86. };
  87. THREE.TypedGeometry.prototype = {
  88. constructor: THREE.TypedGeometry,
  89. face: function ( index ) {
  90. return new THREE.TypedFace( this.positions, this.normals, this.uvs, index );
  91. },
  92. dispose: function () {
  93. this.dispatchEvent( { type: 'dispose' } );
  94. }
  95. };
  96. THREE.EventDispatcher.prototype.apply( THREE.TypedGeometry.prototype );