octreeSceneComponent.d.ts 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import type { ISmartArrayLike } from "../../Misc/smartArray";
  2. import { Scene } from "../../scene";
  3. import type { SubMesh } from "../../Meshes/subMesh";
  4. import { AbstractMesh } from "../../Meshes/abstractMesh";
  5. import { Ray } from "../../Culling/ray";
  6. import { Octree } from "./octree";
  7. import type { Collider } from "../../Collisions/collider";
  8. declare module "../../scene" {
  9. interface Scene {
  10. /**
  11. * @internal
  12. * Backing Filed
  13. */
  14. _selectionOctree: Octree<AbstractMesh>;
  15. /**
  16. * Gets the octree used to boost mesh selection (picking)
  17. * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/optimizeOctrees
  18. */
  19. selectionOctree: Octree<AbstractMesh>;
  20. /**
  21. * Creates or updates the octree used to boost selection (picking)
  22. * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/optimizeOctrees
  23. * @param maxCapacity defines the maximum capacity per leaf
  24. * @param maxDepth defines the maximum depth of the octree
  25. * @returns an octree of AbstractMesh
  26. */
  27. createOrUpdateSelectionOctree(maxCapacity?: number, maxDepth?: number): Octree<AbstractMesh>;
  28. }
  29. }
  30. declare module "../../Meshes/abstractMesh" {
  31. interface AbstractMesh {
  32. /**
  33. * @internal
  34. * Backing Field
  35. */
  36. _submeshesOctree: Octree<SubMesh>;
  37. /**
  38. * This function will create an octree to help to select the right submeshes for rendering, picking and collision computations.
  39. * Please note that you must have a decent number of submeshes to get performance improvements when using an octree
  40. * @param maxCapacity defines the maximum size of each block (64 by default)
  41. * @param maxDepth defines the maximum depth to use (no more than 2 levels by default)
  42. * @returns the new octree
  43. * @see https://www.babylonjs-playground.com/#NA4OQ#12
  44. * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/optimizeOctrees
  45. */
  46. createOrUpdateSubmeshesOctree(maxCapacity?: number, maxDepth?: number): Octree<SubMesh>;
  47. }
  48. }
  49. /**
  50. * Defines the octree scene component responsible to manage any octrees
  51. * in a given scene.
  52. */
  53. export declare class OctreeSceneComponent {
  54. /**
  55. * The component name help to identify the component in the list of scene components.
  56. */
  57. readonly name = "Octree";
  58. /**
  59. * The scene the component belongs to.
  60. */
  61. scene: Scene;
  62. /**
  63. * Indicates if the meshes have been checked to make sure they are isEnabled()
  64. */
  65. readonly checksIsEnabled = true;
  66. /**
  67. * Creates a new instance of the component for the given scene
  68. * @param scene Defines the scene to register the component in
  69. */
  70. constructor(scene?: Scene);
  71. /**
  72. * Registers the component in a given scene
  73. */
  74. register(): void;
  75. /**
  76. * Return the list of active meshes
  77. * @returns the list of active meshes
  78. */
  79. getActiveMeshCandidates(): ISmartArrayLike<AbstractMesh>;
  80. /**
  81. * Return the list of active sub meshes
  82. * @param mesh The mesh to get the candidates sub meshes from
  83. * @returns the list of active sub meshes
  84. */
  85. getActiveSubMeshCandidates(mesh: AbstractMesh): ISmartArrayLike<SubMesh>;
  86. private _tempRay;
  87. /**
  88. * Return the list of sub meshes intersecting with a given local ray
  89. * @param mesh defines the mesh to find the submesh for
  90. * @param localRay defines the ray in local space
  91. * @returns the list of intersecting sub meshes
  92. */
  93. getIntersectingSubMeshCandidates(mesh: AbstractMesh, localRay: Ray): ISmartArrayLike<SubMesh>;
  94. /**
  95. * Return the list of sub meshes colliding with a collider
  96. * @param mesh defines the mesh to find the submesh for
  97. * @param collider defines the collider to evaluate the collision against
  98. * @returns the list of colliding sub meshes
  99. */
  100. getCollidingSubMeshCandidates(mesh: AbstractMesh, collider: Collider): ISmartArrayLike<SubMesh>;
  101. /**
  102. * Rebuilds the elements related to this component in case of
  103. * context lost for instance.
  104. */
  105. rebuild(): void;
  106. /**
  107. * Disposes the component and the associated resources.
  108. */
  109. dispose(): void;
  110. }