Skip to content

Yannick Ruijter

C/C++ Embedded Systems & Algorithms

Dynamic Octree Generation

The Project

A research project on 3D spatial partitioning using octrees, built in Unity/C#. The goal was to understand and implement octrees from the ground up. Starting from a tutorial-based static tree and extending it into a fully dynamic structure that can insert and remove objects at runtime, with automatic node collapsing and tree shrinking to keep memory use efficient. The project also lays the groundwork for A* pathfinding across the octree’s empty leaf nodes, treating them as a navigable graph for 3D movement.

Technical Highlights

  • Dynamic Insertion: objects can be added at runtime without rebuilding the tree. The octree finds the smallest node that fully contains the new object and subdivides only where needed, and expands outward (rather than reconstructing from scratch) when an object falls outside the current bounds.
  • Dynamic Removal: removing an object walks back up through every node it belonged to, clearing references as it goes.
  • Node Collapsing: once all children of a node become empty, they’re merged back into their parent automatically, keeping the tree from holding onto unnecessary subdivisions.
  • Tree Shrinking: if only one branch of the octree still contains objects, the root shrinks down to that branch instead of keeping a needlessly large bounding volume alive.
  • A* Groundwork: empty leaf nodes are collected and connected into a graph based on adjacency, forming the basis for pathfinding through 3D space.

More Info

For a far more detailed, step-by-step breakdown, including code snippets and demo clips of the tree adapting in real time, the GitHub repo is the way to go.