InterleavedBufferAttribute.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. Object.defineProperties( InterleavedBufferAttribute.prototype, {
  13. count: {
  14. get: function () {
  15. return this.data.count;
  16. }
  17. },
  18. array: {
  19. get: function () {
  20. return this.data.array;
  21. }
  22. }
  23. } );
  24. Object.assign( InterleavedBufferAttribute.prototype, {
  25. isInterleavedBufferAttribute: true,
  26. setX: function ( index, x ) {
  27. this.data.array[ index * this.data.stride + this.offset ] = x;
  28. return this;
  29. },
  30. setY: function ( index, y ) {
  31. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  32. return this;
  33. },
  34. setZ: function ( index, z ) {
  35. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  36. return this;
  37. },
  38. setW: function ( index, w ) {
  39. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  40. return this;
  41. },
  42. getX: function ( index ) {
  43. return this.data.array[ index * this.data.stride + this.offset ];
  44. },
  45. getY: function ( index ) {
  46. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  47. },
  48. getZ: function ( index ) {
  49. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  50. },
  51. getW: function ( index ) {
  52. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  53. },
  54. setXY: function ( index, x, y ) {
  55. index = index * this.data.stride + this.offset;
  56. this.data.array[ index + 0 ] = x;
  57. this.data.array[ index + 1 ] = y;
  58. return this;
  59. },
  60. setXYZ: function ( index, x, y, z ) {
  61. index = index * this.data.stride + this.offset;
  62. this.data.array[ index + 0 ] = x;
  63. this.data.array[ index + 1 ] = y;
  64. this.data.array[ index + 2 ] = z;
  65. return this;
  66. },
  67. setXYZW: function ( index, x, y, z, w ) {
  68. index = index * this.data.stride + this.offset;
  69. this.data.array[ index + 0 ] = x;
  70. this.data.array[ index + 1 ] = y;
  71. this.data.array[ index + 2 ] = z;
  72. this.data.array[ index + 3 ] = w;
  73. return this;
  74. }
  75. } );
  76. export { InterleavedBufferAttribute };