X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fscene%2Fmodel%2Fmodellib.cxx;h=efbcd1361b2fb7af5f32fb308cfb742c2a7b0349;hb=32a6bd78d8bf143f40922f1a0bc7a88ea7706a7d;hp=b431754795247e645ede551a929295bcd3990a83;hpb=6d05fc6f575040d42220ddf60f60889c16e35d52;p=simgear.git diff --git a/simgear/scene/model/modellib.cxx b/simgear/scene/model/modellib.cxx index b4317547..efbcd136 100644 --- a/simgear/scene/model/modellib.cxx +++ b/simgear/scene/model/modellib.cxx @@ -19,6 +19,10 @@ # include #endif +#include + +#include +#include #include #include #include @@ -26,27 +30,56 @@ #include #include #include +#include #include +#include +#include -#include "SGPagedLOD.hxx" #include "SGReaderWriterXML.hxx" -#include "SGReaderWriterXMLOptions.hxx" #include "modellib.hxx" - +using std::string; using namespace simgear; osgDB::RegisterReaderWriterProxy g_readerWriter_XML_Proxy; ModelRegistryCallbackProxy g_xmlCallbackProxy("xml"); - +SGPropertyNode_ptr SGModelLib::static_propRoot; +SGModelLib::panel_func SGModelLib::static_panelFunc = NULL; + //////////////////////////////////////////////////////////////////////// // Implementation of SGModelLib. //////////////////////////////////////////////////////////////////////// -void SGModelLib::init(const string &root_dir) +void SGModelLib::init(const string &root_dir, SGPropertyNode* root) { osgDB::Registry::instance()->getDataFilePathList().push_front(root_dir); + 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::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); } SGModelLib::SGModelLib() @@ -57,15 +90,38 @@ SGModelLib::~SGModelLib() { } +namespace +{ +osg::Node* loadFile(const string& path, SGReaderWriterOptions* options) +{ + using namespace osg; + using namespace osgDB; + if (boost::iends_with(path, ".ac")) + options->setInstantiateEffects(true); + ref_ptr model = readRefNodeFile(path, options); + if (!model) + return 0; + else + return model.release(); +} +} + osg::Node* SGModelLib::loadModel(const string &path, SGPropertyNode *prop_root, - SGModelData *data) + SGModelData *data, + bool load2DPanels) { - osg::ref_ptr opt = new SGReaderWriterXMLOptions(*(osgDB::Registry::instance()->getOptions())); - opt->setPropRoot(prop_root); + osg::ref_ptr opt; + opt = SGReaderWriterOptions::copyOrCreate(osgDB::Registry::instance()->getOptions()); + opt->setPropertyNode(prop_root ? prop_root: static_propRoot.get()); opt->setModelData(data); - osg::Node *n = readNodeFile(path, opt.get()); + + if (load2DPanels) { + opt->setLoadPanel(static_panelFunc); + } + + osg::Node *n = loadFile(path, opt.get()); if (n && n->getName().empty()) n->setName("Direct loaded model \"" + path + "\""); return n; @@ -73,30 +129,50 @@ SGModelLib::loadModel(const string &path, } osg::Node* -SGModelLib::loadModel(const string &path, - SGPropertyNode *prop_root, - panel_func pf) +SGModelLib::loadDeferredModel(const string &path, SGPropertyNode *prop_root, + SGModelData *data) { - osg::ref_ptr opt = new SGReaderWriterXMLOptions(*(osgDB::Registry::instance()->getOptions())); - opt->setPropRoot(prop_root); - opt->setLoadPanel(pf); - return readNodeFile(path, opt.get()); + osg::ProxyNode* proxyNode = new osg::ProxyNode; + proxyNode->setLoadingExternalReferenceMode(osg::ProxyNode::DEFER_LOADING_TO_DATABASE_PAGER); + proxyNode->setFileName(0, path); + + osg::ref_ptr 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::Options::CACHE_ALL); + else + opt->setObjectCacheHint(osgDB::Options::CACHE_NONE); + proxyNode->setDatabaseOptions(opt.get()); + + return proxyNode; } -osg::Node* -SGModelLib::loadPagedModel(const string &path, - SGPropertyNode *prop_root, +osg::PagedLOD* +SGModelLib::loadPagedModel(const string &path, SGPropertyNode *prop_root, SGModelData *data) { - SGPagedLOD *plod = new SGPagedLOD; + osg::PagedLOD *plod = new osg::PagedLOD; plod->setName("Paged LOD for \"" + path + "\""); plod->setFileName(0, path); plod->setRange(0, 0.0, 50.0*SG_NM_TO_METER); - osg::ref_ptr opt = new SGReaderWriterXMLOptions(*(osgDB::Registry::instance()->getOptions())); - opt->setPropRoot(prop_root); + osg::ref_ptr opt; + opt = SGReaderWriterOptions::copyOrCreate(osgDB::Registry::instance()->getOptions()); + opt->setPropertyNode(prop_root ? prop_root: static_propRoot.get()); opt->setModelData(data); - plod->setReaderWriterOptions(opt.get()); + 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::Options::CACHE_ALL); + else + opt->setObjectCacheHint(osgDB::Options::CACHE_NONE); + plod->setDatabaseOptions(opt.get()); return plod; }