X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fscene%2Fmaterial%2Fmatlib.cxx;h=5de7e01c75d9e227d8fb989370f7049a2b7e5272;hb=5dfa4c0840b65377bba3224d24f2443d836e0782;hp=6f5d10bf40662332787fada77f71bacb07e158b2;hpb=c6b2124129e908d95ccfdf9d11a51cd257e55e55;p=simgear.git diff --git a/simgear/scene/material/matlib.cxx b/simgear/scene/material/matlib.cxx index 6f5d10bf..5de7e01c 100644 --- a/simgear/scene/material/matlib.cxx +++ b/simgear/scene/material/matlib.cxx @@ -25,10 +25,6 @@ # include #endif -#if defined ( __CYGWIN__ ) -#include -#endif - #include #include #include @@ -36,18 +32,7 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include #include #include @@ -82,7 +67,10 @@ bool SGMaterialLib::load( const string &fg_root, const string& mpath, << ex.getMessage() ); throw; } - + osg::ref_ptr options + = new osgDB::ReaderWriter::Options; + options->setObjectCacheHint(osgDB::ReaderWriter::Options::CACHE_ALL); + options->setDatabasePath(fg_root); int nMaterials = materials.nChildren(); for (int i = 0; i < nMaterials; i++) { const SGPropertyNode *node = materials.getChild(i); @@ -97,7 +85,7 @@ bool SGMaterialLib::load( const string &fg_root, const string& mpath, } } - SGSharedPtr m = new SGMaterial(fg_root, node); + SGSharedPtr m = new SGMaterial(options.get(), node); vectornames = node->getChildren("name"); for ( unsigned int j = 0; j < names.size(); j++ ) { @@ -105,7 +93,7 @@ bool SGMaterialLib::load( const string &fg_root, const string& mpath, // cerr << "Material " << name << endl; matlib[name] = m; m->add_name(name); - SG_LOG( SG_TERRAIN, SG_INFO, " Loading material " + SG_LOG( SG_TERRAIN, SG_DEBUG, " Loading material " << names[j]->getStringValue() ); } } else { @@ -135,19 +123,20 @@ SGMaterialLib::~SGMaterialLib ( void ) { } const SGMaterial* -SGMaterialLib::findMaterial(const osg::StateSet* stateSet) +SGMaterialLib::findMaterial(const osg::Geode* geode) { - if (!stateSet) - return 0; - - const osg::Referenced* base = stateSet->getUserData(); - if (!base) - return 0; - - const SGMaterialUserData* matUserData - = dynamic_cast(base); - if (!matUserData) - return 0; - - return matUserData->getMaterial(); + if (!geode) + return 0; + const simgear::EffectGeode* effectGeode; + effectGeode = dynamic_cast(geode); + if (!effectGeode) + return 0; + const simgear::Effect* effect = effectGeode->getEffect(); + if (!effect) + return 0; + const SGMaterialUserData* userData; + userData = dynamic_cast(effect->getUserData()); + if (!userData) + return 0; + return userData->getMaterial(); }