BufferGeometry偏移量和索引

时间:2014-05-30 06:47:43

标签: javascript three.js indices buffer-geometry

我只想知道一段时间究竟是什么“抵消”和“指数/指数”。偏移是例如在https://github.com/mrdoob/three.js/blob/dev/src/core/BufferGeometry.js中提到并且IndexedGeometry中提到了索引,但是我现在无法在开发树中找到它。 尽管指数似乎相当明显,虽然我可以深入研究代码,为自己找出一些可能正确的答案,但我很乐意听到“官方”陈述:)

谢谢!

1 个答案:

答案 0 :(得分:8)

定义几何有两种方法:

<强>非索引

"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 ]

<强>索引

"indices":  [ 0, 1, 2, ... ],
"vertices": [ 0, 1, 2,  3, 4, 5,  6, 7, 8,  ... ],
"normals":  [ 0, 1, 2,  3, 4, 5,  6, 7, 8,  ... ]

在此模式下,索引定义数据的顺序。第一个三角形使用索引012。这些索引将用于获取verticesnormals数据:

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 ]

根据抵消 ...

使用偏移,您可以渲染几何体的特定范围。您可以从triangle 0triangle.length进行绘制,而不是从triangle 200绘制到triangle 400

相关问题