Skip to main content
Participant
March 10, 2015

Vertex order

Hello,

I have the vertices and index data for a model. But some of the faces do not get rendered. After experimenting for a while, i have found that the vertex order is causing the issue. To demonstrate the behavior, here is a small code snippet that i am trying with "OculusRoomTiny" sample. In this code, the vertices correspond to a plane with +Y as its normal and vertices are as shown.

2 3
x--------------x
|--------------|
|--------------|
x--------------x
0 1

If the indices of the two triangles are provided as 2,1,0 2,3,1 - it works.
If the indices of the two triangles are provided as 0,1,2,2,1,3 - it does not work.

But considering that the face has a normal of 0,1,0, I am expecting it to work with 0,1,2,2,1,3 as the indices.

Any suggestion on how the vertex order is determined ?

Here is the code snippet that can be included in "OculusRoomTiny" sample for testing. I haven't done any other change to the sample other than stopping the model[0] from getting moved so that i can see the plane.


void Model::AddCustomSolid( Color c)
{
Vector3f Vert[][2] =
{
// y = 1 Top face with normal 0,1,0
Vector3f(1.0, 1.0, 1.0), Vector3f(1.0, 1.0),
Vector3f(1.0, 1.0, 0.0), Vector3f(1.0, 0.0),
Vector3f(0.0, 1.0, 1.0), Vector3f(0.0, 1.0),
Vector3f(0.0, 1.0, 0.0), Vector3f(0.0, 0.0),
};

int numOfIndices = 6;
int numOfVertices = 4;

// Works
uint16_t CubeIndices[] =
{
2, 1, 0,
2, 3, 1,
};
//*/

//// Does not work
//uint16_t CubeIndices[] =
//{
// 0, 1, 2,
// 2, 1, 3,
//};

for(int i = 0; i < numOfIndices; i++)
AddIndex(CubeIndices[i] + (uint16_t) numVertices);

for(int v = 0; v < numOfVertices; v++)
{
Vertex vvv;

vvv.Pos = Vert[v][0];
vvv.U = Vert[v][1].x;
vvv.V = Vert[v][1].y;
vvv.C = c;

AddVertex(vvv);
}
}


Thank you

Regards,
Ram

    4 replies

    Inspiring
    March 10, 2015
    What is it you are trying to accomplish?
    AMD Ryzen 7 1800X | MSI X370 Titanium | G.Skill 16GB DDR4 3200 | EVGA SuperNOVA 1000 | Corsair Hydro H110i Gigabyte RX Vega 64 x2 | Samsung 960 Evo M.2 500GB | Seagate FireCuda SSHD 2TB | Phanteks ENTHOO EVOLV
    Up and Coming
    March 10, 2015
    Vertex stitching order is anticlockwise around the surface normal in most engines.
    Some 3d tools have it clockwise when physically stitching with a mouse.

    Your code disagrees with your post, code implies vertex arranged like:


    // y = 1 Top face with normal 0,1,0
    Vector3f(1.0, 1.0, 1.0), Vector3f(1.0, 1.0),
    Vector3f(1.0, 1.0, 0.0), Vector3f(1.0, 0.0),
    Vector3f(0.0, 1.0, 1.0), Vector3f(0.0, 1.0),
    Vector3f(0.0, 1.0, 0.0), Vector3f(0.0, 0.0),

    VERTEX VIEWED FROM ABOVE
    [2].....[0]
    : :
    : :
    : :
    [3].....[1]


    So just stitch two anticlockwise triangles.
    Android VR Developer. https://twitter.com/SiliconDroid
    Up and Coming
    March 10, 2015
    "cybereality" wrote:
    What is it you are trying to accomplish?


    I'll bet a voxel engine...
    Android VR Developer. https://twitter.com/SiliconDroid
    BalajiRamAuthor
    Participant
    March 11, 2015
    Thank you g4c and cybereality !

    As you rightly mentioned, I was not considering the coordinate system while viewing the plane along its normal. Now i understand it.

    I am working on viewing a CAD model (mostly machine parts) using Oculus Rift DK2 and using its Direct HMD access.

    Regards,
    Ram