BufferAttribute.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. /**
  2. * @author mrdoob / http://mrdoob.com/
  3. */
  4. THREE.BufferAttribute = function ( array, itemSize ) {
  5. this.array = array;
  6. this.itemSize = itemSize;
  7. this.needsUpdate = false;
  8. };
  9. THREE.BufferAttribute.prototype = {
  10. constructor: THREE.BufferAttribute,
  11. get length () {
  12. console.warn( 'THREE.BufferAttribute: .length has been renamed to .count.' );
  13. return this.count;
  14. },
  15. get count() {
  16. return this.array.length / this.itemSize;
  17. },
  18. copyAt: function ( index1, attribute, index2 ) {
  19. index1 *= this.itemSize;
  20. index2 *= attribute.itemSize;
  21. for ( var i = 0, l = this.itemSize; i < l; i ++ ) {
  22. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  23. }
  24. return this;
  25. },
  26. copyArray: function ( array ) {
  27. this.array.set( array );
  28. return this;
  29. },
  30. copyColorsArray: function ( colors ) {
  31. var array = this.array, offset = 0;
  32. for ( var i = 0, l = colors.length; i < l; i ++ ) {
  33. var color = colors[ i ];
  34. if ( color === undefined ) {
  35. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  36. color = new THREE.Color();
  37. }
  38. array[ offset ++ ] = color.r;
  39. array[ offset ++ ] = color.g;
  40. array[ offset ++ ] = color.b;
  41. }
  42. return this;
  43. },
  44. copyIndicesArray: function ( indices ) {
  45. var array = this.array, offset = 0;
  46. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  47. var index = indices[ i ];
  48. array[ offset ++ ] = index.a;
  49. array[ offset ++ ] = index.b;
  50. array[ offset ++ ] = index.c;
  51. }
  52. return this;
  53. },
  54. copyVector2sArray: function ( vectors ) {
  55. var array = this.array, offset = 0;
  56. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  57. var vector = vectors[ i ];
  58. if ( vector === undefined ) {
  59. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  60. vector = new THREE.Vector2();
  61. }
  62. array[ offset ++ ] = vector.x;
  63. array[ offset ++ ] = vector.y;
  64. }
  65. return this;
  66. },
  67. copyVector3sArray: function ( vectors ) {
  68. var array = this.array, offset = 0;
  69. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  70. var vector = vectors[ i ];
  71. if ( vector === undefined ) {
  72. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  73. vector = new THREE.Vector3();
  74. }
  75. array[ offset ++ ] = vector.x;
  76. array[ offset ++ ] = vector.y;
  77. array[ offset ++ ] = vector.z;
  78. }
  79. return this;
  80. },
  81. copyVector4sArray: function ( vectors ) {
  82. var array = this.array, offset = 0;
  83. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  84. var vector = vectors[ i ];
  85. if ( vector === undefined ) {
  86. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  87. vector = new THREE.Vector4();
  88. }
  89. array[ offset ++ ] = vector.x;
  90. array[ offset ++ ] = vector.y;
  91. array[ offset ++ ] = vector.z;
  92. array[ offset ++ ] = vector.w;
  93. }
  94. return this;
  95. },
  96. set: function ( value, offset ) {
  97. if ( offset === undefined ) offset = 0;
  98. this.array.set( value, offset );
  99. return this;
  100. },
  101. getX: function ( index ) {
  102. return this.array[ index * this.itemSize ];
  103. },
  104. setX: function ( index, x ) {
  105. this.array[ index * this.itemSize ] = x;
  106. return this;
  107. },
  108. getY: function ( index ) {
  109. return this.array[ index * this.itemSize + 1 ];
  110. },
  111. setY: function ( index, y ) {
  112. this.array[ index * this.itemSize + 1 ] = y;
  113. return this;
  114. },
  115. getZ: function ( index ) {
  116. return this.array[ index * this.itemSize + 2 ];
  117. },
  118. setZ: function ( index, z ) {
  119. this.array[ index * this.itemSize + 2 ] = z;
  120. return this;
  121. },
  122. getW: function ( index ) {
  123. return this.array[ index * this.itemSize + 3 ];
  124. },
  125. setW: function ( index, w ) {
  126. this.array[ index * this.itemSize + 3 ] = w;
  127. return this;
  128. },
  129. setXY: function ( index, x, y ) {
  130. index *= this.itemSize;
  131. this.array[ index + 0 ] = x;
  132. this.array[ index + 1 ] = y;
  133. return this;
  134. },
  135. setXYZ: function ( index, x, y, z ) {
  136. index *= this.itemSize;
  137. this.array[ index + 0 ] = x;
  138. this.array[ index + 1 ] = y;
  139. this.array[ index + 2 ] = z;
  140. return this;
  141. },
  142. setXYZW: function ( index, x, y, z, w ) {
  143. index *= this.itemSize;
  144. this.array[ index + 0 ] = x;
  145. this.array[ index + 1 ] = y;
  146. this.array[ index + 2 ] = z;
  147. this.array[ index + 3 ] = w;
  148. return this;
  149. },
  150. clone: function () {
  151. return new THREE.BufferAttribute( new this.array.constructor( this.array ), this.itemSize );
  152. }
  153. };
  154. //
  155. THREE.Int8Attribute = function ( array, itemSize ) {
  156. return new THREE.BufferAttribute( new Int8Array( array ), itemSize );
  157. };
  158. THREE.Uint8Attribute = function ( array, itemSize ) {
  159. return new THREE.BufferAttribute( new Uint8Array( array ), itemSize );
  160. };
  161. THREE.Uint8ClampedAttribute = function ( array, itemSize ) {
  162. return new THREE.BufferAttribute( new Uint8ClampedArray( array ), itemSize );
  163. };
  164. THREE.Int16Attribute = function ( array, itemSize ) {
  165. return new THREE.BufferAttribute( new Int16Array( array ), itemSize );
  166. };
  167. THREE.Uint16Attribute = function ( array, itemSize ) {
  168. return new THREE.BufferAttribute( new Uint16Array( array ), itemSize );
  169. };
  170. THREE.Int32Attribute = function ( array, itemSize ) {
  171. return new THREE.BufferAttribute( new Int32Array( array ), itemSize );
  172. };
  173. THREE.Uint32Attribute = function ( array, itemSize ) {
  174. return new THREE.BufferAttribute( new Uint32Array( array ), itemSize );
  175. };
  176. THREE.Float32Attribute = function ( array, itemSize ) {
  177. return new THREE.BufferAttribute( new Float32Array( array ), itemSize );
  178. };
  179. THREE.Float64Attribute = function ( array, itemSize ) {
  180. return new THREE.BufferAttribute( new Float64Array( array ), itemSize );
  181. };
粤ICP备19079148号