Переглянути джерело

X3D importer: Fixed path handling

Patrick Dähne 8 роки тому
батько
коміт
8959bcb847
2 змінених файлів з 10 додано та 3 видалено
  1. 3 1
      code/X3DImporter.cpp
  2. 7 2
      code/X3DImporter_Networking.cpp

+ 3 - 1
code/X3DImporter.cpp

@@ -1610,8 +1610,10 @@ void X3DImporter::InternReadFile(const std::string& pFile, aiScene* pScene, IOSy
 	mpIOHandler = pIOHandler;
 	mpIOHandler = pIOHandler;
 
 
 	Clear();// delete old graph.
 	Clear();// delete old graph.
-	pIOHandler->PushDirectory(DefaultIOSystem::absolutePath(pFile));
+	std::string::size_type slashPos = pFile.find_last_of("\\/");
+	pIOHandler->PushDirectory(slashPos == std::string::npos ? std::string() : pFile.substr(0, slashPos + 1));
 	ParseFile(pFile, pIOHandler);
 	ParseFile(pFile, pIOHandler);
+	pIOHandler->PopDirectory();
 	//
 	//
 	// Assimp use static arrays of objects for fast speed of rendering. That's good, but need some additional operations/
 	// Assimp use static arrays of objects for fast speed of rendering. That's good, but need some additional operations/
 	// We know that geometry objects(meshes) are stored in <Shape>, also in <Shape>-><Appearance> materials(in Assimp logical view)
 	// We know that geometry objects(meshes) are stored in <Shape>, also in <Shape>-><Appearance> materials(in Assimp logical view)

+ 7 - 2
code/X3DImporter_Networking.cpp

@@ -51,9 +51,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 // Header files, Assimp.
 // Header files, Assimp.
 #include <assimp/DefaultIOSystem.h>
 #include <assimp/DefaultIOSystem.h>
 
 
+#include <regex>
+
 namespace Assimp
 namespace Assimp
 {
 {
 
 
+static std::regex pattern_parentDir(R"((^|/)[^/]+/../)");
+
 // <Inline
 // <Inline
 // DEF=""              ID
 // DEF=""              ID
 // USE=""              IDREF
 // USE=""              IDREF
@@ -91,9 +95,10 @@ void X3DImporter::ParseNode_Networking_Inline()
 		{
 		{
 			std::string full_path;
 			std::string full_path;
 
 
-			full_path = mpIOHandler->CurrentDirectory() + "/" + url.front();
+			full_path = std::regex_replace(mpIOHandler->CurrentDirectory() + url.front(), pattern_parentDir, "$1");
 			// Attribute "url" can contain list of strings. But we need only one - first.
 			// Attribute "url" can contain list of strings. But we need only one - first.
-			mpIOHandler->PushDirectory(DefaultIOSystem::absolutePath(full_path));
+			std::string::size_type slashPos = full_path.find_last_of("\\/");
+			mpIOHandler->PushDirectory(slashPos == std::string::npos ? std::string() : full_path.substr(0, slashPos + 1));
 			ParseFile(full_path, mpIOHandler);
 			ParseFile(full_path, mpIOHandler);
 			mpIOHandler->PopDirectory();
 			mpIOHandler->PopDirectory();
 		}
 		}