]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/model/modellib.cxx
pass SGReaderWriterXMLOptions to effects
[simgear.git] / simgear / scene / model / modellib.cxx
index dda15a92c5832cb7fccac67738118ad0ebac38e4..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>
@@ -26,6 +28,7 @@
 #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"
@@ -34,6 +37,8 @@
 
 #include "modellib.hxx"
 
+#include <simgear/math/SGMath.hxx>
+
 
 using namespace simgear;
 
@@ -57,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,
@@ -65,9 +89,7 @@ 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;
@@ -82,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*