Browse Source

Adding prefab support

Josh Engebretson 10 years ago
parent
commit
fd5a98cad0

+ 12 - 0
Data/AtomicEditor/Resources/EditorData/AtomicEditor/typescript/ui/HierarchyFrame.ts

@@ -22,6 +22,10 @@ class HierarchyFrame extends Atomic.UIWidget {
 
 
         hierarchycontainer.addChild(hierList);
         hierarchycontainer.addChild(hierList);
 
 
+        //this.subscribeToEvent("NodeAdded", (data) => this.handleNodeAdded(data));
+
+        this.subscribeToEvent("EditorUpdateHierarchy", (data) => this.handleUpdateHierarchy(data));
+
         this.subscribeToEvent(this, "WidgetEvent", (data) => this.handleWidgetEvent(data));
         this.subscribeToEvent(this, "WidgetEvent", (data) => this.handleWidgetEvent(data));
         this.subscribeToEvent("EditorActiveSceneChanged", (data) => this.handleActiveSceneChanged(data));
         this.subscribeToEvent("EditorActiveSceneChanged", (data) => this.handleActiveSceneChanged(data));
 
 
@@ -30,6 +34,7 @@ class HierarchyFrame extends Atomic.UIWidget {
     recursiveAddNode(parentID: number, node: Atomic.Node) {
     recursiveAddNode(parentID: number, node: Atomic.Node) {
 
 
         var name = node.name;
         var name = node.name;
+
         if (!name.length)
         if (!name.length)
             name = "(Anonymous)"
             name = "(Anonymous)"
 
 
@@ -63,9 +68,16 @@ class HierarchyFrame extends Atomic.UIWidget {
 
 
     }
     }
 
 
+    handleUpdateHierarchy(data) {
+
+        this.refresh();
+
+    }
+
     handleActiveSceneChanged(data) {
     handleActiveSceneChanged(data) {
 
 
         this.scene = <Atomic.Scene> data.scene;
         this.scene = <Atomic.Scene> data.scene;
+
         this.refresh();
         this.refresh();
 
 
     }
     }

+ 1 - 1
Source/Atomic/Resource/ResourceCache.cpp

@@ -566,7 +566,7 @@ Resource* ResourceCache::GetResource(StringHash type, const String& nameIn, bool
     if (!file)
     if (!file)
         return 0;   // Error is already logged
         return 0;   // Error is already logged
 
 
-    //LOGDEBUG("Loading resource " + name);
+    LOGDEBUG("Loading resource " + name);
     resource->SetName(name);
     resource->SetName(name);
 
 
     if (!resource->Load(*(file.Get())))
     if (!resource->Load(*(file.Get())))

+ 1 - 0
Source/AtomicEditorWork/Application/AEEditorApp.cpp

@@ -107,6 +107,7 @@ void AEEditorApp::Setup()
     engineParameters_["WindowResizable"] = true;
     engineParameters_["WindowResizable"] = true;
     engineParameters_["FullScreen"] = false;
     engineParameters_["FullScreen"] = false;
     engineParameters_["LogName"] = filesystem->GetAppPreferencesDir("AtomicEditor", "Logs") + "AtomicEditor.log";
     engineParameters_["LogName"] = filesystem->GetAppPreferencesDir("AtomicEditor", "Logs") + "AtomicEditor.log";
+    engineParameters_["LogLevel"] = LOG_DEBUG;
 
 
 #ifdef ATOMIC_PLATFORM_OSX
 #ifdef ATOMIC_PLATFORM_OSX
     engineParameters_["WindowIcon"] = "Images/AtomicLogo32.png";
     engineParameters_["WindowIcon"] = "Images/AtomicLogo32.png";

+ 64 - 7
Source/AtomicEditorWork/Editors/SceneEditor3D/SceneView3D.cpp

@@ -18,6 +18,7 @@
 
 
 #include <Atomic/Atomic3D/Terrain.h>
 #include <Atomic/Atomic3D/Terrain.h>
 #include <Atomic/Atomic3D/Model.h>
 #include <Atomic/Atomic3D/Model.h>
+#include <Atomic/Atomic3D/AnimationController.h>
 
 
 #include <Atomic/Input/Input.h>
 #include <Atomic/Input/Input.h>
 
 
@@ -32,6 +33,8 @@
 
 
 #include <ToolCore/Assets/Asset.h>
 #include <ToolCore/Assets/Asset.h>
 #include <ToolCore/Assets/AssetDatabase.h>
 #include <ToolCore/Assets/AssetDatabase.h>
+#include <ToolCore/Assets/ModelImporter.h>
+#include <ToolCore/Assets/PrefabImporter.h>
 
 
 #include "AEEditor.h"
 #include "AEEditor.h"
 #include "AEEvents.h"
 #include "AEEvents.h"
@@ -251,7 +254,7 @@ void SceneView3D::HandlePostRenderUpdate(StringHash eventType, VariantMap& event
     // Visualize the currently selected nodes
     // Visualize the currently selected nodes
     if (selectedNode_.NotNull())
     if (selectedNode_.NotNull())
     {
     {
-        DrawNodeDebug(selectedNode_, debugRenderer_);
+        //DrawNodeDebug(selectedNode_, debugRenderer_);
 
 
     }
     }
 
 
@@ -315,8 +318,8 @@ void SceneView3D::HandlePostRenderUpdate(StringHash eventType, VariantMap& event
 
 
             if (r.drawable_)
             if (r.drawable_)
             {
             {
-                debugRenderer_->AddNode(r.drawable_->GetNode(), 1.0, false);
-                r.drawable_->DrawDebugGeometry(debugRenderer_, false);
+                //debugRenderer_->AddNode(r.drawable_->GetNode(), 1.0, false);
+                //r.drawable_->DrawDebugGeometry(debugRenderer_, false);
             }
             }
 
 
         }
         }
@@ -365,6 +368,14 @@ void SceneView3D::HandleUpdate(StringHash eventType, VariantMap& eventData)
             {
             {
                 dragNode_->LoadXML(xml->GetRoot());
                 dragNode_->LoadXML(xml->GetRoot());
                 UpdateDragNode(0, 0);
                 UpdateDragNode(0, 0);
+
+                AnimationController* controller = dragNode_->GetComponent<AnimationController>();
+                if (controller)
+                {
+                    controller->PlayExclusive("Idle", 0, true);
+
+                    dragNode_->GetScene()->SetUpdateEnabled(true);
+                }
             }
             }
 
 
             preloadResourceScene_ = 0;
             preloadResourceScene_ = 0;
@@ -436,26 +447,72 @@ void SceneView3D::HandleDragEnterWidget(StringHash eventType, VariantMap& eventD
 
 
         AssetDatabase* db = GetSubsystem<AssetDatabase>();
         AssetDatabase* db = GetSubsystem<AssetDatabase>();
 
 
-        const String& importer = asset->GetImporterTypeName();
+        AssetImporter* importer = asset->GetImporter();
+
+        if (!importer)
+            return;
+
+        StringHash importerType = importer->GetType();
+
+        if (importerType == PrefabImporter::GetTypeStatic())
+        {
+            dragNode_ = scene_->CreateChild(asset->GetName());
+
+            SharedPtr<File> file(new File(context_, asset->GetPath()));
+            SharedPtr<XMLFile> xml(new XMLFile(context_));
+
+            if (!xml->Load(*file))
+                return;
 
 
-        if (importer == "ModelImporter")
+            dragNode_->LoadXML(xml->GetRoot());
+
+            dragNode_->SetName(asset->GetName());
+
+        }
+        else if (importerType == ModelImporter::GetTypeNameStatic())
         {
         {
             dragNode_ = scene_->CreateChild(asset->GetName());
             dragNode_ = scene_->CreateChild(asset->GetName());
 
 
+            SharedPtr<File> file(new File(context_, asset->GetCachePath()));
+            SharedPtr<XMLFile> xml(new XMLFile(context_));
+
+            if (!xml->Load(*file))
+                return;
+
+            dragNode_->LoadXML(xml->GetRoot());
+            dragNode_->SetName(asset->GetName());
+
+            AnimationController* controller = dragNode_->GetComponent<AnimationController>();
+            if (controller)
+            {
+                controller->PlayExclusive("Idle", 0, true);
+
+                dragNode_->GetScene()->SetUpdateEnabled(true);
+            }
+
+
+            /*
+            dragNode_ = scene_->CreateChild(asset->GetName());            
             preloadResourceScene_ = new Scene(context_);
             preloadResourceScene_ = new Scene(context_);
 
 
-            SharedPtr<File> file(new File(context_, db->GetCachePath() + asset->GetGUID()));
+            SharedPtr<File> file(new File(context_, asset->GetCachePath()));
 
 
             preloadResourceScene_->LoadAsyncXML(file, LOAD_RESOURCES_ONLY);
             preloadResourceScene_->LoadAsyncXML(file, LOAD_RESOURCES_ONLY);
             dragAssetGUID_ = asset->GetGUID();
             dragAssetGUID_ = asset->GetGUID();
+            */
+        }
 
 
+        if (dragNode_.NotNull())
+        {
             Input* input = GetSubsystem<Input>();
             Input* input = GetSubsystem<Input>();
             IntVector2 pos = input->GetMousePosition();
             IntVector2 pos = input->GetMousePosition();
-
             UpdateDragNode(pos.x_, pos.y_);
             UpdateDragNode(pos.x_, pos.y_);
 
 
+            SendEvent("EditorUpdateHierarchy");
         }
         }
 
 
+
+
         //LOGINFOF("Dropped %s : %s on SceneView3D", asset->GetPath().CString(), asset->GetGUID().CString());
         //LOGINFOF("Dropped %s : %s on SceneView3D", asset->GetPath().CString(), asset->GetGUID().CString());
     }
     }
 
 

+ 2 - 1
Source/AtomicJS/Packages/ToolCore/ToolCore.json

@@ -4,7 +4,8 @@
 							 "Source/ToolCore/Import", "Source/ToolCore/Assets"],
 							 "Source/ToolCore/Import", "Source/ToolCore/Assets"],
 	"classes" : ["ToolEnvironment", "ToolSystem", "Project", "ProjectFile", "Platform", "PlatformMac", "PlatformWeb",
 	"classes" : ["ToolEnvironment", "ToolSystem", "Project", "ProjectFile", "Platform", "PlatformMac", "PlatformWeb",
 							 "PlatformWindows", "Command", "PlayCmd", "OpenAssetImporter",
 							 "PlatformWindows", "Command", "PlayCmd", "OpenAssetImporter",
-							 "Asset", "AssetDatabase", "AssetImporter", "ModelImporter", "AnimationImportInfo"],
+							 "Asset", "AssetDatabase", "AssetImporter", "ModelImporter", "AnimationImportInfo",
+							 "PrefabImporter"],
 	"typescript_decl" : {
 	"typescript_decl" : {
 
 
 		"AssetDatabase" : [
 		"AssetDatabase" : [

+ 9 - 0
Source/ToolCore/Assets/Asset.cpp

@@ -9,6 +9,8 @@
 #include "SceneImporter.h"
 #include "SceneImporter.h"
 #include "MaterialImporter.h"
 #include "MaterialImporter.h"
 #include "TextureImporter.h"
 #include "TextureImporter.h"
+#include "PrefabImporter.h"
+
 #include "Asset.h"
 #include "Asset.h"
 
 
 namespace ToolCore
 namespace ToolCore
@@ -29,6 +31,9 @@ Asset::~Asset()
 
 
 bool Asset::CheckCacheFile()
 bool Asset::CheckCacheFile()
 {
 {
+    if (importer_.Null() || !importer_->RequiresCacheFile())
+        return true;
+
     FileSystem* fs = GetSubsystem<FileSystem>();
     FileSystem* fs = GetSubsystem<FileSystem>();
     AssetDatabase* db = GetSubsystem<AssetDatabase>();
     AssetDatabase* db = GetSubsystem<AssetDatabase>();
     String cachePath = db->GetCachePath();
     String cachePath = db->GetCachePath();
@@ -177,6 +182,10 @@ bool Asset::CreateImporter()
         {
         {
             importer_ = new ModelImporter(context_, this);
             importer_ = new ModelImporter(context_, this);
         }
         }
+        else if (ext == ".prefab")
+        {
+            importer_ = new PrefabImporter(context_);
+        }
         else if (ext == ".scene")
         else if (ext == ".scene")
         {
         {
             importer_ = new SceneImporter(context_);
             importer_ = new SceneImporter(context_);

+ 2 - 1
Source/ToolCore/Assets/AssetImporter.cpp

@@ -7,7 +7,8 @@
 namespace ToolCore
 namespace ToolCore
 {
 {
 
 
-AssetImporter::AssetImporter(Context* context) : Object(context)
+AssetImporter::AssetImporter(Context* context) : Object(context),
+    requiresCacheFile_(true)
 {
 {
     SetDefaults();
     SetDefaults();
 }
 }

+ 5 - 1
Source/ToolCore/Assets/AssetImporter.h

@@ -29,9 +29,13 @@ public:
     /// Imports to cached data
     /// Imports to cached data
     virtual bool Import(const String& guid) = 0;
     virtual bool Import(const String& guid) = 0;
 
 
+    bool RequiresCacheFile() const { return requiresCacheFile_; }
+
 protected:
 protected:
 
 
-    JSONValue jsonRoot_;
+    JSONValue jsonRoot_;   
+    bool requiresCacheFile_;
+
 
 
     virtual bool LoadSettingsInternal();
     virtual bool LoadSettingsInternal();
     virtual bool SaveSettingsInternal();
     virtual bool SaveSettingsInternal();

+ 61 - 0
Source/ToolCore/Assets/PrefabImporter.cpp

@@ -0,0 +1,61 @@
+
+#include <Atomic/Resource/ResourceCache.h>
+#include <Atomic/Resource/Image.h>
+
+#include "Asset.h"
+#include "AssetDatabase.h"
+#include "PrefabImporter.h"
+
+namespace ToolCore
+{
+
+PrefabImporter::PrefabImporter(Context* context) : AssetImporter(context)
+{
+    requiresCacheFile_ = false;
+}
+
+PrefabImporter::~PrefabImporter()
+{
+
+}
+
+void PrefabImporter::SetDefaults()
+{
+    AssetImporter::SetDefaults();
+}
+
+bool PrefabImporter::Import(const String& guid)
+{
+    AssetDatabase* db = GetSubsystem<AssetDatabase>();
+    Asset* asset = db->GetAssetByGUID(guid);
+
+    if (!asset)
+        return false;
+
+    ResourceCache* cache = GetSubsystem<ResourceCache>();
+
+    return true;
+}
+
+bool PrefabImporter::LoadSettingsInternal()
+{
+    if (!AssetImporter::LoadSettingsInternal())
+        return false;
+
+    JSONValue import = jsonRoot_.GetChild("PrefabImporter", JSON_OBJECT);
+
+    return true;
+}
+
+bool PrefabImporter::SaveSettingsInternal()
+{
+    if (!AssetImporter::SaveSettingsInternal())
+        return false;
+
+    JSONValue import = jsonRoot_.CreateChild("PrefabImporter");
+
+    return true;
+}
+
+
+}

+ 29 - 0
Source/ToolCore/Assets/PrefabImporter.h

@@ -0,0 +1,29 @@
+
+#pragma once
+
+#include "AssetImporter.h"
+
+namespace ToolCore
+{
+
+class PrefabImporter : public AssetImporter
+{
+    OBJECT(PrefabImporter);
+
+public:
+    /// Construct.
+    PrefabImporter(Context* context);
+    virtual ~PrefabImporter();
+
+    virtual void SetDefaults();
+
+    bool Import(const String& guid);
+
+protected:
+
+    virtual bool LoadSettingsInternal();
+    virtual bool SaveSettingsInternal();
+
+};
+
+}