14#include <unordered_set>
91 kOctree(
int maxDepth = 6,
int maxObjectsPerNode = 8);
131 void traverse(
const std::function<
void(
const kAABB &,
int,
bool)> &visitor)
const;
143 std::vector<kMesh*> meshes;
144 std::unique_ptr<Node> children[8];
158 void insert(
kMesh *mesh,
const kAABB &meshBounds,
int depth,
159 int maxDepth,
int maxObj);
165 void collectAll(std::vector<kMesh*> &out)
const;
172 void query(
const kFrustum &frustum, std::vector<kMesh*> &out)
const;
179 void traverse(
const std::function<
void(
const kAABB &,
int,
bool)> &visitor,
183 int nodeCount()
const;
186 std::unique_ptr<Node> root;
188 int maxObjectsPerNode;
196 static void collectMeshes(
kObject *node, std::vector<kMesh*> &out);
View frustum defined by six planes extracted from a view-projection matrix.
Definition koctree.h:41
bool intersectsAABB(const kAABB &aabb) const
Quick reject: returns false if the AABB is fully outside.
void extractFromMatrix(const kMat4 &viewProjection)
Extract the six frustum planes from a combined view-projection matrix.
kFrustumTestResult testAABB(const kAABB &aabb) const
Test an AABB against the frustum.
Scene-graph node that holds renderable geometry.
Definition kmesh.h:35
Base scene-graph node.
Definition kobject.h:43
~kOctree()
Destroy the octree and release all nodes.
int getMeshCount() const
Get the total number of meshes indexed by the tree.
Definition koctree.h:121
kOctree(int maxDepth=6, int maxObjectsPerNode=8)
Construct an empty octree with the given subdivision limits.
std::vector< kMesh * > queryVisible(const kFrustum &frustum) const
Return all meshes whose world AABB intersects the frustum.
void clear()
Discard all nodes and mesh references.
void traverse(const std::function< void(const kAABB &, int, bool)> &visitor) const
Visit every node in the tree top-down.
void build(kScene *scene)
Rebuild the tree from all loaded meshes in the scene.
int getNodeCount() const
Get the total number of nodes currently in the tree.
Holds all objects, lights, and rendering settings for one scene.
Definition kscene.h:36
Core type aliases, enumerations, structs, and utility functions used throughout the engine.
Symbol visibility / linkage macro for the Kemena3D library.
#define KEMENA3D_API
Definition kexport.h:35
Top-level Kemena3D engine namespace.
Definition kanimation.h:23
glm::vec4 kVec4
4-component float vector.
Definition kdatatype.h:34
glm::mat4 kMat4
4x4 float matrix.
Definition kdatatype.h:39
kFrustumTestResult
Result of testing a volume against a view frustum.
Definition koctree.h:29
@ Outside
Volume lies entirely outside the frustum.
Definition koctree.h:30
@ Inside
Volume lies entirely inside all six planes.
Definition koctree.h:32
@ Intersecting
Volume straddles one or more frustum planes.
Definition koctree.h:31
Axis-aligned bounding box (min/max in the same space).
Definition kdatatype.h:572