Browse Source

Use full asset paths (with / sanitated to _) in Tundra scene import, as there may be assets with same name but with different content in different subdirectories.

Lasse Öörni 13 years ago
parent
commit
5ede251b62
2 changed files with 41 additions and 20 deletions
  1. 40 19
      Bin/Data/Scripts/Editor/EditorImport.as
  2. 1 1
      Docs/Urho3D.dox

+ 40 - 19
Bin/Data/Scripts/Editor/EditorImport.as

@@ -233,7 +233,7 @@ void ImportTundraScene(const String&in fileName)
             if (!meshName.empty)
             if (!meshName.empty)
             {
             {
                 StaticModel@ model = newNode.CreateComponent("StaticModel");
                 StaticModel@ model = newNode.CreateComponent("StaticModel");
-                model.model = cache.GetResource("Model", "Models/" + GetFileNameAndExtension(meshName).Replaced(".mesh", ".mdl"));
+                model.model = cache.GetResource("Model", GetOutModelName(meshName));
                 model.drawDistance = drawDistance;
                 model.drawDistance = drawDistance;
                 model.castShadows = castShadows;
                 model.castShadows = castShadows;
                 // Set default grey material to match Tundra defaults
                 // Set default grey material to match Tundra defaults
@@ -241,7 +241,7 @@ void ImportTundraScene(const String&in fileName)
                 // Then try to assign the actual materials
                 // Then try to assign the actual materials
                 for (uint i = 0; i < materialNames.length; ++i)
                 for (uint i = 0; i < materialNames.length; ++i)
                 {
                 {
-                    Material@ mat = cache.GetResource("Material", "Materials/" + GetFileNameAndExtension(materialNames[i]).Replaced(".material", ".xml"));
+                    Material@ mat = cache.GetResource("Material", GetOutMaterialName(materialNames[i]));
                     if (mat !is null)
                     if (mat !is null)
                         model.materials[i] = mat;
                         model.materials[i] = mat;
                 }
                 }
@@ -277,11 +277,11 @@ void ImportTundraScene(const String&in fileName)
                     break;
                     break;
 
 
                 case 4:
                 case 4:
-                    shape.SetTriangleMesh(cache.GetResource("Model", "Models/" + GetFileNameAndExtension(collisionMeshName).Replaced(".mesh", ".mdl")), 0, bodySize);
+                    shape.SetTriangleMesh(cache.GetResource("Model", GetOutModelName(collisionMeshName)), 0, bodySize);
                     break;
                     break;
 
 
                 case 6:
                 case 6:
-                    shape.SetConvexHull(cache.GetResource("Model", "Models/" + GetFileNameAndExtension(collisionMeshName).Replaced(".mesh", ".mdl")), 0, bodySize);
+                    shape.SetConvexHull(cache.GetResource("Model", GetOutModelName(collisionMeshName)), 0, bodySize);
                     break;
                     break;
                 }
                 }
 
 
@@ -365,6 +365,21 @@ void ProcessRef(String& ref)
         ref = ref.Substring(7);
         ref = ref.Substring(7);
 }
 }
 
 
+String GetOutModelName(const String&in ref)
+{
+    return "Models/" + GetFullAssetName(ref).Replaced('/', '_').Replaced(".mesh", ".mdl");
+}
+
+String GetOutMaterialName(const String&in ref)
+{
+    return "Materials/" + GetFullAssetName(ref).Replaced('/', '_').Replaced(".material", ".xml");
+}
+
+String GetOutTextureName(const String&in ref)
+{
+    return "Textures/" + GetFullAssetName(ref).Replaced('/', '_');
+}
+
 void ConvertModel(const String&in modelName, const String&in filePath, Array<String>@ convertedModels)
 void ConvertModel(const String&in modelName, const String&in filePath, Array<String>@ convertedModels)
 {
 {
     if (modelName.Trimmed().empty)
     if (modelName.Trimmed().empty)
@@ -376,19 +391,24 @@ void ConvertModel(const String&in modelName, const String&in filePath, Array<Str
             return;
             return;
     }
     }
 
 
-    String convertedModelName = filePath + modelName + ".xml";
+    String meshFileName = filePath + GetFullAssetName(modelName);
+    String xmlFileName = filePath + GetFullAssetName(modelName) + ".xml";
+    String outFileName = sceneResourcePath + GetOutModelName(modelName);
 
 
     // Convert .mesh to .mesh.xml
     // Convert .mesh to .mesh.xml
-    String cmdLine = "ogrexmlconverter \"" + filePath + GetFullAssetName(modelName) + "\" \"" + convertedModelName + "\"";
-    if (!fileSystem.FileExists(convertedModelName))
+    String cmdLine = "ogrexmlconverter \"" + meshFileName + "\" \"" + xmlFileName + "\"";
+    if (!fileSystem.FileExists(xmlFileName))
         fileSystem.SystemCommand(cmdLine.Replaced('/', '\\'));
         fileSystem.SystemCommand(cmdLine.Replaced('/', '\\'));
 
 
-    // Convert .mesh.xml to .mdl
-    Array<String> args;
-    args.Push("\"" + filePath + GetFullAssetName(modelName) + ".xml\"");
-    args.Push("\"" + sceneResourcePath + "Models/" + GetFileNameAndExtension(modelName).Replaced(".mesh", ".mdl") + "\"");
-    args.Push("-a");
-    fileSystem.SystemRun(fileSystem.programDir + "OgreImporter", args);
+    if (!fileSystem.FileExists(outFileName))
+    {
+        // Convert .mesh.xml to .mdl
+        Array<String> args;
+        args.Push("\"" + xmlFileName + "\"");
+        args.Push("\"" + outFileName + "\"");
+        args.Push("-a");
+        fileSystem.SystemRun(fileSystem.programDir + "OgreImporter", args);
+    }
 
 
     convertedModels.Push(modelName);
     convertedModels.Push(modelName);
 }
 }
