2

I have an axis aligned bounding box for each mesh in a scene (multiple meshes in the scene), which I want to minimize the AABB's for all meshes by rotating the entire scene (this will be done in a precomputation step so the user will never feel this algorithm).

How do I find the rotation that will minimize the AABB across all meshes in a scene (I understand that it won't be the absolute minimum BB for each mesh, but overall it will be the smallest AABB's for a single scene axis)?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
yosmo78
  • 489
  • 4
  • 13
  • compute [OBB](https://stackoverflow.com/a/62284464/2521214) from your all of your AABBs and then simply [place and orient camera](https://stackoverflow.com/a/28084380/2521214) using OBB axises and position +/- some offset – Spektre May 25 '22 at 07:35
  • @Spektre I like your idea of using the OBB, but it probably still needs to combined for with the optimization technique because I have a dynamic camera (also this is for optimizing a BVH too) – yosmo78 May 25 '22 at 16:33

1 Answers1

1

First of all you can compute the convex hull of the meshes so to drastically reduce the number of computed points. Indeed, the minimal bounding box of the convex hull is guaranteed to be the same than the target mesh.

There are ways to compute the optimal volume for 1 mesh by computing the diameter of the point set of the convex hull but AFAIK this cannot be easily transposed to N meshes. The rotating calipers can be used to compute the diameter of a point set (the supporting parallel lines of the antipodal pair can be used to form the bounding box).

One simple way to address this problem is by using basic optimizations methods (AFAIK there is no exact algorithm to solve this in linear time nor any simple exact algorithm).

Here is an example of metric function to minimize (total volume):

function metric(α, β, θ)
    R_α <- RotationMatrixX(α)
    R_β <- RotationMatrixY(β)
    R_θ <- RotationMatrixZ(θ)
    R <- R_α * R_β * R_θ
    sum <- 0
    for each mesh M:
        K <- Points(PrecomputedConvexHull(M)) * R
        B <- BoundingBox(K)
        sum <- sum + volume(B)
    return sum

α, β and θ are the rotation angles of the X, Y and Z axis to optimize so to minimize the total volume. There are many optimization methods that can be used to minimize this metric function. For example, you can use the L-BFGS algorithm (it should be relatively good since the metric function should be "smooth").

Jérôme Richard
  • 41,678
  • 6
  • 29
  • 59
  • I think convex hull is overkill for this ... I would use OBB instead – Spektre May 25 '22 at 07:36
  • What do you mean by OBB? An Optimal Bonding Box algorithm? AFAIK, they are local to each mesh and the OP want all bounding box to be aligned to the same axis. Optimal solutions for each mesh does not give much information to compute the global optimal for the whole scene. – Jérôme Richard May 25 '22 at 10:31
  • I mean construct single OBB from all AABBs ... should be much much faster (using CUBE_MAP (with zoom) or just PCA) than construct convex hull from AABBs alone ... not to mention you need to optimize the orientation which is more or less the same complexity as finding OBB ... **OBB** means (Object) **Oriented Bounding Box** in context to **AABB** Axis Aligned Bounding Box I thought it was clear if not see my comment in main thread – Spektre May 25 '22 at 11:31
  • I think building a single OOB for the whole scene does not help to find "*the rotation that will minimize the AABB across all meshes*" since if meshes are far apart, then the OOB will be very impacted by this and the result will not be useful. Building an OOB for every mesh is not more useful since the global result cannot be computed from it. Using a PCA is a good idea but meshed need to be moved to the same location so to not to get a wrong result. I think It should be a quite good approximation though it does not consider outliers points. – Jérôme Richard May 25 '22 at 18:59
  • I agree that the proposed solution is expensive but I did not find something faster giving results at least as good as this method so far (while being reasonably simple). – Jérôme Richard May 25 '22 at 19:03