karansher / computer-graphics-bounding-volume-hierarchy

Computer Graphics Assignment about Bounding Volume Hierarchies
0 stars 0 forks source link

AABBTree Splitting #7

Open AustinBlackman opened 1 year ago

AustinBlackman commented 1 year ago

Hi, I understand that the assignment says to utilize spatial splitting by determining the largest axis and using the midpoint of the axis to determine the children. However, using this method I seem to be experiencing some trouble. Currently I find the largest axis, find the midpoint, then check each object to see if its maximum point is larger than the midpoint. If the maximum point is larger, I add it to the list of objects that I will pass to the right child, and if it is smaller I pass it to the list for the left child. However with this method I keep experiencing stack overflow errors where a small amount of objects get repeatedly placed into the same side repeatedly. I have double checked my code for small errors and I cannot seem to find any, so it makes me believe that the method I am using for splitting is incorrect. Can anyone comment on my approach?

alekao commented 1 year ago

I had this error as well, here is how I eventually solved it: If an object is split by the midpoint (min <= midpoint <= max), then I add it to the side with fewer objects currently. Otherwise, the object just belongs to the side it is in.

Hope this works for you as well.

henrytwo commented 1 year ago

Are we supposed to split based on the min/max points of each bounding box, or would it be efficient to use the center() function?

alekao commented 1 year ago

When I used the center() function to determine side I still had the stack overflow issue.

philip-huang commented 1 year ago

So you have identified the issue here: all the triangles overlap with both subtree boxes, so you need to make a special case to prevent this from happening repeatedly. One way is to take the median of the object points and split them. There are other ways to solve this (for example the one metioned above), and any one of them is fine.