Octree

Octree Data Structure

class Octree : public Spatial
{
public:
    struct Node
    {
        AABB box;
        std::vector<int> tris;
        std::shared_ptr<Node> child[8] = {nullptr};
    };

    std::shared_ptr<Node> root = nullptr;
    int maxDepth = 8;
    int maxPerNode = 16;
    
    ...
};

Insert Triangle

QueryAABB

It checks if the query AABB intersects with the current octree node.

If there is an intersection, it adds all triangles in the current node and recursively checks its children.

Raycast

Last updated