InterleavedBufferAttribute.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import { _Math } from '../math/Math';
  2. /**
  3. * @author benaadams / https://twitter.com/ben_a_adams
  4. */
  5. function InterleavedBufferAttribute( interleavedBuffer, itemSize, offset, normalized ) {
  6. this.uuid = _Math.generateUUID();
  7. this.data = interleavedBuffer;
  8. this.itemSize = itemSize;
  9. this.offset = offset;
  10. this.normalized = normalized === true;
  11. }
  12. InterleavedBufferAttribute.prototype = {
  13. constructor: InterleavedBufferAttribute,
  14. isInterleavedBufferAttribute: true,
  15. get length() {
  16. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Please use .count.' );
  17. return this.array.length;
  18. },
  19. get count() {
  20. return this.data.count;
  21. },
  22. get array() {
  23. return this.data.array;
  24. },
  25. setX: function ( index, x ) {
  26. this.data.array[ index * this.data.stride + this.offset ] = x;
  27. return this;
  28. },
  29. setY: function ( index, y ) {
  30. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  31. return this;
  32. },
  33. setZ: function ( index, z ) {
  34. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  35. return this;
  36. },
  37. setW: function ( index, w ) {
  38. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  39. return this;
  40. },
  41. getX: function ( index ) {
  42. return this.data.array[ index * this.data.stride + this.offset ];
  43. },
  44. getY: function ( index ) {
  45. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  46. },
  47. getZ: function ( index ) {
  48. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  49. },
  50. getW: function ( index ) {
  51. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  52. },
  53. setXY: function ( index, x, y ) {
  54. index = index * this.data.stride + this.offset;
  55. this.data.array[ index + 0 ] = x;
  56. this.data.array[ index + 1 ] = y;
  57. return this;
  58. },
  59. setXYZ: function ( index, x, y, z ) {
  60. index = index * this.data.stride + this.offset;
  61. this.data.array[ index + 0 ] = x;
  62. this.data.array[ index + 1 ] = y;
  63. this.data.array[ index + 2 ] = z;
  64. return this;
  65. },
  66. setXYZW: function ( index, x, y, z, w ) {
  67. index = index * this.data.stride + this.offset;
  68. this.data.array[ index + 0 ] = x;
  69. this.data.array[ index + 1 ] = y;
  70. this.data.array[ index + 2 ] = z;
  71. this.data.array[ index + 3 ] = w;
  72. return this;
  73. }
  74. };
  75. export { InterleavedBufferAttribute };
粤ICP备19079148号