有两种定义几何的方法:
非索引
"vertices": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, ... ],
"normals": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, ... ]
在此模式下,每个三角形位置都是按照定义的,并且您不能重复使用数据。
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, ... ]
在此模式下,索引定义数据的顺序。第一个三角形使用索引0
, 1
, and 2
。这些索引将用于获取vertices
and normals
data:
triangle 0: [ 0, 1, 2, 3, 4, 5, 6, 7, 8 ]
索引的主要好处是可以重用数据并上传更少的数据到 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 ]
As per offsets...
通过偏移,您可以渲染几何体的特定范围。而不是从triangle 0
to triangle.length
,你可以从中得出triangle 200
to triangle 400
.