Trouble getting the true bounds of a nested scene graph

While working with giant maps (Rotating world map data into flat plane) I have a 3 deep set of Transform nodes wrapping a set of meshes. I need to know the exact bounds of the meshes contents so I can “wrap” all the map tiles with a border object (think 3d version of a 9-slice image).

Tried to do it with https://www.babylonjs-playground.com/#9JG4AA#1 but the bounds is too large. Sure this has to do with the rotation and scaling. But I need the water tight bounds.

Tried

    let xformMin = mapMax;
    let xformMax = mapMin;

    mapMeshes.forEach((m, i) => {
      const mat4 = m
        .computeWorldMatrix(true)
        .clone()
        .invert();
      const bb = m.getBoundingInfo().boundingBox;

      const newMin = Vector3.TransformCoordinates(bb.minimumWorld, mat4);
      xformMin.minimizeInPlace(newMin);
      const newMax = Vector3.TransformCoordinates(bb.maximumWorld, mat4);
      xformMax.maximizeInPlace(newMax);

      console.log(i, newMax.subtract(newMin));
    });
    console.log(xformMin, xformMax, xformMax.subtract(xformMin));

With similar results.

The meshes are a combination of Mesh and InstanceMesh. Is there a way to “bake” down a set of transform of the verts on a hierarchy and get the accurate bounds?

Maybe you want to use transformNode.getHierarchyBoundingVectors() ?

Yep tried that too, why I include the playground example :stuck_out_tongue: https://www.babylonjs-playground.com/#9JG4AA#1

oh sorry I misread :frowning:

Then I’m not sure what you call “accurate” bounds? This ones are pretty accurate but they are axis aligned. Maybe you want object bounding boxes?