There are a couple of methods for defining geometries:
Non-Indexed
"vertices": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, ... ],
"normals": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, ... ]
In this mode, each triangle position is explicitly defined and data cannot be reused.
triangle 0: [ 0, 1, 2, 3, 4, 5, 6, 7, 8 ]
Indexed
"indices": [ 0, 1, 2, ... ],
"vertices": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, ... ],
"normals": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, ... ]
In this mode, indices determine the order of the data. The first triangle uses indices 0
, 1
, and 2
. These indices are used to access the corresponding vertices
and normals
data:
triangle 0: [ 0, 1, 2, 3, 4, 5, 6, 7, 8 ]
The primary advantage of indexed method is the ability to reuse data and reduce the amount of data sent to the GPU:
"indices": [ 0, 0, 0, ... ],
"vertices": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, ... ]
triangle 0: [ 0, 1, 2, 0, 1, 2, 0, 1, 2 ]
Regarding offsets...
Using offsets allows you to render specific ranges of your geometry. Instead of rendering from triangle 0
to triangle.length
, you can choose to render from triangle 200
to triangle 400
.