Răsfoiți Sursa

- Collada Exporter id naming scheme once again revised to exclude any potential invalid chars
- Collada Exporter outputs proper URLs for texture file names now.
- Updated Collada Loader to understand and convert texture file name URLs

git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@1191 67173fc5-114c-0410-ac8e-9d2fd5bffc1f

ulfjorensen 13 ani în urmă
părinte
comite
6970307b4e
2 a modificat fișierele cu 32 adăugiri și 8 ștergeri
  1. 14 8
      code/ColladaExporter.cpp
  2. 18 0
      code/ColladaLoader.cpp

+ 14 - 8
code/ColladaExporter.cpp

@@ -156,7 +156,17 @@ void ColladaExporter::WriteImageEntry( const Surface& pSurface, const std::strin
   {
     mOutput << startstr << "<image id=\"" << pNameAdd << "\">" << endstr;
     PushTag(); 
-    mOutput << startstr << "<init_from>" << pSurface.texture << "</init_from>" << endstr;
+    mOutput << startstr << "<init_from>";
+    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 << "</init_from>" << endstr;
     PopTag();
     mOutput << startstr << "</image>" << 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<std::string> (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++;

+ 18 - 0
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);
 }
 
 // ------------------------------------------------------------------------------------------------