X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fscene%2Fmaterial%2Fmatlib.cxx;h=5de7e01c75d9e227d8fb989370f7049a2b7e5272;hb=675c86582d8b25270897db0a36d0e02388f09bf4;hp=9c02cb96c2f18e062b64021585fe9ee9ccbac847;hpb=560c100484e3678770c9589e6067d627ec5554e5;p=simgear.git diff --git a/simgear/scene/material/matlib.cxx b/simgear/scene/material/matlib.cxx index 9c02cb96..5de7e01c 100644 --- a/simgear/scene/material/matlib.cxx +++ b/simgear/scene/material/matlib.cxx @@ -25,56 +25,38 @@ # include #endif -#ifdef SG_MATH_EXCEPTION_CLASH -# include -#endif - -#ifdef HAVE_WINDOWS_H -# include -#endif - #include #include #include -#include SG_GL_H - #include -#include STL_STRING - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include + +#include #include #include #include #include +#include #include #include "mat.hxx" +#include "Effect.hxx" +#include "Technique.hxx" #include "matlib.hxx" -SG_USING_NAMESPACE(std); -SG_USING_STD(string); +using std::string; // Constructor SGMaterialLib::SGMaterialLib ( void ) { } // Load a library of material properties -bool SGMaterialLib::load( const string &fg_root, const string& mpath, const char *season ) { - +bool SGMaterialLib::load( const string &fg_root, const string& mpath, + SGPropertyNode *prop_root ) +{ SGPropertyNode materials; SG_LOG( SG_INPUT, SG_INFO, "Reading materials from " << mpath ); @@ -85,12 +67,25 @@ bool SGMaterialLib::load( const string &fg_root, const string& mpath, const char << 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); + const SGPropertyNode *node = materials.getChild(i); if (!strcmp(node->getName(), "material")) { - SGSharedPtr m = new SGMaterial(fg_root, node, season); + const SGPropertyNode *conditionNode = node->getChild("condition"); + if (conditionNode) { + SGSharedPtr condition = sgReadCondition(prop_root, conditionNode); + if (!condition->test()) { + SG_LOG(SG_INPUT, SG_DEBUG, "Skipping material entry #" + << i << " (condition false)"); + continue; + } + } + + SGSharedPtr m = new SGMaterial(options.get(), node); vectornames = node->getChildren("name"); for ( unsigned int j = 0; j < names.size(); j++ ) { @@ -98,7 +93,7 @@ bool SGMaterialLib::load( const string &fg_root, const string& mpath, const char // 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 { @@ -110,48 +105,6 @@ bool SGMaterialLib::load( const string &fg_root, const string& mpath, const char return true; } - -// Load a library of material properties -bool SGMaterialLib::add_item ( const string &tex_path ) -{ - string material_name = tex_path; - int pos = tex_path.rfind( "/" ); - material_name = material_name.substr( pos + 1 ); - - return add_item( material_name, tex_path ); -} - - -// Load a library of material properties -bool SGMaterialLib::add_item ( const string &mat_name, const string &full_path ) -{ - int pos = full_path.rfind( "/" ); - string tex_name = full_path.substr( pos + 1 ); - string tex_path = full_path.substr( 0, pos ); - - SG_LOG( SG_TERRAIN, SG_INFO, " Loading material " - << mat_name << " (" << full_path << ")"); - - matlib[mat_name] = new SGMaterial( full_path ); - matlib[mat_name]->add_name(mat_name); - - return true; -} - - -// Load a library of material properties -bool SGMaterialLib::add_item ( const string &mat_name, osg::StateSet *state ) -{ - matlib[mat_name] = new SGMaterial( state ); - matlib[mat_name]->add_name(mat_name); - - SG_LOG( SG_TERRAIN, SG_INFO, " Loading material given a premade " - << "osg::StateSet = " << mat_name ); - - return true; -} - - // find a material record by material name SGMaterial *SGMaterialLib::find( const string& material ) { SGMaterial *result = NULL; @@ -164,39 +117,26 @@ SGMaterial *SGMaterialLib::find( const string& material ) { return NULL; } - // Destructor SGMaterialLib::~SGMaterialLib ( void ) { -} - - -// Load one pending "deferred" texture. Return true if a texture -// loaded successfully, false if no pending, or error. -void SGMaterialLib::load_next_deferred() { - // container::iterator it = begin(); - for ( material_map_iterator it = begin(); it != end(); it++ ) { - /* we don't need the key, but here's how we'd get it if we wanted it. */ - // const string &key = it->first; - SGMaterial *slot = it->second; - if (slot->load_texture()) - return; - } + SG_LOG( SG_GENERAL, SG_INFO, "SGMaterialLib::~SGMaterialLib() size=" << matlib.size()); } const SGMaterial* -SGMaterialLib::findMaterial(const osg::StateSet* stateSet) const +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(); }