InterleavedBuffer.js 1.1 KB

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