From 689e11693adaf31799e9e70620c7d5a0d1d64532 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 25 Nov 2003 10:32:23 +0000 Subject: [PATCH] From Alberto Farre, added support for nesting of files. --- src/osgPlugins/flt/FltFile.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/osgPlugins/flt/FltFile.cpp b/src/osgPlugins/flt/FltFile.cpp index b984d6318..7a592a850 100644 --- a/src/osgPlugins/flt/FltFile.cpp +++ b/src/osgPlugins/flt/FltFile.cpp @@ -115,8 +115,8 @@ bool FltFile::readModel(const std::string& fileName) bool FltFile::readFile(const std::string& fileName) { - FileInput fin; + FileInput fin; if (!fin.open(fileName)) { // havn't found file, look in OSGFILEPATH @@ -195,7 +195,26 @@ bool FltFile::readFile(const std::string& fileName) pExternalFltFile = Registry::instance()->getFltFile(filename); if (pExternalFltFile == NULL) { - pExternalFltFile = new FltFile(pColorPool, pTexturePool, pMaterialPool); + //Path for Nested external references + std::string filePath = osgDB::getFilePath(filename); + std::string pushAndPopPath; + //If absolute path + if( (filePath.length()>0 && filePath.find_first_of("/\\")==0) || + (filePath.length()>2 && filePath.substr(1,1)==":" && filePath.find_first_of("/\\")==2) ) + { + pushAndPopPath = filePath; + } + else + { + osgDB::FilePathList fpl = osgDB::getDataFilePathList(); + pushAndPopPath = fpl.empty() ? "." : fpl.front(); + if(pushAndPopPath.empty()) pushAndPopPath = "."; + pushAndPopPath += "/" + filePath; + } + osgDB::PushAndPopDataPath tmpfile(pushAndPopPath); + + + pExternalFltFile = new FltFile(pColorPool, pTexturePool, pMaterialPool); pExternalFltFile->readModel(filename); } Registry::instance()->addFltFile(filename, pExternalFltFile);