Browse Source

WIP mdl model support

Josh Engebretson 10 years ago
parent
commit
671a37b2e7

+ 2 - 1
Script/AtomicEditor/ui/frames/inspector/CreateComponentButton.ts

@@ -23,7 +23,8 @@ _2DCreateSource.addItem(new Atomic.UIMenuItem("TileMap2D", "TileMap2D"));
 var geometryCreateSource = new Atomic.UIMenuItemSource();
 
 geometryCreateSource.addItem(new Atomic.UIMenuItem("StaticModel", "StaticModel"));
-geometryCreateSource.addItem(new Atomic.UIMenuItem("AnimatedModel", "create component"));
+geometryCreateSource.addItem(new Atomic.UIMenuItem("AnimatedModel", "AnimatedModel"));
+geometryCreateSource.addItem(new Atomic.UIMenuItem("AnimationController", "AnimationController"));
 geometryCreateSource.addItem(new Atomic.UIMenuItem("BillboardSet", "create component"));
 geometryCreateSource.addItem(new Atomic.UIMenuItem("CustomGeometry", "create component"));
 geometryCreateSource.addItem(new Atomic.UIMenuItem("ParticleEmitter", "create component"));

+ 1 - 1
Source/ToolCore/Assets/Asset.cpp

@@ -245,7 +245,7 @@ bool Asset::CreateImporter()
         textureFormats.Push(".dds");
 
         // todo, externalize recognizers
-        if (ext == ".fbx" || ext == ".blend" || ext == ".dae")
+        if (ext == ".fbx" || ext == ".blend" || ext == ".dae" || ext == ".mdl")
         {
             importer_ = new ModelImporter(context_, this);
         }

+ 45 - 7
Source/ToolCore/Assets/ModelImporter.cpp

@@ -7,6 +7,7 @@
 
 #include <Atomic/Atomic3D/AnimationController.h>
 #include <Atomic/Atomic3D/Animation.h>
+#include <Atomic/Atomic3D/StaticModel.h>
 #include <Atomic/Atomic3D/Model.h>
 
 #include <Atomic/Resource/ResourceCache.h>
@@ -43,9 +44,12 @@ void ModelImporter::SetDefaults()
 
 bool ModelImporter::ImportModel()
 {
+
+    LOGDEBUGF("Importing Model: %s", asset_->GetPath().CString());
+
     SharedPtr<OpenAssetImporter> importer(new OpenAssetImporter(context_));
 
-    //importer->SetVerboseLog(true);
+    importer->SetVerboseLog(true);
 
     importer->SetScale(scale_);
     importer->SetExportAnimations(false);
@@ -183,22 +187,56 @@ bool ModelImporter::ImportAnimations()
 
 bool ModelImporter::Import()
 {
+
+    String ext = asset_->GetExtension();
     String modelAssetFilename = asset_->GetPath();
 
     importNode_ = new Node(context_);
 
-    // skip external animations, they will be brought in when importing their
-    // corresponding model
-    if (!modelAssetFilename.Contains("@"))
+    if (ext == ".mdl")
     {
-        ImportModel();
+        FileSystem* fs = GetSubsystem<FileSystem>();
+        ResourceCache* cache = GetSubsystem<ResourceCache>();
+
+        // mdl files are native file format that doesn't need to be converted
+        // doesn't allow scale, animations legacy primarily for ToonTown
+
+        if (!fs->Copy(asset_->GetPath(), asset_->GetCachePath() + ".mdl"))
+        {
+            importNode_= 0;
+            return false;
+        }
 
-        if (importAnimations_)
+        Model* mdl = cache->GetResource<Model>( asset_->GetCachePath() + ".mdl");
+
+        if (!mdl)
         {
-            ImportAnimations();
+            importNode_= 0;
+            return false;
         }
 
+        // Force a reload, though file watchers will catch this delayed and load again
+        cache->ReloadResource(mdl);
+
+        importNode_->CreateComponent<StaticModel>()->SetModel(mdl);
     }
+    else
+    {
+        // skip external animations, they will be brought in when importing their
+        // corresponding model
+        if (!modelAssetFilename.Contains("@"))
+        {
+            ImportModel();
+
+            if (importAnimations_)
+            {
+                //ImportAnimations();
+            }
+
+        }
+
+    }
+
 
     File outFile(context_);