[SOLVED] Calculate bounding box of a model

Hello,

I am trying to find the (bounding) size of a model with pc.
Is there something like: this.entity.model.size.x?

Thank you.

There isn’t an API function to do this, no. However, this should work:

var meshInstances = this.entity.model.meshInstances;
if (meshInstances.length > 0) {
    var bbox = new pc.BoundingBox();
    bbox.copy(meshInstances[0].aabb);
    for (var i = 1; i < meshInstances.length; i++) {
        bbox.add(meshInstances[i].aabb);
    }
}

The docs for pc.BoundingBox are here.

2 Likes

Thank you very much! It works perfectly.

1 Like