I'm confused about how the Octree implementation works

If you look here, we can see that for each mesh you add, it adds the mesh to every OctreeBlock:

If you look at addEntry in OctreeBlock, it never actually pushes to the entries of the OctreeBlock. Instead, it calls the _creationFunc, which I guess is expected to push the entries

But, calling addMesh onto Octree recursively loops through every block

Wouldn’t it be really easy to get into a situation where the same Mesh | TransformNode is added to every OctreeBlock in the whole scene? And wouldn’t that negate the performance optimization?

Yes it is possible if you have a big mesh and if all other meshes are inside this big mesh: in that case, the big mesh intersects all the octree blocks so will be referenced by all the blocks.

Octrees are useful when you have a lot of meshes that intersect only a few blocks. (Very) big meshes don’t benefit much from an octree subdivision.

1 Like