Search code examples
javascriptthree.jsvertexverticesbuffer-geometry

What is the meaning of Three.js BufferGeometry vertex positions array elements order?


This is array of vertex positions taken from this three.js documenation:

var vertexPositions = [
    [-1.0, -1.0,  1.0],
    [ 1.0, -1.0,  1.0],
    [ 1.0,  1.0,  1.0],

    [ 1.0,  1.0,  1.0],
    [-1.0,  1.0,  1.0],
    [-1.0, -1.0,  1.0]
];

If I change elements (vertices) order in this array than resulting shape is changing. I would like to know why this elements are in that specific order because I want to create shapes programmatically. To do this I just have to know why order of vertices do matter. I have tried to figure this out myself but without success.


Solution

  • They're the verts defining two triangles necessary to construct a square.

    E.g.: enter image description here

    Image taken via quick google search. Although the diagonal runs the other direction in this case, from [-1,-1, 1] to [ 1, 1, 1].

    The Z component of the 3D verts just indicating where on the Z axis the square exists. Depending on the nature of the application, changing that value may not do anything visible.