boundingInfo.d.ts 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import type { DeepImmutable } from "../types";
  2. import type { Matrix } from "../Maths/math.vector";
  3. import { Vector3 } from "../Maths/math.vector";
  4. import { BoundingBox } from "./boundingBox";
  5. import { BoundingSphere } from "./boundingSphere";
  6. import type { Plane } from "../Maths/math.plane";
  7. import type { Collider } from "../Collisions/collider";
  8. /**
  9. * Interface for cullable objects
  10. * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/materials_introduction#back-face-culling
  11. */
  12. export interface ICullable {
  13. /**
  14. * Checks if the object or part of the object is in the frustum
  15. * @param frustumPlanes Camera near/planes
  16. * @returns true if the object is in frustum otherwise false
  17. */
  18. isInFrustum(frustumPlanes: Plane[]): boolean;
  19. /**
  20. * Checks if a cullable object (mesh...) is in the camera frustum
  21. * Unlike isInFrustum this checks the full bounding box
  22. * @param frustumPlanes Camera near/planes
  23. * @returns true if the object is in frustum otherwise false
  24. */
  25. isCompletelyInFrustum(frustumPlanes: Plane[]): boolean;
  26. }
  27. /**
  28. * Info for a bounding data of a mesh
  29. */
  30. export declare class BoundingInfo implements ICullable {
  31. /**
  32. * Bounding box for the mesh
  33. */
  34. readonly boundingBox: BoundingBox;
  35. /**
  36. * Bounding sphere for the mesh
  37. */
  38. readonly boundingSphere: BoundingSphere;
  39. private _isLocked;
  40. private static readonly _TmpVector3;
  41. /**
  42. * Constructs bounding info
  43. * @param minimum min vector of the bounding box/sphere
  44. * @param maximum max vector of the bounding box/sphere
  45. * @param worldMatrix defines the new world matrix
  46. */
  47. constructor(minimum: DeepImmutable<Vector3>, maximum: DeepImmutable<Vector3>, worldMatrix?: DeepImmutable<Matrix>);
  48. /**
  49. * Recreates the entire bounding info from scratch as if we call the constructor in place
  50. * @param min defines the new minimum vector (in local space)
  51. * @param max defines the new maximum vector (in local space)
  52. * @param worldMatrix defines the new world matrix
  53. */
  54. reConstruct(min: DeepImmutable<Vector3>, max: DeepImmutable<Vector3>, worldMatrix?: DeepImmutable<Matrix>): void;
  55. /**
  56. * min vector of the bounding box/sphere
  57. */
  58. get minimum(): Vector3;
  59. /**
  60. * max vector of the bounding box/sphere
  61. */
  62. get maximum(): Vector3;
  63. /**
  64. * If the info is locked and won't be updated to avoid perf overhead
  65. */
  66. get isLocked(): boolean;
  67. set isLocked(value: boolean);
  68. /**
  69. * Updates the bounding sphere and box
  70. * @param world world matrix to be used to update
  71. */
  72. update(world: DeepImmutable<Matrix>): void;
  73. /**
  74. * Recreate the bounding info to be centered around a specific point given a specific extend.
  75. * @param center New center of the bounding info
  76. * @param extend New extend of the bounding info
  77. * @returns the current bounding info
  78. */
  79. centerOn(center: DeepImmutable<Vector3>, extend: DeepImmutable<Vector3>): BoundingInfo;
  80. /**
  81. * Grows the bounding info to include the given point.
  82. * @param point The point that will be included in the current bounding info (in local space)
  83. * @returns the current bounding info
  84. */
  85. encapsulate(point: Vector3): BoundingInfo;
  86. /**
  87. * Grows the bounding info to encapsulate the given bounding info.
  88. * @param toEncapsulate The bounding info that will be encapsulated in the current bounding info
  89. * @returns the current bounding info
  90. */
  91. encapsulateBoundingInfo(toEncapsulate: BoundingInfo): BoundingInfo;
  92. /**
  93. * Scale the current bounding info by applying a scale factor
  94. * @param factor defines the scale factor to apply
  95. * @returns the current bounding info
  96. */
  97. scale(factor: number): BoundingInfo;
  98. /**
  99. * Returns `true` if the bounding info is within the frustum defined by the passed array of planes.
  100. * @param frustumPlanes defines the frustum to test
  101. * @param strategy defines the strategy to use for the culling (default is BABYLON.AbstractMesh.CULLINGSTRATEGY_STANDARD)
  102. * The different strategies available are:
  103. * * BABYLON.AbstractMesh.CULLINGSTRATEGY_STANDARD most accurate but slower @see https://doc.babylonjs.com/typedoc/classes/BABYLON.AbstractMesh#CULLINGSTRATEGY_STANDARD
  104. * * BABYLON.AbstractMesh.CULLINGSTRATEGY_BOUNDINGSPHERE_ONLY faster but less accurate @see https://doc.babylonjs.com/typedoc/classes/BABYLON.AbstractMesh#CULLINGSTRATEGY_BOUNDINGSPHERE_ONLY
  105. * * BABYLON.AbstractMesh.CULLINGSTRATEGY_OPTIMISTIC_INCLUSION can be faster if always visible @see https://doc.babylonjs.com/typedoc/classes/BABYLON.AbstractMesh#CULLINGSTRATEGY_OPTIMISTIC_INCLUSION
  106. * * BABYLON.AbstractMesh.CULLINGSTRATEGY_OPTIMISTIC_INCLUSION_THEN_BSPHERE_ONLY can be faster if always visible @see https://doc.babylonjs.com/typedoc/classes/BABYLON.AbstractMesh#CULLINGSTRATEGY_OPTIMISTIC_INCLUSION_THEN_BSPHERE_ONLY
  107. * @returns true if the bounding info is in the frustum planes
  108. */
  109. isInFrustum(frustumPlanes: Array<DeepImmutable<Plane>>, strategy?: number): boolean;
  110. /**
  111. * Gets the world distance between the min and max points of the bounding box
  112. */
  113. get diagonalLength(): number;
  114. /**
  115. * Checks if a cullable object (mesh...) is in the camera frustum
  116. * Unlike isInFrustum this checks the full bounding box
  117. * @param frustumPlanes Camera near/planes
  118. * @returns true if the object is in frustum otherwise false
  119. */
  120. isCompletelyInFrustum(frustumPlanes: Array<DeepImmutable<Plane>>): boolean;
  121. /**
  122. * @internal
  123. */
  124. _checkCollision(collider: Collider): boolean;
  125. /**
  126. * Checks if a point is inside the bounding box and bounding sphere or the mesh
  127. * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/interactions/mesh_intersect
  128. * @param point the point to check intersection with
  129. * @returns if the point intersects
  130. */
  131. intersectsPoint(point: DeepImmutable<Vector3>): boolean;
  132. /**
  133. * Checks if another bounding info intersects the bounding box and bounding sphere or the mesh
  134. * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/interactions/mesh_intersect
  135. * @param boundingInfo the bounding info to check intersection with
  136. * @param precise if the intersection should be done using OBB
  137. * @returns if the bounding info intersects
  138. */
  139. intersects(boundingInfo: DeepImmutable<BoundingInfo>, precise: boolean): boolean;
  140. }