From 110c761695e2cc9ec8f758965a0dd8aa84ff16d6 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 13 Mar 2008 16:18:03 +0000 Subject: [PATCH] From Melchoir Franz, "ac3d.cpp does currently strip everything but the file name in "texture" paths. This is to drop absolute paths that some 3d editors export (even AC3D itself!). But this also strips directories of relative paths, which is wrong and contradicts the ac3d reference implementation. (The reference implementation doesn't strip anything, though, and so takes the absolute paths as they are. Definitely not what we want.) The attached solution checks absolute paths and only strips those: (1) A:\\foo\\bar.png -> bar.png (as before) (2) /foo/bar.png -> bar.png (as before) (3) foo/bar.png -> foo/bar.png (new) (4) ../foo/bar.png -> ../foo/bar.png (new) " --- src/osgPlugins/ac/ac3d.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/osgPlugins/ac/ac3d.cpp b/src/osgPlugins/ac/ac3d.cpp index 79bebba90..b4a1ea3b7 100644 --- a/src/osgPlugins/ac/ac3d.cpp +++ b/src/osgPlugins/ac/ac3d.cpp @@ -1120,14 +1120,16 @@ readObject(std::istream& stream, FileData& fileData, const osg::Matrix& parentTr else if (token == "texture") { // read the texture name std::string texname = readString(stream); - - // strip the path to the texture, just look in the directory we read the ac file - std::string::size_type p = texname.rfind('\\'); - if (p != std::string::npos) - texname = texname.substr(p+1, std::string::npos); - p = texname.rfind('/'); - if (p != std::string::npos) - texname = texname.substr(p+1, std::string::npos); + + // strip absolute paths + if (texname[0] == '/' || isalpha(texname[0]) && texname[1] == ':') { + std::string::size_type p = texname.rfind('\\'); + if (p != std::string::npos) + texname = texname.substr(p+1, std::string::npos); + p = texname.rfind('/'); + if (p != std::string::npos) + texname = texname.substr(p+1, std::string::npos); + } textureData = fileData.toTextureData(texname); }