octree.d.ts 4.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import type { SmartArray } from "../../Misc/smartArray";
  2. import type { Vector3 } from "../../Maths/math.vector";
  3. import type { SubMesh } from "../../Meshes/subMesh";
  4. import type { AbstractMesh } from "../../Meshes/abstractMesh";
  5. import type { Ray } from "../../Culling/ray";
  6. import { OctreeBlock } from "./octreeBlock";
  7. import type { Plane } from "../../Maths/math.plane";
  8. /**
  9. * Octrees are a really powerful data structure that can quickly select entities based on space coordinates.
  10. * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/optimizeOctrees
  11. */
  12. export declare class Octree<T> {
  13. /** Defines the maximum depth (sub-levels) for your octree. Default value is 2, which means 8 8 8 = 512 blocks :) (This parameter takes precedence over capacity.) */
  14. maxDepth: number;
  15. /**
  16. * Blocks within the octree containing objects
  17. */
  18. blocks: Array<OctreeBlock<T>>;
  19. /**
  20. * Content stored in the octree
  21. */
  22. dynamicContent: T[];
  23. private _maxBlockCapacity;
  24. private _selectionContent;
  25. private _creationFunc;
  26. /**
  27. * Creates a octree
  28. * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/optimizeOctrees
  29. * @param creationFunc function to be used to instantiate the octree
  30. * @param maxBlockCapacity defines the maximum number of meshes you want on your octree's leaves (default: 64)
  31. * @param maxDepth defines the maximum depth (sub-levels) for your octree. Default value is 2, which means 8 8 8 = 512 blocks :) (This parameter takes precedence over capacity.)
  32. */
  33. constructor(creationFunc: (entry: T, block: OctreeBlock<T>) => void, maxBlockCapacity?: number,
  34. /** Defines the maximum depth (sub-levels) for your octree. Default value is 2, which means 8 8 8 = 512 blocks :) (This parameter takes precedence over capacity.) */
  35. maxDepth?: number);
  36. /**
  37. * Updates the octree by adding blocks for the passed in meshes within the min and max world parameters
  38. * @param worldMin worldMin for the octree blocks var blockSize = new Vector3((worldMax.x - worldMin.x) / 2, (worldMax.y - worldMin.y) / 2, (worldMax.z - worldMin.z) / 2);
  39. * @param worldMax worldMax for the octree blocks var blockSize = new Vector3((worldMax.x - worldMin.x) / 2, (worldMax.y - worldMin.y) / 2, (worldMax.z - worldMin.z) / 2);
  40. * @param entries meshes to be added to the octree blocks
  41. */
  42. update(worldMin: Vector3, worldMax: Vector3, entries: T[]): void;
  43. /**
  44. * Adds a mesh to the octree
  45. * @param entry Mesh to add to the octree
  46. */
  47. addMesh(entry: T): void;
  48. /**
  49. * Remove an element from the octree
  50. * @param entry defines the element to remove
  51. */
  52. removeMesh(entry: T): void;
  53. /**
  54. * Selects an array of meshes within the frustum
  55. * @param frustumPlanes The frustum planes to use which will select all meshes within it
  56. * @param allowDuplicate If duplicate objects are allowed in the resulting object array
  57. * @returns array of meshes within the frustum
  58. */
  59. select(frustumPlanes: Plane[], allowDuplicate?: boolean): SmartArray<T>;
  60. /**
  61. * Test if the octree intersect with the given bounding sphere and if yes, then add its content to the selection array
  62. * @param sphereCenter defines the bounding sphere center
  63. * @param sphereRadius defines the bounding sphere radius
  64. * @param allowDuplicate defines if the selection array can contains duplicated entries
  65. * @returns an array of objects that intersect the sphere
  66. */
  67. intersects(sphereCenter: Vector3, sphereRadius: number, allowDuplicate?: boolean): SmartArray<T>;
  68. /**
  69. * Test if the octree intersect with the given ray and if yes, then add its content to resulting array
  70. * @param ray defines the ray to test with
  71. * @returns array of intersected objects
  72. */
  73. intersectsRay(ray: Ray): SmartArray<T>;
  74. /**
  75. * Adds a mesh into the octree block if it intersects the block
  76. * @param entry defines the mesh to try to add to the block
  77. * @param block defines the block where the mesh should be added
  78. */
  79. static CreationFuncForMeshes: (entry: AbstractMesh, block: OctreeBlock<AbstractMesh>) => void;
  80. /**
  81. * Adds a submesh into the octree block if it intersects the block
  82. * @param entry defines the submesh to try to add to the block
  83. * @param block defines the block where the submesh should be added
  84. */
  85. static CreationFuncForSubMeshes: (entry: SubMesh, block: OctreeBlock<SubMesh>) => void;
  86. }