Arrays.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. /**
  6. * TSL function for creating a storage buffer node with a configured `StorageBufferAttribute`.
  7. *
  8. * @tsl
  9. * @function
  10. * @param {Number|TypedArray} count - The data count. It is also valid to pass a typed array as an argument.
  11. * @param {String|Struct} [type='float'] - The data type.
  12. * @returns {StorageBufferNode}
  13. */
  14. export const attributeArray = ( count, type = 'float' ) => {
  15. let itemSize, typedArray;
  16. if ( type.isStruct === true ) {
  17. itemSize = type.layout.getLength();
  18. typedArray = getTypedArrayFromType( 'float' );
  19. } else {
  20. itemSize = getLengthFromType( type );
  21. typedArray = getTypedArrayFromType( type );
  22. }
  23. const buffer = new StorageBufferAttribute( count, itemSize, typedArray );
  24. const node = storage( buffer, type, count );
  25. return node;
  26. };
  27. /**
  28. * TSL function for creating a storage buffer node with a configured `StorageInstancedBufferAttribute`.
  29. *
  30. * @tsl
  31. * @function
  32. * @param {Number|TypedArray} count - The data count. It is also valid to pass a typed array as an argument.
  33. * @param {String|Struct} [type='float'] - The data type.
  34. * @returns {StorageBufferNode}
  35. */
  36. export const instancedArray = ( count, type = 'float' ) => {
  37. let itemSize, typedArray;
  38. if ( type.isStruct === true ) {
  39. itemSize = type.layout.getLength();
  40. typedArray = getTypedArrayFromType( 'float' );
  41. } else {
  42. itemSize = getLengthFromType( type );
  43. typedArray = getTypedArrayFromType( type );
  44. }
  45. const buffer = new StorageInstancedBufferAttribute( count, itemSize, typedArray );
  46. const node = storage( buffer, type, count );
  47. return node;
  48. };
粤ICP备19079148号