InstancedBufferAttribute.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { BufferAttribute } from './BufferAttribute.js';
  2. /**
  3. * An instanced version of a buffer attribute.
  4. *
  5. * @augments BufferAttribute
  6. */
  7. class InstancedBufferAttribute extends BufferAttribute {
  8. /**
  9. * Constructs a new instanced buffer attribute.
  10. *
  11. * @param {TypedArray} array - The array holding the attribute data.
  12. * @param {number} itemSize - The item size.
  13. * @param {boolean} [normalized=false] - Whether the data are normalized or not.
  14. * @param {number} [meshPerAttribute=1] - How often a value of this buffer attribute should be repeated.
  15. */
  16. constructor( array, itemSize, normalized, meshPerAttribute = 1 ) {
  17. super( array, itemSize, normalized );
  18. /**
  19. * This flag can be used for type testing.
  20. *
  21. * @type {boolean}
  22. * @readonly
  23. * @default true
  24. */
  25. this.isInstancedBufferAttribute = true;
  26. /**
  27. * Defines how often a value of this buffer attribute should be repeated. A
  28. * value of one means that each value of the instanced attribute is used for
  29. * a single instance. A value of two means that each value is used for two
  30. * consecutive instances (and so on).
  31. *
  32. * @type {number}
  33. * @default 1
  34. */
  35. this.meshPerAttribute = meshPerAttribute;
  36. }
  37. copy( source ) {
  38. super.copy( source );
  39. this.meshPerAttribute = source.meshPerAttribute;
  40. return this;
  41. }
  42. toJSON() {
  43. const data = super.toJSON();
  44. data.meshPerAttribute = this.meshPerAttribute;
  45. data.isInstancedBufferAttribute = true;
  46. return data;
  47. }
  48. }
  49. export { InstancedBufferAttribute };
粤ICP备19079148号