Browse Source

In scene mode, output material lists for all imported models.
Do not apply empty material if a material from a material list can not be found. Instead retain the old.
Fixed outdated documentation.

Lasse Öörni 12 years ago
parent
commit
091fe0b15f

+ 5 - 1
Bin/Data/Scripts/Editor/EditorImport.as

@@ -64,7 +64,11 @@ void ApplyMaterialList(StaticModel@ newModel)
         for (uint i = 0; i < newModel.numGeometries; ++i)
         {
             if (!list.eof)
-                newModel.materials[i] = cache.GetResource("Material", list.ReadLine());
+            {
+                Material@ newMat = cache.GetResource("Material", list.ReadLine());
+                if (newMat !is null)
+                    newModel.materials[i] = newMat;
+            }
             else
                 break;
         }

+ 0 - 2
Docs/GettingStarted.dox

@@ -698,8 +698,6 @@ To create a user variable into the current node, or delete it, type the variable
 
 While editing, you can execute script files using the "Run script" item in the %File menu. These are AngelScript files that are executed in immediate mode ie. you do not need to define a function. The editor's scene will be accessible to the script as the global property "scene."
 
-Automatic resource reloading when changed (for example editing a texture in a paint program while the scene editor is running) is currently supported on Windows only. On other platforms you need to manually reload scene resources (Ctrl+R) after editing to make the changes visible.
-
 Components of same type can be multi-edited. Where attribute values differ, the attribute field will be left blank, but editing the attribute will apply the change to all components.
 
 In addition to whole scenes, single scene nodes including all their components and child nodes can be loaded and saved (%File -> Load node, %File -> Save node as.) These can act as "prefabs" for speeding up scene construction. To save a node, it needs first to be selected in the hierarchy window.

+ 3 - 2
Docs/Reference.dox

@@ -1366,7 +1366,7 @@ Usage:
 AssetImporter <command> <input file> <output file> [options]
 
 Commands:
-model Output a model
+model Output a model and a material list
 scene Output a scene
 dump  Dump scene node structure. No output file is generated
 lod   Combine several Urho3D models as LOD levels of the output model
@@ -1375,7 +1375,6 @@ lod   Combine several Urho3D models as LOD levels of the output model
 Options:
 -b    Save scene in binary format, default format is XML
 -i    Use local ID's for scene nodes
--mX   Output a material list file X (model mode only)
 -na   Do not output animations
 -nm   Do not output materials
 -ns   Do not create subdirectories for resources
@@ -1385,6 +1384,8 @@ Options:
 -t    Generate tangents to model(s)
 \endverbatim
 
+The material list is a text file, one material per line, saved alongside the Urho3D model. It is used by the scene editor to automatically apply the imported default materials when setting a new model for a StaticModel, AnimatedModel or Skybox component. The list files can safely be deleted if not needed, and should not be included in production builds of Urho3D applications.
+
 \section Tools_OgreImporter OgreImporter
 
 Loads OGRE .mesh.xml and .skeleton.xml files and saves them as Urho3D .mdl (model) and .ani (animation) files. For other 3D formats and whole scene importing, see AssetImporter instead. However that tool does not handle the OGRE formats as completely as this.

+ 15 - 15
Tools/AssetImporter/AssetImporter.cpp

@@ -431,20 +431,6 @@ void ExportModel(const String& outName)
         CollectAnimations(model);
         BuildAndSaveAnimations(model);
     }
-    
-    // If exporting materials, also save material list for use by the editor
-    if (!noMaterials_)
-    {
-        String materialListName = ReplaceExtension(model.outName_, ".txt");
-        File listFile(context_);
-        if (listFile.Open(materialListName, FILE_WRITE))
-        {
-            for (unsigned i = 0; i < model.meshes_.Size(); ++i)
-                listFile.WriteLine(GetMeshMaterialName(model.meshes_[i]));
-        }
-        else
-            PrintLine("Warning: could not write material list file " + materialListName);
-    }
 }
 
 void CollectMeshes(OutModel& model, aiNode* node)
@@ -826,6 +812,20 @@ void BuildAndSaveModel(OutModel& model)
     if (!outFile.Open(model.outName_, FILE_WRITE))
         ErrorExit("Could not open output file " + model.outName_);
     outModel->Save(outFile);
+    
+    // If exporting materials, also save material list for use by the editor
+    if (!noMaterials_)
+    {
+        String materialListName = ReplaceExtension(model.outName_, ".txt");
+        File listFile(context_);
+        if (listFile.Open(materialListName, FILE_WRITE))
+        {
+            for (unsigned i = 0; i < model.meshes_.Size(); ++i)
+                listFile.WriteLine(GetMeshMaterialName(model.meshes_[i]));
+        }
+        else
+            PrintLine("Warning: could not write material list file " + materialListName);
+    }
 }
 
 void BuildAndSaveAnimations(OutModel& model)
@@ -986,7 +986,7 @@ void ExportScene(const String& outName)
     
     CollectSceneModels(outScene, rootNode_);
     
-    // Save models
+    // Save models and their material lists
     for (unsigned i = 0; i < outScene.models_.Size(); ++i)
         BuildAndSaveModel(outScene.models_[i]);