From: fredb Date: Wed, 2 Apr 2008 22:25:12 +0000 (+0000) Subject: Allows to load submodels with path relative to current model path. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=bb3b6068204cd054dee4819067694f8cb9b31b1d;p=simgear.git Allows to load submodels with path relative to current model path. Submodel path must be prefixed by ./ otherwise path is relative to fg_root ( current behavior ) --- diff --git a/simgear/scene/model/SGReaderWriterXML.cxx b/simgear/scene/model/SGReaderWriterXML.cxx index 36a3ebed..88f9e645 100644 --- a/simgear/scene/model/SGReaderWriterXML.cxx +++ b/simgear/scene/model/SGReaderWriterXML.cxx @@ -214,10 +214,17 @@ sgLoad3DModel_internal(const string &path, for (unsigned i = 0; i < model_nodes.size(); i++) { SGPropertyNode_ptr sub_props = model_nodes[i]; + SGPath submodelpath; osg::ref_ptr submodel; - const char* submodelFileName = sub_props->getStringValue("path"); + string submodelFileName = sub_props->getStringValue("path"); + if ( submodelFileName.size() > 2 && submodelFileName.substr( 0, 2 ) == "./" ) { + submodelpath = modelpath.dir(); + submodelpath.append( submodelFileName.substr( 2 ) ); + } else { + submodelpath = submodelFileName; + } try { - submodel = sgLoad3DModel_internal(submodelFileName, prop_root, 0, load_panel); + submodel = sgLoad3DModel_internal(submodelpath.str(), prop_root, 0, load_panel); } catch (const sg_throwable &t) { SG_LOG(SG_INPUT, SG_ALERT, "Failed to load submodel: " << t.getFormattedMessage()); throw;