What is VertexIndices in webgl?

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

I do not understand what VertexIndices is and why the pyramid does not have them?

+3
source share
1 answer

When determining the geometry of your 3D object, there are two main elements that you work with: Vertices and Triangles. A vertex is simply a position in space defined by the XYZ coordinates (and usually some additional information, such as texture coordinates), and a triangle is just three vertices.

Defining vertices is pretty simple. Usually you just provide a list of these items:

[ 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 can we make triangles out of this? The easiest way is to simply say that each set of three vertices implicitly is one triangle (so the array above will define one triangle). This is easy, because it does not require additional information, you just provide tops in triples, and the equipment does the rest. This is called Non-Indexed Geometry, and it is the method that the pyramid uses in the tutorial you are attached to.

The problem is that in most models, multiple triangles will have the same vertex. Think about the corner of the cube: there are at least three triangles that everyone should use the same point. With non-indexed geometry, you just need to copy the information for this vertex in your array three times. This is not very efficient, and for large complex cells you will get a lot of redundant data. We can fix this with indexed geometry.

With indexed geometry, you define each vertex in your cell once, and then provide a second array of integers that are indexed into your vertex array and basically โ€œconnect the dotsโ€ to tell your graphics card that the dots are triangles.

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

It is much more efficient, saves memory and, as a rule, faster. This is the method that the cube uses in the tutorial.

Both methods work very well, and both have scenarios in which they are the best choice, but usually you will see that most professional applications use Indexed Geometry due to lower memory usage.

Is all this clear?

+9
source

Source: https://habr.com/ru/post/956730/


All Articles