[osg-users] Billboarding 3D models loaded from a file
Paul Leopard
paul.leopard at gmail.com
Mon Mar 28 12:29:03 PDT 2016
Just for info ... I've used the following to gain access to drawables within a 3D model :
Code:
struct GeodeInfo
{
GeodeInfo() : m_drawable( 0 ) {}
std::string m_geodeName;
osg::Drawable* m_drawable;
}; // end struct GeodeInfo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
struct InfoVisitor : public osg::NodeVisitor
{
std::vector<GeodeInfo> m_infos;
InfoVisitor()
{
setTraversalMode( osg::NodeVisitor::TRAVERSE_ALL_CHILDREN );
}
void apply( osg::Geode& geode )
{
for ( unsigned int i=0; i<geode.getNumDrawables(); ++i )
{
GeodeInfo gInfo;
gInfo.m_geodeName = geode.getName();
gInfo.m_drawable = geode.getDrawable( i );
m_infos.push_back( gInfo );
}
}
}; // end struct InfoVisitor ~~~~~~~~~~~~~~~~~~~~~~~~
osg::ref_ptr<osg::Node> MakeTargetBB( const sgp_core::FileInfo& modelFile )
{
if ( !modelFile.exists() )
{
ostringstream ostr;
ostr << "OPM file does not exist : " << modelFile.filePath();
SGP_THROW_MESSAGE( ostr.str() );
}
string modelFileName = modelFile.absoluteFilePath();
osg::ref_ptr<osg::Node> rModelNode = osgDB::readNodeFile( modelFileName );
if ( rModelNode.get() == 0 )
{
ostringstream os;
os << "Failed loading target model : " << modelFile.filePath();
SGP_THROW_MESSAGE( os.str() );
}
InfoVisitor infVis;
rModelNode->accept( infVis );
if ( infVis.m_infos.size() > 0 )
{
std::vector<GeodeInfo>::const_iterator iItr = infVis.m_infos.begin();
cout << "Found drawable named : " << (*iItr).m_geodeName << endl;
}
return rModelNode;
} // end MakeTargetBB() ~~~~~~~~~~~~~~~~~~~
------------------------
things are more like they are now than they have ever been before
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=66644#66644
More information about the osg-users
mailing list