GCubeSDK
©2026 FenixFox®Studios

Octree

Class representing a hierarchical tree data structure used to partition 3D space. An octree is a hierarchical tree data structure used to partition a three-dimensional space by recursively subdividing it into eight octants. Be careful when using the octree cause building it will use recursion which can fill up the memory. Make sure to use good balanced values for trianglesPerLeaf and maxLevel! Octree can be used in games to compute collision between the game world and colliders from the player or other dynamic 3D objects.

Methods

Octree(u32 trianglesPerLeaf, u32 maxLevel)

Constructor to create new octree

trianglesPerLeaf tris per subTree before split 8
maxLevel maximum depth of Octree 16

Octree& addTriangle(const Triangle& triangle)

Adds the given triangle to the Octree

triangle triangle to add

Octree& calcBox()

Prepares box for the build

Octree& split(u32 level)

Splits the Octree recursively when building

level current level

Octree& build()

Builds the Octree

Octree& clear()

Clears the Octree by making it empty

void getRayTriangles(const Ray& ray, vector<Triangle*>& triangles)

Computes the triangles that potentially intersect with the given ray

ray ray to test
triangles target array that holds the triangles

void getSphereTriangles(const Sphere& sphere, vector<Triangle*>& triangles)

Computes the triangles that potentially intersect with the given bounding sphere

sphere sphere to test
triangles target array that holds the triangles

void getBoxTriangles(const Box3& box, vector<Triangle*>& triangles)

Computes the triangles that potentially intersect with the given bounding box

box bounding box
triangles target array that holds the triangles

void getCapsuleTriangles(const Capsule& capsule, vector<Triangle*>& triangles)

Computes the triangles that potentially intersect with the given capsule

capsule capsule to test
triangles target array that holds the triangles

void* boxIntersect(const Box3& box)

Performs a bounding box intersection test with this Octree

box bounding box to test

void* sphereIntersect(const Sphere& sphere)

Performs a bounding sphere intersection test with this Octree

sphere bounding sphere to test

void* capsuleIntersect(const Capsule& capsule)

Performs a capsule intersection test with this Octree

capsule capsule to test

void* rayIntersect(const Ray& ray)

Performs a ray intersection test with this Octree

ray ray to test

void* triangleBoxIntersect(const Box3& box, const Triangle& triangle)

Computes the intersection between the given bounding box and triangle

box bounding box to test
triangle triangle to test

void* triangleCapsuleIntersect(const Capsule& capsule, const Triangle& triangle)

Computes the intersection between the given capsule and triangle

capsule capsule to test
triangle triangle to test

void* triangleSphereIntersect(const Sphere& sphere, const Triangle& triangle)

Computes the intersection between the given sphere and triangle

sphere sphere to test
triangle triangle to test

Octree& fromGraphNode(Object3D& group)

Constructs the Octree from the given 3D object

group scene graph node

const vector<Octree*>& getSubTrees() const

Gets the child octree nodes

Properties

bounds Box3 bounds of the Octree (no margin applied)
box Box3* base box that encloses the entire Octree
enabled bool Active/inactive
id u32 Unique identifier
isOctree bool Read-only tag
layers Layers* layers configuration for refine testing
maxLevel u32 maximum level of the Octree (16)
name string Optional display name
trianglesPerLeaf u32 number of triangles a leaf can store before split (8)
uuid string UUID string
version u32 Bumps on change