Arrays.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import StorageInstancedBufferAttribute from '../../renderers/common/StorageInstancedBufferAttribute.js';
  2. import StorageBufferAttribute from '../../renderers/common/StorageBufferAttribute.js';
  3. import { storage } from './StorageBufferNode.js';
  4. import { getLengthFromType, getTypedArrayFromType } from '../core/NodeUtils.js';
  5. /** @module Arrays **/
  6. /**
  7. * TSL function for creating a storage buffer node with a configured `StorageBufferAttribute`.
  8. *
  9. * @function
  10. * @param {Number} count - The data count.
  11. * @param {String} [type='float'] - The data type.
  12. * @returns {StorageBufferNode}
  13. */
  14. export const attributeArray = ( count, type = 'float' ) => {
  15. const itemSize = getLengthFromType( type );
  16. const typedArray = getTypedArrayFromType( type );
  17. const buffer = new StorageBufferAttribute( count, itemSize, typedArray );
  18. const node = storage( buffer, type, count );
  19. return node;
  20. };
  21. /**
  22. * TSL function for creating a storage buffer node with a configured `StorageInstancedBufferAttribute`.
  23. *
  24. * @function
  25. * @param {Number} count - The data count.
  26. * @param {String} [type='float'] - The data type.
  27. * @returns {StorageBufferNode}
  28. */
  29. export const instancedArray = ( count, type = 'float' ) => {
  30. const itemSize = getLengthFromType( type );
  31. const typedArray = getTypedArrayFromType( type );
  32. const buffer = new StorageInstancedBufferAttribute( count, itemSize, typedArray );
  33. const node = storage( buffer, type, count );
  34. return node;
  35. };
粤ICP备19079148号