Calculate the exact size of the model for the bounding box

Hi, I want to calculate the exact size of the model for the bounding box.No spaces would be required. What would be the possible way to do it. Need help :slight_smile:

Hi @HXA and welcome,

You can do that using the set/add methods the BoundingBox class provides. Basically loop through the mesh instances of model and append each aabb to get the total one.

The model viewer project template includes a similar method in the orbit-camera.js script, to find the total bounding box of the focused model and frame the camera accordingly.

I already did this but it create other near spaces as well of model.

Could you elaborate on what you mean with near spaces?

surrounding of model

An axis aligned bounding box will always create volumes that their sides are parallel to the world axis.

That means if your model isn’t box shaped or it’s rotated and not being parallel to the world axis then that is expected.

If you are looking to estimate the volume of a model and bounding boxes don’t fit it properly then you will need to find a different solution.

You will have most likely iterate through each model triangle and try to find the signed volume. Here is some helpful code from Unity that you could potentially translate to PlayCanvas:

Well thanks for the information. Is there a sample project related to this. It would be very helpful for me to understand in depth

No, not that I am aware of.

maybe post a screenshot if possible?

Our viewer uses this to calculate bounding box of meshes inside glb


Thanks for the help, here is the demo sample you can get the idea what type of issues I’m facing