c++openglopenscenegraph

OpenSceneGraph: analysing a scenegraph


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;
}

Solution

  • 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.