InterleavedBufferAttribute.js 2.2 KB

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