Kemena3D
Loading...
Searching...
No Matches
kemena::kOctree Class Reference

Loose octree that spatially indexes scene meshes for frustum culling. More...

#include <koctree.h>

Public Member Functions

 kOctree (int maxDepth=6, int maxObjectsPerNode=8)
 Construct an empty octree with the given subdivision limits.
 ~kOctree ()
 Destroy the octree and release all nodes.
void build (kScene *scene)
 Rebuild the tree from all loaded meshes in the scene.
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.
int getNodeCount () const
 Get the total number of nodes currently in the tree.
int getMeshCount () const
 Get the total number of meshes indexed by the tree.
void traverse (const std::function< void(const kAABB &, int, bool)> &visitor) const
 Visit every node in the tree top-down.

Detailed Description

Loose octree that spatially indexes scene meshes for frustum culling.

Usage per frame:

octree.build(scene); // rebuild from scene
kFrustum frustum;
frustum.extractFromMatrix(proj * view);
auto visible = octree.queryVisible(frustum); // cull
for (kMesh *m : visible) renderMesh(m);
View frustum defined by six planes extracted from a view-projection matrix.
Definition koctree.h:41
void extractFromMatrix(const kMat4 &viewProjection)
Extract the six frustum planes from a combined view-projection matrix.
Scene-graph node that holds renderable geometry.
Definition kmesh.h:35

Constructor & Destructor Documentation

◆ kOctree()

kemena::kOctree::kOctree ( int maxDepth = 6,
int maxObjectsPerNode = 8 )

Construct an empty octree with the given subdivision limits.

Parameters
maxDepthMaximum recursion depth (default 6).
maxObjectsPerNodeMeshes per leaf before subdivision (default 8).

◆ ~kOctree()

kemena::kOctree::~kOctree ( )

Destroy the octree and release all nodes.

Member Function Documentation

◆ build()

void kemena::kOctree::build ( kScene * scene)

Rebuild the tree from all loaded meshes in the scene.

Computes world-space AABBs, derives world bounds, then inserts every mesh into the appropriate octree node. Call once per frame (or whenever the scene changes).

◆ clear()

void kemena::kOctree::clear ( )

Discard all nodes and mesh references.

◆ getMeshCount()

int kemena::kOctree::getMeshCount ( ) const
inline

Get the total number of meshes indexed by the tree.

◆ getNodeCount()

int kemena::kOctree::getNodeCount ( ) const

Get the total number of nodes currently in the tree.

◆ queryVisible()

std::vector< kMesh * > kemena::kOctree::queryVisible ( const kFrustum & frustum) const

Return all meshes whose world AABB intersects the frustum.

Traverses the tree top-down; entire subtrees whose bounds are outside the frustum are skipped, and subtrees fully inside are collected without further plane tests.

◆ traverse()

void kemena::kOctree::traverse ( const std::function< void(const kAABB &, int, bool)> & visitor) const

Visit every node in the tree top-down.

The callback receives the node's world-space AABB, its depth (root = 0), and whether it is a leaf node. Useful for debug visualization.

Parameters
visitorCallable: void(const kAABB &bounds, int depth, bool isLeaf)
Here is the call graph for this function:
Here is the caller graph for this function:

The documentation for this class was generated from the following file: