[osg-users] Getting texture coordinates of loaded models

Franclin Foping fsfoping at yahoo.fr
Thu Jul 31 05:10:13 PDT 2008

 I would like to retrieve the texture and normal coordinates of a loaded model. But not sure how to do it. My first attempt was to use a visitor to traverse the node, retrieve its Drawable objects, convert them to Geometry and finally extract texture coordinates but unfortunately, it doesn't work. 
 Here is a fully commented code snippet for your information.

  class myVisitor : public osg::NodeVisitor
     myVisitor() : osg::NodeVisitor(TRAVERSE_ALL_CHILDREN){ } 
    void apply(osg::Geode& geode)
          for (unsigned int i = 0; i < geode.getNumDrawables(); ++i)
            osg::Drawable* draw = geode.getDrawable(i);
    //At this level, everything is ok since the Draw pointer contains at least one valid Drawable objects. If I use a TriangleFunctor, it will return all triangles of that Drawable :) 
 // However I would like to get the texture coordinates as well. 
            const osg::Geometry* geometryd = dynamic_cast<const osg::Geometry*> (draw);
   // geometryd is dangling !!!
            if (geometryd)
            const osg::Array* tc = geometryd->getTexCoordArray(0);

  osg::Node* myNode = osgDB::readNodeFile("my3DModel.3ds");
 myVisitor visit;
  myNode->accept (visit);
 //Rest of the program irrelevant for this post. 
  Hopefully, I have clarified the matter further and can expect some help from you guys.
 Kinds regards,

 Envoyé avec Yahoo! Mail.
Une boite mail plus intelligente. 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20080731/7c047a55/attachment-0002.htm>

More information about the osg-users mailing list