From: Mathias Froehlich Date: Sun, 4 Mar 2012 06:41:56 +0000 (+0100) Subject: Make use of SGReaderWriterOptions::copyOrCreate in SGReaderWriterXML. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=4e24095d8be43a8f6a2e060dfea4e7a4aec44ea5;p=simgear.git Make use of SGReaderWriterOptions::copyOrCreate in SGReaderWriterXML. --- diff --git a/simgear/scene/model/SGReaderWriterXML.cxx b/simgear/scene/model/SGReaderWriterXML.cxx index ec740593..83a2f59f 100644 --- a/simgear/scene/model/SGReaderWriterXML.cxx +++ b/simgear/scene/model/SGReaderWriterXML.cxx @@ -200,34 +200,26 @@ void makeEffectAnimations(PropertyList& animation_nodes, static osg::Node * sgLoad3DModel_internal(const SGPath& path, - const osgDB::Options* options_, + const osgDB::Options* dbOptions, SGPropertyNode *overlay) { if (!path.exists()) { SG_LOG(SG_INPUT, SG_ALERT, "Failed to load file: \"" << path.str() << "\""); return NULL; } - - const SGReaderWriterOptions* xmlOptions; - xmlOptions = dynamic_cast(options_); - SGSharedPtr prop_root; - osg::Node *(*load_panel)(SGPropertyNode *)=0; - osg::ref_ptr data; + osg::ref_ptr options; + options = SGReaderWriterOptions::copyOrCreate(dbOptions); + SGPath modelpath(path); SGPath texturepath(path); SGPath modelDir(modelpath.dir()); - if (xmlOptions) { - prop_root = xmlOptions->getPropertyNode(); - load_panel = xmlOptions->getLoadPanel(); - data = xmlOptions->getModelData(); - } - - if (!prop_root) { + SGSharedPtr prop_root = options->getPropertyNode(); + if (!prop_root.valid()) prop_root = new SGPropertyNode; - } - + osg::ref_ptr data = options->getModelData(); + osg::ref_ptr model; osg::ref_ptr group; SGPropertyNode_ptr props = new SGPropertyNode; @@ -269,10 +261,7 @@ sgLoad3DModel_internal(const SGPath& path, // model without wrapper } - osg::ref_ptr options - = new SGReaderWriterOptions(*options_); options->setPropertyNode(prop_root); - options->setLoadPanel(load_panel); // Assume that textures are in // the same location as the XML file. @@ -280,9 +269,11 @@ sgLoad3DModel_internal(const SGPath& path, if (!texturepath.extension().empty()) texturepath = texturepath.dir(); - options->setDatabasePath(texturepath.str()); + osg::ref_ptr options2; + options2 = new SGReaderWriterOptions(*options); + options2->setDatabasePath(texturepath.str()); osgDB::ReaderWriter::ReadResult modelResult; - modelResult = osgDB::readNodeFile(modelpath.str(), options.get()); + modelResult = osgDB::readNodeFile(modelpath.str(), options2.get()); if (!modelResult.validNode()) throw sg_io_exception("Failed to load 3D model:" + modelResult.message(), modelpath.str()); @@ -298,7 +289,7 @@ sgLoad3DModel_internal(const SGPath& path, model->addObserver(databaseReference); // Update liveries - TextureUpdateVisitor liveryUpdate(options->getDatabasePathList()); + TextureUpdateVisitor liveryUpdate(options2->getDatabasePathList()); model->accept(liveryUpdate); // Copy the userdata fields, still sharing the boundingvolumes, @@ -353,11 +344,6 @@ sgLoad3DModel_internal(const SGPath& path, continue; } - osg::ref_ptr options; - options = new SGReaderWriterOptions(*options_); - options->setPropertyNode(prop_root); - options->setLoadPanel(load_panel); - try { submodel = sgLoad3DModel_internal(submodelPath, options.get(), sub_props->getNode("overlay")); @@ -405,6 +391,7 @@ sgLoad3DModel_internal(const SGPath& path, } } // end of submodel loading + osg::Node *(*load_panel)(SGPropertyNode *) = options->getLoadPanel(); if ( load_panel ) { // Load panels vector panel_nodes = props->getChildren("panel"); @@ -420,15 +407,17 @@ sgLoad3DModel_internal(const SGPath& path, std::vector particle_nodes; particle_nodes = props->getChildren("particlesystem"); for (unsigned i = 0; i < particle_nodes.size(); ++i) { + osg::ref_ptr options2; + options2 = new SGReaderWriterOptions(*options); if (i==0) { if (!texturepath.extension().empty()) texturepath = texturepath.dir(); - options->setDatabasePath(texturepath.str()); + options2->setDatabasePath(texturepath.str()); } group->addChild(Particles::appendParticles(particle_nodes[i], prop_root, - options.get())); + options2.get())); } std::vector text_nodes;