InterleavedBufferAttribute.js 2.3 KB

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