Browse Source

Added AssetImporter option to restore earlier behavior, to flatten scene hierarchy in scene mode.

Lasse Öörni 12 years ago
parent
commit
7fbefe6f43
2 changed files with 33 additions and 4 deletions
  1. 1 0
      Docs/Reference.dox
  2. 32 4
      Source/Tools/AssetImporter/AssetImporter.cpp

+ 1 - 0
Docs/Reference.dox

@@ -1729,6 +1729,7 @@ Options:
 -l          Output a material list file for models
 -l          Output a material list file for models
 -na         Do not output animations
 -na         Do not output animations
 -nm         Do not output materials
 -nm         Do not output materials
+-nh         Do not save full node hierarchy (scene mode only)\n"
 -ns         Do not create subdirectories for resources
 -ns         Do not create subdirectories for resources
 -nz         Do not create a zone and a directional light (scene mode only)
 -nz         Do not create a zone and a directional light (scene mode only)
 -nf         Do not fix infacing normals
 -nf         Do not fix infacing normals

+ 32 - 4
Source/Tools/AssetImporter/AssetImporter.cpp

@@ -104,6 +104,7 @@ bool localIDs_ = false;
 bool saveBinary_ = false;
 bool saveBinary_ = false;
 bool createZone_ = true;
 bool createZone_ = true;
 bool noAnimations_ = false;
 bool noAnimations_ = false;
+bool noHierarchy_ = false;
 bool noMaterials_ = false;
 bool noMaterials_ = false;
 bool saveMaterialList_ = false;
 bool saveMaterialList_ = false;
 bool includeNonSkinningBones_ = false;
 bool includeNonSkinningBones_ = false;
@@ -206,6 +207,7 @@ void Run(const Vector<String>& arguments)
             "-l          Output a material list file for models\n"
             "-l          Output a material list file for models\n"
             "-na         Do not output animations\n"
             "-na         Do not output animations\n"
             "-nm         Do not output materials\n"
             "-nm         Do not output materials\n"
+            "-nh         Do not save full node hierarchy (scene mode only)\n"
             "-ns         Do not create subdirectories for resources\n"
             "-ns         Do not create subdirectories for resources\n"
             "-nz         Do not create a zone and a directional light (scene mode only)\n"
             "-nz         Do not create a zone and a directional light (scene mode only)\n"
             "-nf         Do not fix infacing normals\n"
             "-nf         Do not fix infacing normals\n"
@@ -279,7 +281,11 @@ void Run(const Vector<String>& arguments)
                 case 'm':
                 case 'm':
                     noMaterials_ = true;
                     noMaterials_ = true;
                     break;
                     break;
-                    
+
+                case 'h':
+                    noHierarchy_ = true;
+                    break;
+
                 case 's':
                 case 's':
                     useSubdirs_ = false;
                     useSubdirs_ = false;
                     break;
                     break;
@@ -384,7 +390,13 @@ void Run(const Vector<String>& arguments)
             ExportModel(outFile);
             ExportModel(outFile);
         
         
         if (command == "scene" || command == "node")
         if (command == "scene" || command == "node")
-            ExportScene(outFile, command == "node");
+        {
+            bool asPrefab = command == "node";
+            // Saving as prefab requires the hierarchy, especially the root node
+            if (asPrefab)
+                noHierarchy_ = false;
+            ExportScene(outFile, asPrefab);
+        }
         
         
         if (!noMaterials_)
         if (!noMaterials_)
         {
         {
@@ -1181,6 +1193,19 @@ Node* CreateSceneNode(Scene* scene, aiNode* srcNode, HashMap<aiNode*, Node*>& no
 {
 {
     if (nodeMapping.Contains(srcNode))
     if (nodeMapping.Contains(srcNode))
         return nodeMapping[srcNode];
         return nodeMapping[srcNode];
+    // Flatten hierarchy if requested
+    if (noHierarchy_)
+    {
+        Node* outNode = scene->CreateChild(FromAIString(srcNode->mName), localIDs_ ? LOCAL : REPLICATED);
+        Vector3 pos, scale;
+        Quaternion rot;
+        GetPosRotScale(GetDerivedTransform(srcNode, rootNode_), pos, rot, scale);
+        outNode->SetTransform(pos, rot, scale);
+        nodeMapping[srcNode] = outNode;
+
+        return outNode;
+    }
+
     if (srcNode == rootNode_ || !srcNode->mParent)
     if (srcNode == rootNode_ || !srcNode->mParent)
     {
     {
         Node* outNode = scene->CreateChild(FromAIString(srcNode->mName), localIDs_ ? LOCAL : REPLICATED);
         Node* outNode = scene->CreateChild(FromAIString(srcNode->mName), localIDs_ ? LOCAL : REPLICATED);
@@ -1247,9 +1272,12 @@ void BuildAndSaveScene(OutScene& scene, bool asPrefab)
         }
         }
     }
     }
 
 
-    HashMap<aiNode*, Node*> nodeMapping;
-    Node* outRootNode = CreateSceneNode(outScene, rootNode_, nodeMapping);
     ResourceCache* cache = context_->GetSubsystem<ResourceCache>();
     ResourceCache* cache = context_->GetSubsystem<ResourceCache>();
+
+    HashMap<aiNode*, Node*> nodeMapping;
+    Node* outRootNode = 0;
+    if (asPrefab || !noHierarchy_)
+        outRootNode = CreateSceneNode(outScene, rootNode_, nodeMapping);
     
     
     // Create geometry nodes
     // Create geometry nodes
     for (unsigned i = 0; i < scene.nodes_.Size(); ++i)
     for (unsigned i = 0; i < scene.nodes_.Size(); ++i)