]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/model/modellib.cxx
pass SGReaderWriterXMLOptions to effects
[simgear.git] / simgear / scene / model / modellib.cxx
index 5cb6965d08df3dac6e8179f2641f4308e9aadc17..4b457f5e48bc2aeece69d10e7e44acbfb07bd882 100644 (file)
@@ -19,6 +19,8 @@
 #  include <simgear_config.h>
 #endif
 
+#include <boost/algorithm/string.hpp>
+
 #include <osgDB/ReadFile>
 #include <osgDB/WriteFile>
 #include <osgDB/Registry>
 #include <simgear/constants.h>
 #include <simgear/props/props.hxx>
 #include <simgear/props/props_io.hxx>
+#include <simgear/scene/model/model.hxx>
 #include <simgear/scene/model/ModelRegistry.hxx>
 
 #include "SGPagedLOD.hxx"
 #include "SGReaderWriterXML.hxx"
 #include "SGReaderWriterXMLOptions.hxx"
 
-//#include "model.hxx"
 #include "modellib.hxx"
 
+#include <simgear/math/SGMath.hxx>
+
 
 using namespace simgear;
 
@@ -58,6 +62,25 @@ SGModelLib::~SGModelLib()
 {
 }
 
+namespace
+{
+osg::Node* loadFile(const string& path, osgDB::ReaderWriter::Options* options)
+{
+    using namespace osg;
+    using namespace osgDB;
+    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());
+    }
+     return model.release();
+}
+}
+
 osg::Node*
 SGModelLib::loadModel(const string &path,
                        SGPropertyNode *prop_root,
@@ -66,9 +89,9 @@ SGModelLib::loadModel(const string &path,
     osg::ref_ptr<SGReaderWriterXMLOptions> opt = new SGReaderWriterXMLOptions(*(osgDB::Registry::instance()->getOptions()));
     opt->setPropRoot(prop_root);
     opt->setModelData(data);
-    osg::Node *n = readNodeFile(path, opt.get());
-    if(data)
-        data->modelLoaded(path, data->getProperties(), n);
+    osg::Node *n = loadFile(path, opt.get());
+    if (n && n->getName().empty())
+        n->setName("Direct loaded model \"" + path + "\"");
     return n;
 
 }
@@ -81,7 +104,7 @@ SGModelLib::loadModel(const string &path,
     osg::ref_ptr<SGReaderWriterXMLOptions> opt = new SGReaderWriterXMLOptions(*(osgDB::Registry::instance()->getOptions()));
     opt->setPropRoot(prop_root);
     opt->setLoadPanel(pf);
-    return readNodeFile(path, opt.get());
+    return loadFile(path, opt.get());
 }
 
 osg::Node*
@@ -90,6 +113,7 @@ SGModelLib::loadPagedModel(const string &path,
                            SGModelData *data)
 {
     SGPagedLOD *plod = new SGPagedLOD;
+    plod->setName("Paged LOD for \"" + path + "\"");
     plod->setFileName(0, path);
     plod->setRange(0, 0.0, 50.0*SG_NM_TO_METER);