Hi,
I have a scene that might contain multiple children / meshes. How can I get the pivot point and center of the scene? Currently I’m using getWorldExtends()
which returns the min
and max
of the scene world but I need more data from the inner BoundingInfo
like the centerWorld
and more data about the meshes in relative to the world like the pivot point but the total pivot.
I’ve created a box with the vector the scene.getWorldExtends()
has returened but it’s not positioned correctly:
This is how:
getBoundingBoxByObject(scene) {
let minmax = scene.getWorldExtends();
return {
x: Math.abs(minmax.max.x - minmax.min.x),
y: Math.abs(minmax.max.y - minmax.min.y),
z: Math.abs(minmax.max.z - minmax.min.z)
};
}
addBoundingBix() {
const vector = this.getBoundingBoxByObject(this.scene);
const box = BABYLON.MeshBuilder.CreateBox('box', {
width: vector.x,
height: vector.y,
length: vector.z
}, this.scene);
}
I need this box to be in the same place as the model. I’ve tried to do this:
box.position.y = minmax.max.y / 2;
And it looks good but axis x
and z
aren’t aligned with the model when applying the same logic.
Thanks.