Best practices for octree-optimized collision detection

You can do both, as shown in the doc you linked. The scene partition is used for mesh selection (ie. for frustum culling), and you can also create an octree at the mesh level to speed up mesh collision / picking.

You visualize the bounding box of the submeshes, not the blocks of the octree. Also, your code should be recursive. Here’s what I came up with:

It will depend on your meshes, I guess, and the trade-off between perf and memory.

For eg, in my PG above, I put a quite low level for capacity (8) so that the tree subdivides at lest 4 times.

Capacity=8, depth = 4:
image

Capacity=32, depth = 4:
image
Note that using depth=2 will produce the same result, because each block at level 1 contains less than 32 submeshes, so there’s no need to subdivide more.

If the tree is not subdivided enough, the system will hold more sub-meshes at each block, which means it will spend more time checking each sub-mesh for collision. If the tree is more subdivided, the system will spend more time traversing the tree, but since there will be fewer sub-meshes in each block, it will spend less time checking for collisions. The assumption here is that traversing the tree is much faster than checking for collisions.

1 Like