- if the number of remaining shapes is less than or equal to the target group size
- add the shapes to this node's list
- create a bounding box for the group
- otherwise
- find the bounding box that contains the remaining shapes
- figure out on which axis (x, y, or z) the bounding box is longest
- sort the shapes on the longest axis
- split the list at the median
- create a left node containing the first half of the list
- create a right node containing the second half of the list
It's nothing fancy, and I haven't tried to find an optimal group size yet, but it works. And, like the title of this post implies, for certain scenes the render times are almost 28 times as fast. Not too shabby.
Tree traversal is pretty simple, too....