0

I am experimenting with building a bounding volume hierarchy using only immutable data-structures. I hope to use the tree for broad-phase collision tests in a real-time simulation.

The tree structure is like this:

type BvhTree<'t> =
  | Leaf of BvhLeaf<'t>
  | Branch of BvhBranch<'t>
  | Nil

and BvhLeaf<'t> =
  {
    Bounds : AABB
    Data : 't
  }

and BvhBranch<'t> =
  {
    Bounds : AABB option
    Left : BvhTree<'t>
    Right : BvhTree<'t>
  }

The goal then is to take a list of simulation objects, which all have bounding volumes (just AABBs for now to keep things simple), and produce a reasonably optimal bounding volume hierarchy.

The best tree is defined as the one whose branching nodes have the lowest surface area in total.

Testing every possible tree structure is too slow and simple appending creates a tree that is too lop-sided, giving poor collision test performance. It might also be possible to use the tree from previous simulation states as a starting point to compute the next tree.

Since I am using immutable data, I must build the tree from the bottom up, unlike the approach usually taken (see this excellent set of slides).

I have been unable to find many resources on the topic.

The basic approach I have come up with is to generate a list of trees, one for each simulation object and then recursively merge them until only only one tree remains. At each step the merge is chosen using simple heuristics.

What are some good techniques for doing this?

2
  • Why must you build it as immutable? Why not build as shown in the linked slides and then copy to immutable when optimized Commented Oct 18, 2020 at 9:47
  • @Blindman67 I am open to that approach if it is faster Commented Oct 18, 2020 at 9:50

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.