https://playcanvas.com/project/1257730/overview/boundingtest
const meshInstances = this.app.root.findByName('Model').model.meshInstances;
const bounding = new pc.BoundingBox();
meshInstances.forEach((meshInstance, index) => {
if (index === 0) {
bounding.copy(meshInstance.aabb);
} else {
bounding.add(meshInstance.aabb);
}
});
console.log("bounding", bounding);
// --- add a cube to match the bounding box
const cube = new pc.Entity();
cube.addComponent('render', {
type: 'box'
});
this.app.root.addChild(cube);
cube.setPosition(bounding.center);
cube.setLocalScale(bounding.halfExtents.mulScalar(2));
the above code doesn’t calculate bounding box correctly. Only position is correct but all other properties are 0, so it doesn’t show any bounding.
Hope to get help. Thanks