]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/material/matlib.cxx
Stuart Buchanan: Fix a bug in the random object placement where the model selected...
[simgear.git] / simgear / scene / material / matlib.cxx
index 4f1357707479c24d555c6437ca5485329402194f..5de7e01c75d9e227d8fb989370f7049a2b7e5272 100644 (file)
 #  include <simgear_config.h>
 #endif
 
-#if defined ( __CYGWIN__ )
-#include <ieeefp.h>
-#endif
-
 #include <simgear/compiler.h>
 #include <simgear/constants.h>
 #include <simgear/structure/exception.hxx>
 #include <string.h>
 #include <string>
 
-#include <osg/AlphaFunc>
-#include <osg/BlendFunc>
-#include <osg/CullFace>
-#include <osg/Material>
-#include <osg/Point>
-#include <osg/PointSprite>
-#include <osg/PolygonMode>
-#include <osg/PolygonOffset>
-#include <osg/StateSet>
-#include <osg/TexEnv>
-#include <osg/TexGen>
-#include <osg/Texture2D>
+#include <osgDB/Registry>
 
 #include <simgear/debug/logstream.hxx>
 #include <simgear/misc/sg_path.hxx>
@@ -82,7 +67,10 @@ bool SGMaterialLib::load( const string &fg_root, const string& mpath,
                 << ex.getMessage() );
         throw;
     }
-
+    osg::ref_ptr<osgDB::ReaderWriter::Options> 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<SGMaterial> m = new SGMaterial(fg_root, node);
+            SGSharedPtr<SGMaterial> m = new SGMaterial(options.get(), node);
 
             vector<SGPropertyNode_ptr>names = 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,15 +123,20 @@ SGMaterialLib::~SGMaterialLib ( void ) {
 }
 
 const SGMaterial*
-SGMaterialLib::findMaterial(const simgear::Effect* effect)
+SGMaterialLib::findMaterial(const osg::Geode* geode)
 {
-  if (!effect)
-    return 0;
-
-  const SGMaterialUserData* matUserData
-    = dynamic_cast<const SGMaterialUserData*>(effect->getUserData());
-  if (!matUserData)
-    return 0;
-  else
-    return matUserData->getMaterial();
+    if (!geode)
+        return 0;
+    const simgear::EffectGeode* effectGeode;
+    effectGeode = dynamic_cast<const simgear::EffectGeode*>(geode);
+    if (!effectGeode)
+        return 0;
+    const simgear::Effect* effect = effectGeode->getEffect();
+    if (!effect)
+        return 0;
+    const SGMaterialUserData* userData;
+    userData = dynamic_cast<const SGMaterialUserData*>(effect->getUserData());
+    if (!userData)
+        return 0;
+    return userData->getMaterial();
 }