]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/model/modellib.cxx
Work around apparent OSG 3.2.0 normal binding bug.
[simgear.git] / simgear / scene / model / modellib.cxx
index 413d1734f120a06b900dfd42035156de12dd9f22..8a55151090905f6eab95996d73406eed93c3da69 100644 (file)
 #include <simgear/props/props_io.hxx>
 #include <simgear/scene/model/model.hxx>
 #include <simgear/scene/model/ModelRegistry.hxx>
+#include <simgear/scene/util/SGReaderWriterOptions.hxx>
 #include <simgear/misc/ResourceManager.hxx>
 
 #include "SGReaderWriterXML.hxx"
-#include "SGReaderWriterXMLOptions.hxx"
 
 #include "modellib.hxx"
 
-#include <simgear/math/SGMath.hxx>
-
 using std::string;
 using namespace simgear;
 
@@ -59,20 +57,27 @@ void SGModelLib::init(const string &root_dir, SGPropertyNode* root)
     static_propRoot = root;
 }
 
+void SGModelLib::resetPropertyRoot()
+{
+    static_propRoot.clear();
+}
+
 void SGModelLib::setPanelFunc(panel_func pf)
 {
   static_panelFunc = pf;
 }
 
 std::string SGModelLib::findDataFile(const std::string& file, 
-  const osgDB::ReaderWriter::Options* opts,
+  const osgDB::Options* opts,
   SGPath currentPath)
 {
+  if (file.empty())
+    return file;
   SGPath p = ResourceManager::instance()->findPath(file, currentPath);
   if (p.exists()) {
     return p.str();
   }
-      
+
   // finally hand on to standard OSG behaviour
   return osgDB::findDataFile(file, opts);
 }
@@ -87,7 +92,7 @@ SGModelLib::~SGModelLib()
 
 namespace
 {
-osg::Node* loadFile(const string& path, SGReaderWriterXMLOptions* options)
+osg::Node* loadFile(const string& path, SGReaderWriterOptions* options)
 {
     using namespace osg;
     using namespace osgDB;
@@ -107,8 +112,9 @@ SGModelLib::loadModel(const string &path,
                        SGModelData *data,
                        bool load2DPanels)
 {
-    osg::ref_ptr<SGReaderWriterXMLOptions> opt = new SGReaderWriterXMLOptions(*(osgDB::Registry::instance()->getOptions()));
-    opt->setPropRoot(prop_root ? prop_root: static_propRoot.get());
+    osg::ref_ptr<SGReaderWriterOptions> opt;
+    opt = SGReaderWriterOptions::copyOrCreate(osgDB::Registry::instance()->getOptions());
+    opt->setPropertyNode(prop_root ? prop_root: static_propRoot.get());
     opt->setModelData(data);
     
     if (load2DPanels) {
@@ -123,25 +129,24 @@ SGModelLib::loadModel(const string &path,
 }
 
 osg::Node*
-SGModelLib::loadDeferedModel(const string &path, SGPropertyNode *prop_root,
+SGModelLib::loadDeferredModel(const string &path, SGPropertyNode *prop_root,
                              SGModelData *data)
 {
     osg::ProxyNode* proxyNode = new osg::ProxyNode;
     proxyNode->setLoadingExternalReferenceMode(osg::ProxyNode::DEFER_LOADING_TO_DATABASE_PAGER);
     proxyNode->setFileName(0, path);
 
-    osg::ref_ptr<SGReaderWriterXMLOptions> opt
-        = new SGReaderWriterXMLOptions(*(osgDB::Registry::instance()
-                                         ->getOptions()));
-    opt->setPropRoot(prop_root ? prop_root: static_propRoot.get());
+    osg::ref_ptr<SGReaderWriterOptions> opt;
+    opt = SGReaderWriterOptions::copyOrCreate(osgDB::Registry::instance()->getOptions());
+    opt->setPropertyNode(prop_root ? prop_root: static_propRoot.get());
     opt->setModelData(data);
     opt->setLoadPanel(static_panelFunc);
     if (SGPath(path).lower_extension() == "ac")
         opt->setInstantiateEffects(true);
     if (!prop_root || prop_root->getBoolValue("/sim/rendering/cache", true))
-        opt->setObjectCacheHint(osgDB::ReaderWriter::Options::CACHE_ALL);
+        opt->setObjectCacheHint(osgDB::Options::CACHE_ALL);
     else
-        opt->setObjectCacheHint(osgDB::ReaderWriter::Options::CACHE_NONE);
+        opt->setObjectCacheHint(osgDB::Options::CACHE_NONE);
     proxyNode->setDatabaseOptions(opt.get());
 
     return proxyNode;
@@ -156,18 +161,17 @@ SGModelLib::loadPagedModel(const string &path, SGPropertyNode *prop_root,
     plod->setFileName(0, path);
     plod->setRange(0, 0.0, 50.0*SG_NM_TO_METER);
 
-    osg::ref_ptr<SGReaderWriterXMLOptions> opt
-        = new SGReaderWriterXMLOptions(*(osgDB::Registry::instance()
-                                         ->getOptions()));
-    opt->setPropRoot(prop_root ? prop_root: static_propRoot.get());
+    osg::ref_ptr<SGReaderWriterOptions> opt;
+    opt = SGReaderWriterOptions::copyOrCreate(osgDB::Registry::instance()->getOptions());
+    opt->setPropertyNode(prop_root ? prop_root: static_propRoot.get());
     opt->setModelData(data);
     opt->setLoadPanel(static_panelFunc);
     if (SGPath(path).lower_extension() == "ac")
         opt->setInstantiateEffects(true);
     if (!prop_root || prop_root->getBoolValue("/sim/rendering/cache", true))
-        opt->setObjectCacheHint(osgDB::ReaderWriter::Options::CACHE_ALL);
+        opt->setObjectCacheHint(osgDB::Options::CACHE_ALL);
     else
-        opt->setObjectCacheHint(osgDB::ReaderWriter::Options::CACHE_NONE);
+        opt->setObjectCacheHint(osgDB::Options::CACHE_NONE);
     plod->setDatabaseOptions(opt.get());
     return plod;
 }