什么是webgl中的VertexIndices? [英] What are VertexIndices in webgl?

查看:819
本文介绍了什么是webgl中的VertexIndices?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从这个网站学习WebGL: http://learningwebgl.com/blog/?p = 370

I'm learning WebGL from this site: http://learningwebgl.com/blog/?p=370

我不明白,什么是VertexIndices,为什么金字塔没有它们?

I don't understand, what are VertexIndices, and why the pyramid dont have them?

推荐答案

定义3D对象的几何体时,您使用的是两个基本元素:顶点和三角形。顶点只是由XYZ坐标定义的空间中的位置(通常是一些附加信息,如纹理坐标),三角形只是三个顶点。

When defining the geometry for your 3D object, there's two basic elements that you are working with: Vertices and Triangles. 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.

定义顶点是非常简单。您通常只提供如下位置列表:

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.

这是否清楚了?

这篇关于什么是webgl中的VertexIndices?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