InterleavedBuffer.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import { _Math } from '../math/Math';
  2. /**
  3. * @author benaadams / https://twitter.com/ben_a_adams
  4. */
  5. function InterleavedBuffer( array, stride ) {
  6. this.uuid = _Math.generateUUID();
  7. this.array = array;
  8. this.stride = stride;
  9. this.count = array.length / stride;
  10. this.dynamic = false;
  11. this.updateRange = { offset: 0, count: - 1 };
  12. this.version = 0;
  13. }
  14. InterleavedBuffer.prototype = {
  15. constructor: InterleavedBuffer,
  16. isInterleavedBuffer: true,
  17. set needsUpdate( value ) {
  18. if ( value === true ) this.version ++;
  19. },
  20. setDynamic: function ( value ) {
  21. this.dynamic = value;
  22. return this;
  23. },
  24. copy: function ( source ) {
  25. this.array = new source.array.constructor( source.array );
  26. this.count = source.count;
  27. this.stride = source.stride;
  28. this.dynamic = source.dynamic;
  29. return this;
  30. },
  31. copyAt: function ( index1, attribute, index2 ) {
  32. index1 *= this.stride;
  33. index2 *= attribute.stride;
  34. for ( var i = 0, l = this.stride; i < l; i ++ ) {
  35. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  36. }
  37. return this;
  38. },
  39. set: function ( value, offset ) {
  40. if ( offset === undefined ) offset = 0;
  41. this.array.set( value, offset );
  42. return this;
  43. },
  44. clone: function () {
  45. return new this.constructor().copy( this );
  46. }
  47. };
  48. export { InterleavedBuffer };