X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fscene%2Fmodel%2Fmodellib.cxx;h=af72e363d65d7a02e25dbad561b6ccf04b120d66;hb=5a96b283f63cfacd3a3a90a82246defb038242d3;hp=45c014309a8e4f2c576d997bf28f30c5ad27d8ca;hpb=66cdbf621571945a5e4e1376996b160835241141;p=simgear.git diff --git a/simgear/scene/model/modellib.cxx b/simgear/scene/model/modellib.cxx index 45c01430..af72e363 100644 --- a/simgear/scene/model/modellib.cxx +++ b/simgear/scene/model/modellib.cxx @@ -21,6 +21,8 @@ #include +#include +#include #include #include #include @@ -30,11 +32,10 @@ #include #include #include +#include #include -#include "SGPagedLOD.hxx" #include "SGReaderWriterXML.hxx" -#include "SGReaderWriterXMLOptions.hxx" #include "modellib.hxx" @@ -52,30 +53,28 @@ 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::setPropRoot(SGPropertyNode* root) -{ - static_propRoot = root; -} - void SGModelLib::setPanelFunc(panel_func pf) { static_panelFunc = pf; } std::string SGModelLib::findDataFile(const std::string& file, - const osgDB::ReaderWriter::Options* opts, + 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); } @@ -90,7 +89,7 @@ SGModelLib::~SGModelLib() namespace { -osg::Node* loadFile(const string& path, SGReaderWriterXMLOptions* options) +osg::Node* loadFile(const string& path, SGReaderWriterOptions* options) { using namespace osg; using namespace osgDB; @@ -110,8 +109,9 @@ SGModelLib::loadModel(const string &path, SGModelData *data, bool load2DPanels) { - osg::ref_ptr opt = new SGReaderWriterXMLOptions(*(osgDB::Registry::instance()->getOptions())); - opt->setPropRoot(prop_root ? prop_root: static_propRoot.get()); + osg::ref_ptr opt; + opt = SGReaderWriterOptions::copyOrCreate(osgDB::Registry::instance()->getOptions()); + opt->setPropertyNode(prop_root ? prop_root: static_propRoot.get()); opt->setModelData(data); if (load2DPanels) { @@ -125,24 +125,51 @@ SGModelLib::loadModel(const string &path, } +osg::Node* +SGModelLib::loadDeferredModel(const string &path, SGPropertyNode *prop_root, + SGModelData *data) +{ + 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, 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 ? prop_root: static_propRoot.get()); + 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 (boost::iends_with(path, ".ac")) + if (SGPath(path).lower_extension() == "ac") opt->setInstantiateEffects(true); - plod->setReaderWriterOptions(opt.get()); + 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; }