2
0

InterleavedBuffer.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import { StaticDrawUsage } from '../constants.js';
  2. /**
  3. * @author benaadams / https://twitter.com/ben_a_adams
  4. */
  5. function InterleavedBuffer( array, stride ) {
  6. this.array = array;
  7. this.stride = stride;
  8. this.count = array !== undefined ? array.length / stride : 0;
  9. this.usage = StaticDrawUsage;
  10. this.updateRange = { offset: 0, count: - 1 };
  11. this.version = 0;
  12. }
  13. Object.defineProperty( InterleavedBuffer.prototype, 'needsUpdate', {
  14. set: function ( value ) {
  15. if ( value === true ) this.version ++;
  16. }
  17. } );
  18. Object.assign( InterleavedBuffer.prototype, {
  19. isInterleavedBuffer: true,
  20. onUploadCallback: function () {},
  21. setUsage: function ( value ) {
  22. this.usage = value;
  23. return this;
  24. },
  25. copy: function ( source ) {
  26. this.array = new source.array.constructor( source.array );
  27. this.count = source.count;
  28. this.stride = source.stride;
  29. this.usage = source.usage;
  30. return this;
  31. },
  32. copyAt: function ( index1, attribute, index2 ) {
  33. index1 *= this.stride;
  34. index2 *= attribute.stride;
  35. for ( var i = 0, l = this.stride; i < l; i ++ ) {
  36. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  37. }
  38. return this;
  39. },
  40. set: function ( value, offset ) {
  41. if ( offset === undefined ) offset = 0;
  42. this.array.set( value, offset );
  43. return this;
  44. },
  45. clone: function () {
  46. return new this.constructor().copy( this );
  47. },
  48. onUpload: function ( callback ) {
  49. this.onUploadCallback = callback;
  50. return this;
  51. }
  52. } );
  53. export { InterleavedBuffer };