]> git.mxchange.org Git - simgear.git/commitdiff
force static models to have effects too
authorTim Moore <timoore33@gmail.com>
Fri, 2 Jul 2010 10:59:10 +0000 (12:59 +0200)
committerTim Moore <timoore33@gmail.com>
Fri, 13 Aug 2010 10:54:02 +0000 (12:54 +0200)
simgear/scene/model/ModelRegistry.cxx
simgear/scene/model/SGReaderWriterXMLOptions.hxx
simgear/scene/model/modellib.cxx

index 82f1a1c77dc3a12169ace8f1ba74e23aee0e5795..a4fb94c9fc2b6561ffca032da2e56fef961d3bd5 100644 (file)
@@ -55,6 +55,8 @@
 #include <simgear/props/condition.hxx>
 
 #include "BoundingVolumeBuildVisitor.hxx"
+#include "model.hxx"
+#include "SGReaderWriterXMLOptions.hxx"
 
 using namespace std;
 using namespace osg;
@@ -384,7 +386,7 @@ public:
 
 static SGReadCallbackInstaller readCallbackInstaller;
 
-// we get optimal geometry from the loader.
+// we get optimal geometry from the loader (Hah!).
 struct ACOptimizePolicy : public OptimizeModelPolicy {
     ACOptimizePolicy(const string& extension)  :
         OptimizeModelPolicy(extension)
@@ -408,6 +410,10 @@ struct ACOptimizePolicy : public OptimizeModelPolicy {
                 && group->getNumChildren() == 1)
                 optimized = static_cast<Node*>(group->getChild(0));
         }
+        const SGReaderWriterXMLOptions* sgopt
+            = dynamic_cast<const SGReaderWriterXMLOptions*>(opt);
+        if (sgopt && sgopt->getInstantiateEffects())
+            optimized = instantiateEffects(optimized.get(), sgopt);
         return optimized.release();
     }
 };
index cca34824d82cc7d57d249d69427246470a4cf180..674a55909d88dfadc961920843054f814eaf8e93 100644 (file)
@@ -34,30 +34,38 @@ public:
     typedef osg::Node *(*panel_func)(SGPropertyNode *);
 
     SGReaderWriterXMLOptions():
-            osgDB::ReaderWriter::Options(),
-            _prop_root(0),
-            _load_panel(0),
-            _model_data(0) {}
+        osgDB::ReaderWriter::Options(),
+        _prop_root(0),
+        _load_panel(0),
+        _model_data(0),
+        _instantiateEffects(false)
+    {}
 
     SGReaderWriterXMLOptions(const std::string& str):
-            osgDB::ReaderWriter::Options(str),
-            _prop_root(0),
-            _load_panel(0),
-            _model_data(0) {}
+        osgDB::ReaderWriter::Options(str),
+        _prop_root(0),
+        _load_panel(0),
+        _model_data(0),
+        _instantiateEffects(false)        
+    {}
 
     SGReaderWriterXMLOptions(const SGReaderWriterXMLOptions& options,
                              const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
-            osgDB::ReaderWriter::Options(options, copyop),
-            _prop_root(options._prop_root),
-            _load_panel(options._load_panel),
-            _model_data(options._model_data) {}
+        osgDB::ReaderWriter::Options(options, copyop),
+        _prop_root(options._prop_root),
+        _load_panel(options._load_panel),
+        _model_data(options._model_data),
+        _instantiateEffects(options._instantiateEffects)
+    {}
 
     SGReaderWriterXMLOptions(const osgDB::ReaderWriter::Options& options,
                              const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
-            osgDB::ReaderWriter::Options(options, copyop),
-            _prop_root(0),
-            _load_panel(0),
-            _model_data(0) {}
+        osgDB::ReaderWriter::Options(options, copyop),
+        _prop_root(0),
+        _load_panel(0),
+        _model_data(0),
+        _instantiateEffects(false)
+    {}
 
     SGPropertyNode *getPropRoot() const {
         return _prop_root;
@@ -68,6 +76,10 @@ public:
     SGModelData *getModelData() const {
         return _model_data.get();
     }
+    bool getInstantiateEffects() const
+    {
+        return _instantiateEffects;
+    }
 
     void setPropRoot(SGPropertyNode *p) {
         _prop_root=p;
@@ -78,13 +90,19 @@ public:
     void setModelData(SGModelData *d) {
         _model_data=d;
     }
-
+    void setInstantiateEffects(bool doit)
+    {
+        _instantiateEffects = doit;
+    }
+    
+    
 protected:
     virtual ~SGReaderWriterXMLOptions() {}
 
     SGPropertyNode_ptr _prop_root;
     osg::Node *(*_load_panel)(SGPropertyNode *);
     osg::ref_ptr<SGModelData> _model_data;
+    bool _instantiateEffects;
 };
 
 }
index 9e1acbe272397be243f448624610cccb92e5e546..b47c57fdfe6f136698f0cc347c48ea1d23cf5ddf 100644 (file)
@@ -95,19 +95,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();
 }
 }
@@ -130,8 +127,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 +135,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;
 }