diff --git a/code/ColladaExporter.cpp b/code/ColladaExporter.cpp
index b0d672342..62293a941 100644
--- a/code/ColladaExporter.cpp
+++ b/code/ColladaExporter.cpp
@@ -156,7 +156,17 @@ void ColladaExporter::WriteImageEntry( const Surface& pSurface, const std::strin
{
mOutput << startstr << "" << endstr;
PushTag();
- mOutput << startstr << "" << pSurface.texture << "" << endstr;
+ mOutput << startstr << "";
+ if( pSurface.texture.find( "file://") == std::string::npos )
+ mOutput << "file://";
+ for( std::string::const_iterator it = std::begin( pSurface.texture); it != std::end( pSurface.texture); ++it )
+ {
+ if( isalnum( *it) || *it == '_' || *it == '.' || *it == '/' || *it == '\\' )
+ mOutput << *it;
+ else
+ mOutput << '%' << std::hex << size_t( (unsigned char) *it) << std::dec;
+ }
+ mOutput << "" << endstr;
PopTag();
mOutput << startstr << "" << endstr;
}
@@ -224,13 +234,9 @@ void ColladaExporter::WriteMaterials()
if( mat->Get( AI_MATKEY_NAME, name) != aiReturn_SUCCESS )
name = "mat";
materials[a].name = std::string( "m") + boost::lexical_cast (a) + name.C_Str();
- size_t pos;
- while( (pos = materials[a].name.find( '#')) != std::string::npos )
- materials[a].name[pos] = 'x';
- while( (pos = materials[a].name.find( ' ')) != std::string::npos )
- materials[a].name[pos] = '_';
- while( (pos = materials[a].name.find( '"')) != std::string::npos )
- materials[a].name[pos] = '_';
+ for( std::string::iterator it = materials[a].name.begin(); it != materials[a].name.end(); ++it )
+ if( !isalnum( *it) )
+ *it = '_';
ReadMaterialSurface( materials[a].ambient, mat, aiTextureType_AMBIENT, AI_MATKEY_COLOR_AMBIENT);
if( !materials[a].ambient.texture.empty() ) numTextures++;
diff --git a/code/ColladaLoader.cpp b/code/ColladaLoader.cpp
index c80c9e90f..b20ebea64 100644
--- a/code/ColladaLoader.cpp
+++ b/code/ColladaLoader.cpp
@@ -1398,6 +1398,24 @@ void ColladaLoader::ConvertPath (aiString& ss)
memmove(ss.data,ss.data+7,ss.length);
ss.data[ss.length] = '\0';
}
+
+ // find and convert all %xyz special chars
+ char* out = ss.data;
+ for( const char* it = ss.data; it != ss.data + ss.length; /**/ )
+ {
+ if( *it == '%' )
+ {
+ size_t nbr = strtoul16( ++it, &it);
+ *out++ = nbr;
+ } else
+ {
+ *out++ = *it++;
+ }
+ }
+
+ // adjust length and terminator of the shortened string
+ *out = 0;
+ ss.length = (ptrdiff_t) (out - ss.data);
}
// ------------------------------------------------------------------------------------------------