]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/model/modellib.cxx
Improved tile cache priority scheme.
[simgear.git] / simgear / scene / model / modellib.cxx
index b965ff3e95cabb5ecf3e600d7a23523a0564d522..ae90f1a46b6d6d4033c636fcacbbdec04c45adf7 100644 (file)
@@ -30,6 +30,7 @@
 #include <simgear/props/props_io.hxx>
 #include <simgear/scene/model/model.hxx>
 #include <simgear/scene/model/ModelRegistry.hxx>
+#include <simgear/misc/ResourceManager.hxx>
 
 #include "SGPagedLOD.hxx"
 #include "SGReaderWriterXML.hxx"
@@ -39,7 +40,7 @@
 
 #include <simgear/math/SGMath.hxx>
 
-
+using std::string;
 using namespace simgear;
 
 osgDB::RegisterReaderWriterProxy<SGReaderWriterXML> g_readerWriter_XML_Proxy;
@@ -47,7 +48,6 @@ ModelRegistryCallbackProxy<LoadOnlyCallback> g_xmlCallbackProxy("xml");
 
 \fSGPropertyNode_ptr SGModelLib::static_propRoot;
 SGModelLib::panel_func SGModelLib::static_panelFunc = NULL;
-SGModelLib::resolve_func SGModelLib::static_resolver = NULL;
 
 ////////////////////////////////////////////////////////////////////////
 // Implementation of SGModelLib.
@@ -67,21 +67,16 @@ void SGModelLib::setPanelFunc(panel_func pf)
   static_panelFunc = pf;
 }
 
-void SGModelLib::setResolveFunc(resolve_func rf)
-{
-  static_resolver = rf;
-}
-
 std::string SGModelLib::findDataFile(const std::string& file, 
-  const osgDB::ReaderWriter::Options* opts)
+  const osgDB::ReaderWriter::Options* opts,
+  SGPath currentPath)
 {
-  if (static_resolver) {
-    SGPath p = static_resolver(file);
-    if (p.exists()) {
-      return p.str();
-    }
+  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);
 }
 
@@ -95,19 +90,16 @@ SGModelLib::~SGModelLib()
 
 namespace
 {
-osg::Node* loadFile(const string& path, osgDB::ReaderWriter::Options* options)
+osg::Node* loadFile(const string& path, SGReaderWriterXMLOptions* options)
 {
     using namespace osg;
     using namespace osgDB;
+    if (boost::iends_with(path, ".ac"))
+        options->setInstantiateEffects(true);
     ref_ptr<Node> model = readRefNodeFile(path, options);
     if (!model)
         return 0;
-    if (boost::iends_with(path, ".ac")) {
-        ref_ptr<SGReaderWriterXMLOptions> sgOptions;
-        if (options)
-            sgOptions = new SGReaderWriterXMLOptions(*options);
-        model = instantiateEffects(model.get(), sgOptions.get());
-    }
+    else
      return model.release();
 }
 }
@@ -115,12 +107,16 @@ osg::Node* loadFile(const string& path, osgDB::ReaderWriter::Options* options)
 osg::Node*
 SGModelLib::loadModel(const string &path,
                        SGPropertyNode *prop_root,
-                       SGModelData *data)
+                       SGModelData *data,
+                       bool load2DPanels)
 {
     osg::ref_ptr<SGReaderWriterXMLOptions> opt = new SGReaderWriterXMLOptions(*(osgDB::Registry::instance()->getOptions()));
     opt->setPropRoot(prop_root ? prop_root: static_propRoot.get());
     opt->setModelData(data);
-    opt->setLoadPanel(static_panelFunc);
+    
+    if (load2DPanels) {
+       opt->setLoadPanel(static_panelFunc);
+    }
     
     osg::Node *n = loadFile(path, opt.get());
     if (n && n->getName().empty())
@@ -130,8 +126,7 @@ SGModelLib::loadModel(const string &path,
 }
 
 osg::Node*
-SGModelLib::loadPagedModel(const string &path,
-                           SGPropertyNode *prop_root,
+SGModelLib::loadPagedModel(const string &path, SGPropertyNode *prop_root,
                            SGModelData *data)
 {
     SGPagedLOD *plod = new SGPagedLOD;
@@ -139,11 +134,14 @@ SGModelLib::loadPagedModel(const string &path,
     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()));
+    osg::ref_ptr<SGReaderWriterXMLOptions> opt
+        = new SGReaderWriterXMLOptions(*(osgDB::Registry::instance()
+                                         ->getOptions()));
     opt->setPropRoot(prop_root ? prop_root: static_propRoot.get());
     opt->setModelData(data);
     opt->setLoadPanel(static_panelFunc);
-    
+    if (boost::iends_with(path, ".ac"))
+        opt->setInstantiateEffects(true);
     plod->setReaderWriterOptions(opt.get());
     return plod;
 }