Please refer to the following documentation for this question: BabylonJS JSON File Format
In a "vertexData" node, vertices, normal vectors, and uv's are declared for construction of 3D objects. See the following "geometry" node as in the example .babylon file at the bottom of the documentation page linked.
"geometries": {
"boxes": [{
"id": "BoxPrimitive",
"size": 2,
"canBeRegenerated": true,
"tags": "Box Primitive Cube CanBeRegenerated"
}],
"vertexData": [{
"id": "CubeGeometry",
"updatable": false,
"positions": [ 1, -1, 1, 1, -1, -1, -1, -1, 1, 1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, 1, 1, -1, -1, 1, -1, -1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, 1, -1, -1, -1, 1, 1, 1, 1, 1, -1, 1, -1, 1, 1, -1, -1, -1, -1, 1, -1, 1, 1, 1, 1, 1, -1, 1, -1, -1, 1, 1, -1, -1, 1, -1, -1, 1, 1, -1, -1, 1, 1, -1, 1, -1, -1, 1, -1, 1, 1],
"normals": [0.5773, -0.5773, 0.5773, 0.5773, -0.5773, -0.5773, -0.5773, -0.5773, 0.5773, 0.5773, 0.5773, 0.5773, -0.5773, 0.5773, 0.5773, 0.5773, 0.5773, -0.5773, 0.5773, 0.5773, 0.5773, 0.5773, -0.5773, -0.5773, 0.5773, -0.5773, -0.5773, 0.5773, 0.5773, -0.5773, -0.5773, -0.5773, -0.5773, -0.5773, -0.5773, -0.5773, -0.5773, 0.5773, -0.5773, -0.5773, -0.5773, 0.5773, 0.5773, 0.5773, 0.5773, 0.5773, -0.5773, 0.5773, -0.5773, 0.5773, 0.5773, -0.5773, -0.5773, -0.5773, -0.5773, 0.5773, -0.5773, 0.5773, 0.5773, 0.5773, 0.5773, 0.5773, -0.5773, 0.5773, -0.5773, -0.5773, 0.5773, 0.5773, -0.5773, -0.5773, 0.5773, -0.5773, -0.5773, 0.5773, 0.5773, -0.5773, -0.5773, 0.5773, 0.5773, -0.5773, 0.5773, -0.5773, -0.5773, 0.5773, -0.5773, 0.5773, 0.5773],
"uvs": [0.5, 0.5, 0.5, 0, 0, 0.5, 0.5, 1, 0, 1, 0.5, 0.5, 0.5, 1, 0, 0.5, 0.5, 0.5, 0.5, 1, 0, 0.5, 0.5, 0.5, 0.5, 1, 1, 0.5, 0.5, 0.5, 0.5, 0, 0, 0.5, 0, 0, 0, 0.5, 0.5, 1, 0, 1, 0, 0.5, 0.5, 1, 0, 1, 1, 1, 1, 0.5, 0.5, 0, 0, 0, 0, 0.5],
"indices": [0, 1, 2, 3, 4, 5, 0, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 1, 17, 2, 4, 18, 5, 19, 20, 21, 22, 23, 10, 12, 24, 25, 26, 27, 28]
}]
}
In this object, there are 29 (often redundant) vertices, declared as groups of 3 floats in "positions", that are then arranged by "indices" which are groups of three integers that represent triangles drawn by connecting the referenced "position" vertex.
Each "position" vertex has a normal vector declared that is simply the position vector standardized to a unit vector. What is the purpose of this? Why is it included? And can 3D models be generated without it?
Additionally, what are "uv's". Each vertex has a pair of 2 uv's. What do these mean?
UV
fields are called Texture Coordinates
and they tell which part of the texture you want to use on your mesh.
U
and V
values are like X
and Y
positions in your 2D image. In fact they were called U/V
instead of X/Y
just to avoid misunderstandings but they represent the same kind of data. They are also normalized which means that 0
value is "beginning" and 1
means "end" (regardless of the resolution of your texture - so you can resize the texture without breaking your rendering).
When you're rendering a triangle you basically have 3 vertices and each of them has its own UV
values. If you mark those values as X/Y
in your 2D image you'll get a triangle using the same part of texture as your rendering will.
Here's another answer about this topic: https://stackoverflow.com/a/21909471/1479630