How to compute bounding sphere (center and radius) of GLTF ModelNode

Hello,

I am working a GLTF model using CesiumJS. I am able to query various ModelNode from the loaded GTLF model.

Next, I would like to compute the bounding box or bounding sphere of few ModelNode in world coordinate system. Is there any example which I can refer to.

Thanks,
Sourabh

I am wondering if someone have any clue. Thanks in advance.

@sourabh
You can get center using given code:-
tileset.boundingSphere.center

Hi there,

The bounding sphere for a node would be computed from the node’s transform. This should be available via the ModelNode.matrix property, then you will need to multiply by the top-level model matrix.

The center of the bounding sphere would be the translate component of the matrix * the scaling component of the matrix, and the radius would be the scaling component of the matrix.

Hi Gabby,
I’m calculating the center and radius as you suggested. However, it appears that the latitude and longitude values are correct, but the height value is being calculated incorrectly. As a result, the red sphere I’m trying to display at the center position does not appear to be in the correct location. Could you please let me know what might be causing this issue?

Here’s a Sandcastle example: Cesium Sandcastle

Hi there,

You will need to include the transforms of any parent nodes in the scene graph as well.