X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fscene%2Fmodel%2FSGReaderWriterXML.cxx;h=50943dcd9e48b00a1a0f9f66e778ae4be6bbc188;hb=a592488f3e18a68bdf020a0413cd45356dfa638c;hp=eee6e08af630800c274df243895f1dea71c6c2fa;hpb=a7439aa05616b04993d9fa1d712ae73e63c51d19;p=simgear.git diff --git a/simgear/scene/model/SGReaderWriterXML.cxx b/simgear/scene/model/SGReaderWriterXML.cxx index eee6e08a..50943dcd 100644 --- a/simgear/scene/model/SGReaderWriterXML.cxx +++ b/simgear/scene/model/SGReaderWriterXML.cxx @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -40,11 +41,10 @@ #include #include #include +#include #include "modellib.hxx" -#include "SGPagedLOD.hxx" #include "SGReaderWriterXML.hxx" -#include "SGReaderWriterXMLOptions.hxx" #include "animation.hxx" #include "particles.hxx" @@ -58,7 +58,7 @@ using namespace osg; static osg::Node * sgLoad3DModel_internal(const SGPath& path, - const osgDB::ReaderWriter::Options* options, + const osgDB::Options* options, SGPropertyNode *overlay = 0); @@ -78,7 +78,7 @@ const char* SGReaderWriterXML::className() const osgDB::ReaderWriter::ReadResult SGReaderWriterXML::readNode(const std::string& fileName, - const osgDB::ReaderWriter::Options* options) const + const osgDB::Options* options) const { osg::Node *result=0; try { @@ -200,34 +200,28 @@ void makeEffectAnimations(PropertyList& animation_nodes, static osg::Node * sgLoad3DModel_internal(const SGPath& path, - const osgDB::ReaderWriter::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 SGReaderWriterXMLOptions* 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->getPropRoot(); - load_panel = xmlOptions->getLoadPanel(); - data = xmlOptions->getModelData(); - } - - if (!prop_root) { + SGSharedPtr prop_root = options->getPropertyNode(); + if (!prop_root.valid()) prop_root = new SGPropertyNode; - } - + // The model data appear to be only used in the topmost model + osg::ref_ptr data = options->getModelData(); + options->setModelData(0); + osg::ref_ptr model; osg::ref_ptr group; SGPropertyNode_ptr props = new SGPropertyNode; @@ -245,9 +239,18 @@ sgLoad3DModel_internal(const SGPath& path, copyProperties(overlay, props); if (props->hasValue("/path")) { - modelpath = SGModelLib::findDataFile(props->getStringValue("/path"), NULL, modelDir); + string modelPathStr = props->getStringValue("/path"); + modelpath = SGModelLib::findDataFile(modelPathStr, NULL, modelDir); + if (modelpath.isNull()) + throw sg_io_exception("Model file not found: '" + modelPathStr + "'", + path.str()); + if (props->hasValue("/texture-path")) { - texturepath = SGModelLib::findDataFile(props->getStringValue("/texture-path"), NULL, modelDir); + string texturePathStr = props->getStringValue("/texture-path"); + texturepath = SGModelLib::findDataFile(texturePathStr, NULL, modelDir); + if (texturepath.isNull()) + throw sg_io_exception("Texture file not found: '" + texturePathStr + "'", + path.str()); } } else { model = new osg::Node; @@ -260,11 +263,6 @@ sgLoad3DModel_internal(const SGPath& path, // model without wrapper } - osg::ref_ptr options - = new SGReaderWriterXMLOptions(*options_); - options->setPropRoot(prop_root); - options->setLoadPanel(load_panel); - // Assume that textures are in // the same location as the XML file. if (!model) { @@ -272,9 +270,8 @@ sgLoad3DModel_internal(const SGPath& path, texturepath = texturepath.dir(); options->setDatabasePath(texturepath.str()); - osgDB::ReaderWriter::ReadResult modelResult - = osgDB::Registry::instance()->readNode(modelpath.str(), - options.get()); + osgDB::ReaderWriter::ReadResult modelResult; + modelResult = osgDB::readNodeFile(modelpath.str(), options.get()); if (!modelResult.validNode()) throw sg_io_exception("Failed to load 3D model:" + modelResult.message(), modelpath.str()); @@ -336,20 +333,22 @@ sgLoad3DModel_internal(const SGPath& path, SGPath submodelpath; osg::ref_ptr submodel; - SGPath submodelPath = SGModelLib::findDataFile(sub_props->getStringValue("path"), + string subPathStr = sub_props->getStringValue("path"); + SGPath submodelPath = SGModelLib::findDataFile(subPathStr, NULL, modelDir); - osg::ref_ptr options; - options = new SGReaderWriterXMLOptions(*options_); - options->setPropRoot(prop_root); - options->setLoadPanel(load_panel); - + if (submodelPath.isNull()) { + SG_LOG(SG_INPUT, SG_ALERT, "Failed to load file: \"" << subPathStr << "\""); + continue; + } + try { submodel = sgLoad3DModel_internal(submodelPath, options.get(), sub_props->getNode("overlay")); } catch (const sg_exception &t) { SG_LOG(SG_INPUT, SG_ALERT, "Failed to load submodel: " << t.getFormattedMessage() << "\n\tfrom:" << t.getOrigin()); + continue; } osg::ref_ptr submodel_final = submodel; @@ -390,6 +389,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"); @@ -402,18 +402,22 @@ sgLoad3DModel_internal(const SGPath& path, } } - std::vector particle_nodes; - particle_nodes = props->getChildren("particlesystem"); - for (unsigned i = 0; i < particle_nodes.size(); ++i) { - if (i==0) { - if (!texturepath.extension().empty()) - texturepath = texturepath.dir(); - - options->setDatabasePath(texturepath.str()); + if (dbOptions->getPluginStringData("SimGear::PARTICLESYSTEM") != "OFF") { + 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(); + + options2->setDatabasePath(texturepath.str()); + } + group->addChild(Particles::appendParticles(particle_nodes[i], + prop_root, + options2.get())); } - group->addChild(Particles::appendParticles(particle_nodes[i], - prop_root, - options.get())); } std::vector text_nodes; @@ -425,6 +429,7 @@ sgLoad3DModel_internal(const SGPath& path, } PropertyList effect_nodes = props->getChildren("effect"); PropertyList animation_nodes = props->getChildren("animation"); + PropertyList light_nodes = props->getChildren("light"); // Some material animations (eventually all) are actually effects. makeEffectAnimations(animation_nodes, effect_nodes); { @@ -435,7 +440,7 @@ sgLoad3DModel_internal(const SGPath& path, for (unsigned i = 0; i < animation_nodes.size(); ++i) /// OSGFIXME: duh, why not only model????? SGAnimation::animate(group.get(), animation_nodes[i], prop_root, - options.get()); + options.get(), path.str(), i); if (!needTransform && group->getNumChildren() < 2) { model = group->getChild(0);