@@ -405,14 +425,13 @@ void ConvertMaterial(const String&in materialName, const String&in filePath, Arr
     }
     }
 
 
     String fileName = filePath + GetFullAssetName(materialName);
     String fileName = filePath + GetFullAssetName(materialName);
-    String outFileName = sceneResourcePath + "Materials/" + GetFileName(materialName) + ".xml";
+    String outFileName = sceneResourcePath + GetOutMaterialName(materialName);
 
 
     if (!fileSystem.FileExists(fileName))
     if (!fileSystem.FileExists(fileName))
         return;
         return;
 
 
     bool mask = false;
     bool mask = false;
     bool twoSided = false;
     bool twoSided = false;
-    bool hasTexture = false;
     String textureName;
     String textureName;
 
 
     File file(fileName, FILE_READ);
     File file(fileName, FILE_READ);
@@ -423,11 +442,11 @@ void ConvertMaterial(const String&in materialName, const String&in filePath, Arr
             mask = true;
             mask = true;
         if (line.StartsWith("cull_hardware none"))
         if (line.StartsWith("cull_hardware none"))
             twoSided = true;
             twoSided = true;
-        if (line.StartsWith("texture ") && !hasTexture)
+        // Todo: handle multiple textures per material
+        if (line.StartsWith("texture ") && textureName.empty)
         {
         {
             textureName = line.Substring(8);
             textureName = line.Substring(8);
             ProcessRef(textureName);
             ProcessRef(textureName);
-            hasTexture = true; // For now handle only the first texture
         }
         }
     }
     }
 
 
@@ -445,15 +464,17 @@ void ConvertMaterial(const String&in materialName, const String&in filePath, Arr
 
 
     if (!textureName.empty)
     if (!textureName.empty)
     {
     {
+        String outTextureName = GetOutTextureName(textureName);
         XMLElement textureElem = rootElem.CreateChild("texture");
         XMLElement textureElem = rootElem.CreateChild("texture");
         textureElem.SetAttribute("unit", "diffuse");
         textureElem.SetAttribute("unit", "diffuse");
-        textureElem.SetAttribute("name", "Textures/" + textureName);
+        textureElem.SetAttribute("name", outTextureName);
 
 
+        // Todo: handle also materials without texture
         File outFile(outFileName, FILE_WRITE);
         File outFile(outFileName, FILE_WRITE);
         outMat.Save(outFile);
         outMat.Save(outFile);
         outFile.Close();
         outFile.Close();
 
 
-        fileSystem.Copy(filePath + GetFullAssetName(textureName), sceneResourcePath + "Textures/" + textureName);
+        fileSystem.Copy(filePath + GetFullAssetName(textureName), sceneResourcePath + outTextureName);
     }
     }
 
 
     convertedMaterials.Push(materialName);
     convertedMaterials.Push(materialName);

+ 1 - 1
Docs/Urho3D.dox

@@ -74,7 +74,7 @@ Urho3D uses the following third-party libraries:
 - stb_image 1.29 (http://nothings.org/)
 - stb_image 1.29 (http://nothings.org/)
 - stb_vorbis 0.99996 (http://nothings.org/)
 - stb_vorbis 0.99996 (http://nothings.org/)
 
 
-DXT / ETC1 / PVRTC decompression code based on the Squish library and the Oolong Engine.
+DXT / ETC1 / PVRTC decompression code based on the Squish library and the Oolong %Engine.
 
 
 Jack and mushroom models from the realXtend project. (http://www.realxtend.org)
 Jack and mushroom models from the realXtend project. (http://www.realxtend.org)