简体   繁体   English

什么是webgl中的VertexIndices?

[英]What are VertexIndices in webgl?

I'm learning WebGL from this site: http://learningwebgl.com/blog/?p=370 我正在从这个网站学习WebGL: http//learningwebgl.com/blog/?p = 370

I don't understand, what are VertexIndices, and why the pyramid dont have them? 我不明白,什么是VertexIndices,为什么金字塔没有它们?

When defining the geometry for your 3D object, there's two basic elements that you are working with: Vertices and Triangles. 定义3D对象的几何体时,您使用的是两个基本元素:顶点和三角形。 A vertex is just a position in space defined by XYZ coords, (and usually some additional information, like texture coordinates) and a triangle is just three vertices. 顶点只是由XYZ坐标定义的空间中的位置(通常是一些附加信息,如纹理坐标),三角形只是三个顶点。

Defining vertices is pretty straightforward. 定义顶点非常简单。 You typically just provide a list of positions like so: 您通常只提供如下位置列表:

[
    1.0, 2.0, 3.0, // vertex 0
    4.0, 5.0, 6.0, // vertex 1
    7.0, 8.0, 9.0, // vertex 2
    // etc..
]

So now the question is how do we make triangles out of that? 所以现在的问题是我们如何制作三角形呢? The most straighforward way is just to say that each set of three vertices is implicitly one triangle (so the array above would define a single triangle). 最直接的方法就是说每组三个顶点隐含一个三角形(因此上面的数组将定义一个三角形)。 This is easy because it doesn't require any additional information, you just provide vertices in threes and the hardware does the rest. 这很简单,因为它不需要任何额外的信息,你只需要提供三个顶点,硬件完成其余的工作。 This is known as Non-Indexed Geometry, and it's the method that the pyramid uses in the tutorial you linked to. 这称为非索引几何,它是金字塔在您链接的教程中使用的方法。

The problem is that in most models several triangles will all share the same vertex. 问题是在大多数模型中,几个三角形都将共享相同的顶点。 Think of the corner of a cube: There's at least three triangles that will all need to use that same point. 想想立方体的角落:至少有三个三角形都需要使用同一个点。 With non-indexed geometry you would need to just copy the information for that vertex in your array three times. 对于非索引几何,您只需要在数组中复制该顶点的信息三次。 This isn't terribly efficient, and for large complicated meshes you'll end up with a lot of redundant data. 这不是非常有效,对于大型复杂网格,您最终会得到大量冗余数据。 We can fix that by using Indexed Geometry. 我们可以通过使用索引几何来解决这个问题。

With indexed geometry you only define each vertex in your mesh once and then provide a second array of integers that index into your vertex array and basically "connects the dots" to tells your graphics card which points make up the triangles. 对于索引几何,您只需在网格中定义一个顶点,然后提供第二个整数数组,这些整数将索引到顶点数组中,基本上“连接点”以告诉您的图形卡构成三角形的哪些点。

[
    0, 1, 2, // Triangle 0, uses vertices 0, 1, and 2
    3, 2, 1, // Triangle 2, uses vertices 3, 2, and 1
    // etc...
]

This is a lot more efficient, saving memory and usually rendering faster too. 这样效率更高,节省内存并且通常渲染速度也更快。 This is the method that the cube uses in the tutorial. 这是多维数据集在教程中使用的方法。

Both methods work just fine, and both have scenarios in which they are the better choice, but usually you'll see most professional apps used Indexed Geometry because of the lower memory usage. 这两种方法都运行得很好,并且两种方法都有更好的选择,但通常您会看到大多数专业应用程序使用索引几何,因为内存使用率较低。

Does that clear things up at all? 这样清楚了吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM