renderingGroup.d.ts 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. import { SmartArray, SmartArrayNoDuplicate } from "../Misc/smartArray";
  2. import type { SubMesh } from "../Meshes/subMesh";
  3. import type { AbstractMesh } from "../Meshes/abstractMesh";
  4. import type { Nullable } from "../types";
  5. import type { IParticleSystem } from "../Particles/IParticleSystem";
  6. import type { IEdgesRenderer } from "./edgesRenderer";
  7. import type { ISpriteManager } from "../Sprites/spriteManager";
  8. import type { Material } from "../Materials/material";
  9. import type { Scene } from "../scene";
  10. /**
  11. * This represents the object necessary to create a rendering group.
  12. * This is exclusively used and created by the rendering manager.
  13. * To modify the behavior, you use the available helpers in your scene or meshes.
  14. * @internal
  15. */
  16. export declare class RenderingGroup {
  17. index: number;
  18. private static _ZeroVector;
  19. private _scene;
  20. private _opaqueSubMeshes;
  21. private _transparentSubMeshes;
  22. private _alphaTestSubMeshes;
  23. private _depthOnlySubMeshes;
  24. private _particleSystems;
  25. private _spriteManagers;
  26. private _opaqueSortCompareFn;
  27. private _alphaTestSortCompareFn;
  28. private _transparentSortCompareFn;
  29. private _renderOpaque;
  30. private _renderAlphaTest;
  31. private _renderTransparent;
  32. /** @internal */
  33. _empty: boolean;
  34. /** @internal */
  35. _edgesRenderers: SmartArrayNoDuplicate<IEdgesRenderer>;
  36. onBeforeTransparentRendering: () => void;
  37. /**
  38. * Set the opaque sort comparison function.
  39. * If null the sub meshes will be render in the order they were created
  40. */
  41. set opaqueSortCompareFn(value: Nullable<(a: SubMesh, b: SubMesh) => number>);
  42. /**
  43. * Set the alpha test sort comparison function.
  44. * If null the sub meshes will be render in the order they were created
  45. */
  46. set alphaTestSortCompareFn(value: Nullable<(a: SubMesh, b: SubMesh) => number>);
  47. /**
  48. * Set the transparent sort comparison function.
  49. * If null the sub meshes will be render in the order they were created
  50. */
  51. set transparentSortCompareFn(value: Nullable<(a: SubMesh, b: SubMesh) => number>);
  52. /**
  53. * Creates a new rendering group.
  54. * @param index The rendering group index
  55. * @param scene
  56. * @param opaqueSortCompareFn The opaque sort comparison function. If null no order is applied
  57. * @param alphaTestSortCompareFn The alpha test sort comparison function. If null no order is applied
  58. * @param transparentSortCompareFn The transparent sort comparison function. If null back to front + alpha index sort is applied
  59. */
  60. constructor(index: number, scene: Scene, opaqueSortCompareFn?: Nullable<(a: SubMesh, b: SubMesh) => number>, alphaTestSortCompareFn?: Nullable<(a: SubMesh, b: SubMesh) => number>, transparentSortCompareFn?: Nullable<(a: SubMesh, b: SubMesh) => number>);
  61. /**
  62. * Render all the sub meshes contained in the group.
  63. * @param customRenderFunction Used to override the default render behaviour of the group.
  64. * @param renderSprites
  65. * @param renderParticles
  66. * @param activeMeshes
  67. */
  68. render(customRenderFunction: Nullable<(opaqueSubMeshes: SmartArray<SubMesh>, transparentSubMeshes: SmartArray<SubMesh>, alphaTestSubMeshes: SmartArray<SubMesh>, depthOnlySubMeshes: SmartArray<SubMesh>) => void>, renderSprites: boolean, renderParticles: boolean, activeMeshes: Nullable<AbstractMesh[]>): void;
  69. /**
  70. * Renders the opaque submeshes in the order from the opaqueSortCompareFn.
  71. * @param subMeshes The submeshes to render
  72. */
  73. private _renderOpaqueSorted;
  74. /**
  75. * Renders the opaque submeshes in the order from the alphatestSortCompareFn.
  76. * @param subMeshes The submeshes to render
  77. */
  78. private _renderAlphaTestSorted;
  79. /**
  80. * Renders the opaque submeshes in the order from the transparentSortCompareFn.
  81. * @param subMeshes The submeshes to render
  82. */
  83. private _renderTransparentSorted;
  84. /**
  85. * Renders the submeshes in a specified order.
  86. * @param subMeshes The submeshes to sort before render
  87. * @param sortCompareFn The comparison function use to sort
  88. * @param camera The camera position use to preprocess the submeshes to help sorting
  89. * @param transparent Specifies to activate blending if true
  90. */
  91. private static _RenderSorted;
  92. /**
  93. * Build in function which can be applied to ensure meshes of a special queue (opaque, alpha test, transparent)
  94. * are rendered back to front if in the same alpha index.
  95. *
  96. * @param a The first submesh
  97. * @param b The second submesh
  98. * @returns The result of the comparison
  99. */
  100. static defaultTransparentSortCompare(a: SubMesh, b: SubMesh): number;
  101. /**
  102. * Build in function which can be applied to ensure meshes of a special queue (opaque, alpha test, transparent)
  103. * are rendered back to front.
  104. *
  105. * @param a The first submesh
  106. * @param b The second submesh
  107. * @returns The result of the comparison
  108. */
  109. static backToFrontSortCompare(a: SubMesh, b: SubMesh): number;
  110. /**
  111. * Build in function which can be applied to ensure meshes of a special queue (opaque, alpha test, transparent)
  112. * are rendered front to back (prevent overdraw).
  113. *
  114. * @param a The first submesh
  115. * @param b The second submesh
  116. * @returns The result of the comparison
  117. */
  118. static frontToBackSortCompare(a: SubMesh, b: SubMesh): number;
  119. /**
  120. * Build in function which can be applied to ensure meshes of a special queue (opaque, alpha test, transparent)
  121. * are grouped by material then geometry.
  122. *
  123. * @param a The first submesh
  124. * @param b The second submesh
  125. * @returns The result of the comparison
  126. */
  127. static PainterSortCompare(a: SubMesh, b: SubMesh): number;
  128. /**
  129. * Resets the different lists of submeshes to prepare a new frame.
  130. */
  131. prepare(): void;
  132. /**
  133. * Resets the different lists of sprites to prepare a new frame.
  134. */
  135. prepareSprites(): void;
  136. dispose(): void;
  137. /**
  138. * Inserts the submesh in its correct queue depending on its material.
  139. * @param subMesh The submesh to dispatch
  140. * @param [mesh] Optional reference to the submeshes's mesh. Provide if you have an exiting reference to improve performance.
  141. * @param [material] Optional reference to the submeshes's material. Provide if you have an exiting reference to improve performance.
  142. */
  143. dispatch(subMesh: SubMesh, mesh?: AbstractMesh, material?: Nullable<Material>): void;
  144. dispatchSprites(spriteManager: ISpriteManager): void;
  145. dispatchParticles(particleSystem: IParticleSystem): void;
  146. private _renderParticles;
  147. private _renderSprites;
  148. }