0

I want to read a 3D Model through OSG and learn the 3D model information about vertices, normals and texture coordinates etc.

I do not understand the code below (complete tutorial from here ). why are we using prset->index(ic) as an index? I am confused. (* verts) is the vertex array but what is the prset->index(ic) ?

for (ic=0; ic<prset->getNumIndices(); ic++) { // NB the vertices are held in the drawable -
    osg::notify(osg::WARN) << "vertex "<< ic << " is index "<<prset->index(ic) << " at " <<
        (* verts)[prset->index(ic)].x() << "," <<
        (* verts)[prset->index(ic)].y() << "," << 
        (* verts)[prset->index(ic)].z() << std::endl;
}
Tuna
  • 113
  • 1
  • 11

1 Answers1

1

If your drawable uses indexed primitives, you need to de-reference the triangle vertices looking into the indices array, as you might re-use shared vertices of the vertex array. Something like this.

rickyviking
  • 846
  • 6
  • 17
  • Thanks for your answer but actually I dont know how to get indices array from a drawable or a geometry. Any idea for it ? – Tuna Mar 25 '21 at 13:29
  • The answer is in the code you posted: you get the ic-th index from the PrimitiveSet with `prset->index(ic)` and use such index to access the corresponding vertex in the vertex array – rickyviking Mar 25 '21 at 14:08
  • Oh thanks I just got it. I was using right indices but making some other mistake because of de-referencing. Now, I used like this for GL_TRIANGLES: 'tri.a=prset->index(i2)' , 'tri.b=prset->index(i2+1)' and 'tri.c=prset->index(i2+2)' – Tuna Mar 26 '21 at 07:19