octreeBlock.d.ts 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import type { SmartArrayNoDuplicate } from "../../Misc/smartArray";
  2. import { Vector3 } from "../../Maths/math.vector";
  3. import type { Ray } from "../../Culling/ray";
  4. import type { Plane } from "../../Maths/math.plane";
  5. /**
  6. * Contains an array of blocks representing the octree
  7. */
  8. export interface IOctreeContainer<T> {
  9. /**
  10. * Blocks within the octree
  11. */
  12. blocks: Array<OctreeBlock<T>>;
  13. }
  14. /**
  15. * Class used to store a cell in an octree
  16. * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/optimizeOctrees
  17. */
  18. export declare class OctreeBlock<T> {
  19. /**
  20. * Gets the content of the current block
  21. */
  22. entries: T[];
  23. /**
  24. * Gets the list of block children
  25. */
  26. blocks: Array<OctreeBlock<T>>;
  27. private _depth;
  28. private _maxDepth;
  29. private _capacity;
  30. private _minPoint;
  31. private _maxPoint;
  32. private _boundingVectors;
  33. private _creationFunc;
  34. /**
  35. * Creates a new block
  36. * @param minPoint defines the minimum vector (in world space) of the block's bounding box
  37. * @param maxPoint defines the maximum vector (in world space) of the block's bounding box
  38. * @param capacity defines the maximum capacity of this block (if capacity is reached the block will be split into sub blocks)
  39. * @param depth defines the current depth of this block in the octree
  40. * @param maxDepth defines the maximal depth allowed (beyond this value, the capacity is ignored)
  41. * @param creationFunc defines a callback to call when an element is added to the block
  42. */
  43. constructor(minPoint: Vector3, maxPoint: Vector3, capacity: number, depth: number, maxDepth: number, creationFunc: (entry: T, block: OctreeBlock<T>) => void);
  44. /**
  45. * Gets the maximum capacity of this block (if capacity is reached the block will be split into sub blocks)
  46. */
  47. get capacity(): number;
  48. /**
  49. * Gets the minimum vector (in world space) of the block's bounding box
  50. */
  51. get minPoint(): Vector3;
  52. /**
  53. * Gets the maximum vector (in world space) of the block's bounding box
  54. */
  55. get maxPoint(): Vector3;
  56. /**
  57. * Add a new element to this block
  58. * @param entry defines the element to add
  59. */
  60. addEntry(entry: T): void;
  61. /**
  62. * Remove an element from this block
  63. * @param entry defines the element to remove
  64. */
  65. removeEntry(entry: T): void;
  66. /**
  67. * Add an array of elements to this block
  68. * @param entries defines the array of elements to add
  69. */
  70. addEntries(entries: T[]): void;
  71. /**
  72. * Test if the current block intersects the frustum planes and if yes, then add its content to the selection array
  73. * @param frustumPlanes defines the frustum planes to test
  74. * @param selection defines the array to store current content if selection is positive
  75. * @param allowDuplicate defines if the selection array can contains duplicated entries
  76. */
  77. select(frustumPlanes: Plane[], selection: SmartArrayNoDuplicate<T>, allowDuplicate?: boolean): void;
  78. /**
  79. * Test if the current block intersect with the given bounding sphere and if yes, then add its content to the selection array
  80. * @param sphereCenter defines the bounding sphere center
  81. * @param sphereRadius defines the bounding sphere radius
  82. * @param selection defines the array to store current content if selection is positive
  83. * @param allowDuplicate defines if the selection array can contains duplicated entries
  84. */
  85. intersects(sphereCenter: Vector3, sphereRadius: number, selection: SmartArrayNoDuplicate<T>, allowDuplicate?: boolean): void;
  86. /**
  87. * Test if the current block intersect with the given ray and if yes, then add its content to the selection array
  88. * @param ray defines the ray to test with
  89. * @param selection defines the array to store current content if selection is positive
  90. */
  91. intersectsRay(ray: Ray, selection: SmartArrayNoDuplicate<T>): void;
  92. /**
  93. * Subdivide the content into child blocks (this block will then be empty)
  94. */
  95. createInnerBlocks(): void;
  96. /**
  97. * @internal
  98. */
  99. static _CreateBlocks<T>(worldMin: Vector3, worldMax: Vector3, entries: T[], maxBlockCapacity: number, currentDepth: number, maxDepth: number, target: IOctreeContainer<T>, creationFunc: (entry: T, block: OctreeBlock<T>) => void): void;
  100. }