Is there a way when looking at the source of a glTF file that you can determine what the boundingBox values of the object are?
1 Answer
There isn't a bounding box for the whole glTF file, but individual primitives have POSITION
accessors that indicate min
and max
values. This is specified in the Meshes section, with the following text:
POSITION
accessor must havemin
andmax
properties defined.
For a concrete example of this, take a look at the Box sample model, which assigns accessor 2 as POSITION
"meshes": [
{
"primitives": [
{
"attributes": {
"NORMAL": 1,
"POSITION": 2
},
"indices": 0,
"mode": 4,
"material": 0
}
],
"name": "Mesh"
}
],
The accessor at index 2
(the third one in the list) looks like this:
"accessors": [
{ ... },
{ ... },
{
"bufferView": 1,
"byteOffset": 288,
"componentType": 5126,
"count": 24,
"max": [
0.5,
0.5,
0.5
],
"min": [
-0.5,
-0.5,
-0.5
],
"type": "VEC3"
}
In this accessor, min
and max
are arrays of x, y, z
raw position data of the primitive. This particular sample model is a unit cube, with values ranging from -0.5
to 0.5
along each axis.
To understand how this affects the whole model though, one must walk the tree of scene nodes, and look at how these mesh primitives are being transformed by the nodes. Also, if there are any animations or morph targets taking effect, they can influence the final positions of these meshes as well.