thinInstanceMesh.d.ts 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import type { Nullable, DeepImmutableObject } from "../types";
  2. import { VertexBuffer, Buffer } from "../Buffers/buffer";
  3. import { Matrix } from "../Maths/math.vector";
  4. declare module "./mesh" {
  5. interface Mesh {
  6. /**
  7. * Gets or sets a boolean defining if we want picking to pick thin instances as well
  8. */
  9. thinInstanceEnablePicking: boolean;
  10. /**
  11. * Indicates that a buffer created as static should be recreated if the buffer is updated (by calling thinInstanceSetMatrixAt or thinInstanceSetAttributeAt, for eg.)
  12. * If this flag is false (the default behavior), a buffer created as "static" won't show any update done to it, and will stay the same as it was created.
  13. * Note however that recreating a buffer each time there's a change will have some performance cost, that's why it is set to false by default.
  14. * You should set this flag to true only if your static buffers should change infrequently. If they change frequently, you should create your buffers as "dynamic" instead.
  15. */
  16. thinInstanceAllowAutomaticStaticBufferRecreation: boolean;
  17. /**
  18. * Creates a new thin instance
  19. * @param matrix the matrix or array of matrices (position, rotation, scale) of the thin instance(s) to create
  20. * @param refresh true to refresh the underlying gpu buffer (default: true). If you do multiple calls to this method in a row, set refresh to true only for the last call to save performance
  21. * @returns the thin instance index number. If you pass an array of matrices, other instance indexes are index+1, index+2, etc
  22. */
  23. thinInstanceAdd(matrix: DeepImmutableObject<Matrix> | Array<DeepImmutableObject<Matrix>>, refresh?: boolean): number;
  24. /**
  25. * Adds the transformation (matrix) of the current mesh as a thin instance
  26. * @param refresh true to refresh the underlying gpu buffer (default: true). If you do multiple calls to this method in a row, set refresh to true only for the last call to save performance
  27. * @returns the thin instance index number
  28. */
  29. thinInstanceAddSelf(refresh?: boolean): number;
  30. /**
  31. * Registers a custom attribute to be used with thin instances
  32. * @param kind name of the attribute
  33. * @param stride size in floats of the attribute
  34. */
  35. thinInstanceRegisterAttribute(kind: string, stride: number): void;
  36. /**
  37. * Sets the matrix of a thin instance
  38. * @param index index of the thin instance
  39. * @param matrix matrix to set
  40. * @param refresh true to refresh the underlying gpu buffer (default: true). If you do multiple calls to this method in a row, set refresh to true only for the last call to save performance
  41. */
  42. thinInstanceSetMatrixAt(index: number, matrix: DeepImmutableObject<Matrix>, refresh?: boolean): void;
  43. /**
  44. * Sets the value of a custom attribute for a thin instance
  45. * @param kind name of the attribute
  46. * @param index index of the thin instance
  47. * @param value value to set
  48. * @param refresh true to refresh the underlying gpu buffer (default: true). If you do multiple calls to this method in a row, set refresh to true only for the last call to save performance
  49. */
  50. thinInstanceSetAttributeAt(kind: string, index: number, value: Array<number>, refresh?: boolean): void;
  51. /**
  52. * Gets / sets the number of thin instances to display. Note that you can't set a number higher than what the underlying buffer can handle.
  53. */
  54. thinInstanceCount: number;
  55. /**
  56. * Sets a buffer to be used with thin instances. This method is a faster way to setup multiple instances than calling thinInstanceAdd repeatedly
  57. * @param kind name of the attribute. Use "matrix" to setup the buffer of matrices
  58. * @param buffer buffer to set
  59. * @param stride size in floats of each value of the buffer
  60. * @param staticBuffer indicates that the buffer is static, so that you won't change it after it is set (better performances - true by default)
  61. */
  62. thinInstanceSetBuffer(kind: string, buffer: Nullable<Float32Array>, stride?: number, staticBuffer?: boolean): void;
  63. /**
  64. * Gets the list of world matrices
  65. * @returns an array containing all the world matrices from the thin instances
  66. */
  67. thinInstanceGetWorldMatrices(): Matrix[];
  68. /**
  69. * Synchronize the gpu buffers with a thin instance buffer. Call this method if you update later on the buffers passed to thinInstanceSetBuffer
  70. * @param kind name of the attribute to update. Use "matrix" to update the buffer of matrices
  71. */
  72. thinInstanceBufferUpdated(kind: string): void;
  73. /**
  74. * Applies a partial update to a buffer directly on the GPU
  75. * Note that the buffer located on the CPU is NOT updated! It's up to you to update it (or not) with the same data you pass to this method
  76. * @param kind name of the attribute to update. Use "matrix" to update the buffer of matrices
  77. * @param data the data to set in the GPU buffer
  78. * @param offset the offset in the GPU buffer where to update the data
  79. */
  80. thinInstancePartialBufferUpdate(kind: string, data: Float32Array, offset: number): void;
  81. /**
  82. * Refreshes the bounding info, taking into account all the thin instances defined
  83. * @param forceRefreshParentInfo true to force recomputing the mesh bounding info and use it to compute the aggregated bounding info
  84. * @param applySkeleton defines whether to apply the skeleton before computing the bounding info
  85. * @param applyMorph defines whether to apply the morph target before computing the bounding info
  86. */
  87. thinInstanceRefreshBoundingInfo(forceRefreshParentInfo?: boolean, applySkeleton?: boolean, applyMorph?: boolean): void;
  88. /** @internal */
  89. _thinInstanceInitializeUserStorage(): void;
  90. /** @internal */
  91. _thinInstanceUpdateBufferSize(kind: string, numInstances?: number): void;
  92. /** @internal */
  93. _thinInstanceCreateMatrixBuffer(kind: string, buffer: Nullable<Float32Array>, staticBuffer: boolean): Buffer;
  94. /** @internal */
  95. _thinInstanceRecreateBuffer(kind: string, staticBuffer?: boolean): void;
  96. /** @internal */
  97. _userThinInstanceBuffersStorage: {
  98. data: {
  99. [key: string]: Float32Array;
  100. };
  101. sizes: {
  102. [key: string]: number;
  103. };
  104. vertexBuffers: {
  105. [key: string]: Nullable<VertexBuffer>;
  106. };
  107. strides: {
  108. [key: string]: number;
  109. };
  110. };
  111. }
  112. }