InterleavedBufferAttribute.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. import { Vector3 } from '../math/Vector3.js';
  2. /**
  3. * @author benaadams / https://twitter.com/ben_a_adams
  4. */
  5. var _vector = new Vector3();
  6. function InterleavedBufferAttribute( interleavedBuffer, itemSize, offset, normalized ) {
  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. applyMatrix4: function ( m ) {
  27. for ( var i = 0, l = this.data.count; i < l; i ++ ) {
  28. _vector.x = this.getX( i );
  29. _vector.y = this.getY( i );
  30. _vector.z = this.getZ( i );
  31. _vector.applyMatrix4( m );
  32. this.setXYZ( i, _vector.x, _vector.y, _vector.z );
  33. }
  34. return this;
  35. },
  36. setX: function ( index, x ) {
  37. this.data.array[ index * this.data.stride + this.offset ] = x;
  38. return this;
  39. },
  40. setY: function ( index, y ) {
  41. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  42. return this;
  43. },
  44. setZ: function ( index, z ) {
  45. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  46. return this;
  47. },
  48. setW: function ( index, w ) {
  49. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  50. return this;
  51. },
  52. getX: function ( index ) {
  53. return this.data.array[ index * this.data.stride + this.offset ];
  54. },
  55. getY: function ( index ) {
  56. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  57. },
  58. getZ: function ( index ) {
  59. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  60. },
  61. getW: function ( index ) {
  62. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  63. },
  64. setXY: function ( index, x, y ) {
  65. index = index * this.data.stride + this.offset;
  66. this.data.array[ index + 0 ] = x;
  67. this.data.array[ index + 1 ] = y;
  68. return this;
  69. },
  70. setXYZ: function ( index, x, y, z ) {
  71. index = index * this.data.stride + this.offset;
  72. this.data.array[ index + 0 ] = x;
  73. this.data.array[ index + 1 ] = y;
  74. this.data.array[ index + 2 ] = z;
  75. return this;
  76. },
  77. setXYZW: function ( index, x, y, z, w ) {
  78. index = index * this.data.stride + this.offset;
  79. this.data.array[ index + 0 ] = x;
  80. this.data.array[ index + 1 ] = y;
  81. this.data.array[ index + 2 ] = z;
  82. this.data.array[ index + 3 ] = w;
  83. return this;
  84. }
  85. } );
  86. export { InterleavedBufferAttribute };