[osg-submissions] osgPlugins/ac/ac3d.cpp: don't strip relative texture paths

Melchior FRANZ melchior.franz at gmail.com
Tue Mar 11 05:24:24 PDT 2008


I had accidentally posted a followup with a new version to the
osg-users list. It will probably get lost there, so here's that
patch again to the right list, along with a corrected description:
------------------------------------------------------------------

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)


Here's the patch for easier review (full version attached):

--- src/osgPlugins/ac/ac3d.cpp  (revision 7919)
+++ src/osgPlugins/ac/ac3d.cpp  (working copy)
@@ -1118,16 +1118,17 @@
             group->setName(readString(stream));
         }
         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);
         }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ac3d.cpp.gz
Type: application/x-gzip
Size: 9705 bytes
Desc: not available
Url : http://lists.openscenegraph.org/pipermail/osg-submissions-openscenegraph.org/attachments/20080311/c1335cd2/attachment.bin 


More information about the osg-submissions mailing list