InterleavedBuffer.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 !== undefined ? array.length / stride : 0;
  10. this.dynamic = false;
  11. this.updateRange = { offset: 0, count: - 1 };
  12. this.onUploadCallback = function () {};
  13. this.version = 0;
  14. }
  15. Object.defineProperty( InterleavedBuffer.prototype, "needsUpdate", {
  16. set: function(value) {
  17. if ( value === true ) this.version ++;
  18. }
  19. });
  20. Object.assign( InterleavedBuffer.prototype, {
  21. isInterleavedBuffer: true,
  22. setArray: function ( array ) {
  23. if ( Array.isArray( array ) ) {
  24. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  25. }
  26. this.count = array !== undefined ? array.length / this.stride : 0;
  27. this.array = array;
  28. },
  29. setDynamic: function ( value ) {
  30. this.dynamic = value;
  31. return this;
  32. },
  33. copy: function ( source ) {
  34. this.array = new source.array.constructor( source.array );
  35. this.count = source.count;
  36. this.stride = source.stride;
  37. this.dynamic = source.dynamic;
  38. return this;
  39. },
  40. copyAt: function ( index1, attribute, index2 ) {
  41. index1 *= this.stride;
  42. index2 *= attribute.stride;
  43. for ( var i = 0, l = this.stride; i < l; i ++ ) {
  44. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  45. }
  46. return this;
  47. },
  48. set: function ( value, offset ) {
  49. if ( offset === undefined ) offset = 0;
  50. this.array.set( value, offset );
  51. return this;
  52. },
  53. clone: function () {
  54. return new this.constructor().copy( this );
  55. },
  56. onUpload: function ( callback ) {
  57. this.onUploadCallback = callback;
  58. return this;
  59. }
  60. } );
  61. export { InterleavedBuffer };