InterleavedBuffer.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /**
  2. * @author benaadams / https://twitter.com/ben_a_adams
  3. */
  4. THREE.InterleavedBuffer = function ( array, stride ) {
  5. this.uuid = THREE.Math.generateUUID();
  6. this.array = array;
  7. this.stride = stride;
  8. this.dynamic = false;
  9. this.updateRange = { offset: 0, count: - 1 };
  10. this.version = 0;
  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. setDynamic: function ( value ) {
  24. this.dynamic = value;
  25. return this;
  26. },
  27. copy: function ( source ) {
  28. this.array = new source.array.constructor( source.array );
  29. this.stride = source.stride;
  30. this.dynamic = source.dynamic;
  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. };