How do indices work (under primitives)?

Hi,

In the mesh attribute I got a vector of positions and textures. But I can’t understand how to use indices to access the right value in my positions vector.
Can someone explain how it does work?

Assuming that the mesh primitive uses TRIANGLES ("mode": 4), then every three indices represent a triangle. So triangles A, B, and C would have indices of vertices:

a1,a2,a3,b1,b2,b3,c1,c2,c3

Where a1 is the index of a vertex in the primitive’s vertex attributes. This arrangement allows vertices to be reused by multiple triangles, reducing space and improving performance. When no indices are given, every three sequential vertices in the vertex attributes form a new triangle, and vertices cannot be reused. This is sometimes called “triangle soup.” :slight_smile:

Hardware APIs like OpenGL and Vulkan have these concepts built in; you don’t necessarily have to write code that looks up each triangle like that.

This tutorial might be helpful:

1 Like