From Sukender: I had to call code from the FBX plugin (to relativise paths). I thus extracted it from FBX and moved it in osgDB (FileNameUtils)

This commit is contained in:
Michael PLATINGS
2011-01-21 12:17:18 +00:00
parent 43afbab09e
commit cc207c1112

View File

@@ -278,53 +278,6 @@ void PrimitiveIndexWriter::drawArrays(GLenum mode,GLint first,GLsizei count)
if (_normalBinding == osg::Geometry::BIND_PER_PRIMITIVE_SET) ++_curNormalIndex;
}
// If 'to' is in a subdirectory of 'from' then this function returns the
// subpath. Otherwise it just returns the file name.
std::string getPathRelative(const std::string& from/*directory*/,
const std::string& to/*file path*/)
{
std::string::size_type slash = to.find_last_of('/');
std::string::size_type backslash = to.find_last_of('\\');
if (slash == std::string::npos)
{
if (backslash == std::string::npos) return to;
slash = backslash;
}
else if (backslash != std::string::npos && backslash > slash)
{
slash = backslash;
}
if (from.empty() || from.length() > to.length())
return osgDB::getSimpleFileName(to);
std::string::const_iterator itTo = to.begin();
for (std::string::const_iterator itFrom = from.begin();
itFrom != from.end(); ++itFrom, ++itTo)
{
char a = tolower(*itFrom), b = tolower(*itTo);
if (a == '\\') a = '/';
if (b == '\\') b = '/';
if (a != b || itTo == to.begin() + slash + 1)
{
return osgDB::getSimpleFileName(to);
}
}
while (itTo != to.end() && (*itTo == '\\' || *itTo == '/'))
{
++itTo;
}
return std::string(itTo, to.end());
}
//std::string testA = getPathRelative("C:\\a\\b", "C:\\a/b/d/f");
//std::string testB = getPathRelative("C:\\a\\d", "C:\\a/b/d/f");
//std::string testC = getPathRelative("C:\\ab", "C:\\a/b/d/f");
//std::string testD = getPathRelative("a/d", "a/d");
WriterNodeVisitor::Material::Material(WriterNodeVisitor& writerNodeVisitor,
const std::string& srcDirectory,
const osg::StateSet* stateset,
@@ -434,7 +387,7 @@ WriterNodeVisitor::Material::Material(WriterNodeVisitor& writerNodeVisitor,
}
else
{
relativePath = getPathRelative(srcDirectory, canonicalPath);
relativePath = osgDB::getPathRelative(srcDirectory, canonicalPath);
destPath = osgDB::getRealPath(osgDB::convertFileNameToNativeStyle( osgDB::concatPaths(_directory, relativePath) ));
if (destPath != canonicalPath)
{