Get boundbox size

    var sphere = BABYLON.MeshBuilder.CreateSphere("sphere", { diameter: 2, segments: 32 }, scene);
    sphere.showBoundingBox = true

    const boundingInfo = sphere.getBoundingInfo()
    const size = boundingInfo.boundingBox.extendSize
    console.log(boundingInfo.boundingBox)

    const { x, y, z } = size
    const box = BABYLON.MeshBuilder.CreateBox('text', { width: x, height: y, depth: z }, scene)

I want to create a box with the same size as the bound size
boundingBox.extendSize & boundingBox.extendSizeWorld, It seems that it does not allow me to accurately obtain the bound size.

I summed up the rule as follows: *2 based on the original size

    let sphereMin = sphere.getBoundingInfo().boundingBox.minimum;
    let sphereMax = sphere.getBoundingInfo().boundingBox.maximum;

    // this reports the "size" of the targeted object
    const size = sphereMax.subtract(sphereMin).length()

Example - https://playground.babylonjs.com/#4F33I3#397

2 Likes

extendSize is a vector that defines the amount of additional extension of the bounding box on each axis. Not the actual size, I suggest you use minimumWorld and maximumWorld to calculate the size

1 Like

My first answer was incorrect regarding the question.
Here is much more correct example - https://playground.babylonjs.com/#4F33I3#718

1 Like

Okay, I’m starting to understand a little bit

It seems that this method is also allowed,because of musk`s suggestion

// Our built-in 'sphere' shape.
    var sphere = BABYLON.MeshBuilder.CreateSphere("sphere", { diameter: 2, segments: 32 }, scene);
    let sphereMin = sphere.getBoundingInfo().boundingBox.minimumWorld;
    let sphereMax = sphere.getBoundingInfo().boundingBox.maximumWorld;

    // this reports the "size" of the targeted object
    // const size = sphereMax.subtract(sphereMin).length()
    const size = BABYLON.Vector3.Zero()
    size.x = sphereMax.x - sphereMin.x
    size.y = sphereMax.y - sphereMin.y
    size.z = sphereMax.z - sphereMin.z

    console.log(size)
1 Like

Updated my previous PG with https://playground.babylonjs.com/#4F33I3#724 to consider mesh scaling as well.

1 Like