Create VerticesData and Indices of Bounding Box without creating a mesh

Hello,

I have meshes I want to get the bounding box of, and then get VerticesData and IndicesData of said bounding box without actually having to create a helper mesh to fetch the info from, for performance reasons.

I am aware that there is boundingInfo.vectorsWorld data, but I’m not sure how I would be able to convert that into vertices data along with the according indices data.

Any help would be appreciated, thanks!
(Preferably a performant way to do this, as it’s going to be executed for every mesh in the scene at once)

So, you can do mesh.getBoundingInfo().boundingBox?

I am aware of that but I want to get Indices Data and Vertices Data for a bounding box of a mesh, without having to create a mesh to apply the bounding box data to.
My current way of doing it is like so:

let boundingInfo = mesh.getBoundingInfo().boundingBox;
var width = boundingInfo.maximum.x - boundingInfo.minimum.x;
var height = boundingInfo.maximum.y - boundingInfo.minimum.y;
var depth = boundingInfo.maximum.z - boundingInfo.minimum.z;
var newscale = new BABYLON.Vector3(width, height, depth);

var box = BABYLON.MeshBuilder.CreateBox("group", { size: 1 }, scene);
box.scaling = newscale.clone();
box.position = mesh.position.clone();

var vertData = object.getVerticesData(BABYLON.VertexBuffer.PositionKind);
var indicesData = object.getIndices();

but since this method creates a mesh it isn’t very performant, for my case, where i need to be doing this to every mesh in the scene at once.

You can create a mesh from scratch (so, no need to create a mesh box). See:

1 Like

Thank you for your help, though in my case, using this function achieved what I wanted in the end, in case anyone else is interested:

function getBoundingBoxVertData(mesh) {

  mesh.refreshBoundingInfo();

  let boundingInfo = mesh.getBoundingInfo().boundingBox;

  var min = boundingInfo.minimumWorld;
  var max = boundingInfo.maximumWorld;

  var vertices = [
    min.x, min.y, min.z,  // Vertex 0
    max.x, min.y, min.z,  // Vertex 1
    max.x, max.y, min.z,  // Vertex 2
    min.x, max.y, min.z,  // Vertex 3
    min.x, min.y, max.z,  // Vertex 4
    max.x, min.y, max.z,  // Vertex 5
    max.x, max.y, max.z,  // Vertex 6
    min.x, max.y, max.z   // Vertex 7
  ];

  var indices = [
    0, 1, 2,  // Face 1
    0, 2, 3,  // Face 2
    4, 6, 5,  // Face 3
    4, 7, 6,  // Face 4
    0, 5, 1,  // Face 5
    0, 4, 5,  // Face 6
    2, 6, 7,  // Face 7
    2, 7, 3,  // Face 8
    0, 3, 7,  // Face 9
    0, 7, 4,  // Face 10
    1, 5, 6,  // Face 11
    1, 6, 2   // Face 12
  ];


}