Browse Source

More work on inspector resource refs

Josh Engebretson 10 years ago
parent
commit
86b431aa6c

+ 31 - 10
Script/AtomicEditor/ui/frames/inspector/DataBinding.ts

@@ -176,11 +176,21 @@ class DataBinding {
 
 
                     EditorUI.getModelOps().showResourceSelection("Select " + attrInfo.resourceTypeName + " Resource", importerName, function(asset: ToolCore.Asset) {
                     EditorUI.getModelOps().showResourceSelection("Select " + attrInfo.resourceTypeName + " Resource", importerName, function(asset: ToolCore.Asset) {
 
 
-                        var resource = Atomic.cache.getResource(attrInfo.resourceTypeName, asset.path);
+                        var resource = asset.resource;
 
 
                         object.setAttribute(attrInfo.name, resource);
                         object.setAttribute(attrInfo.name, resource);
-                        if (resource)
-                            o.editField.text = resource.name;
+
+                        if (resource) {
+
+                            // use the asset name instead of the cache name
+                            if (asset.importer.requiresCacheFile())
+                                o.editField.text = asset.name;
+                            else
+                                o.editField.text = resource.name;
+                        }
+                        else
+                            o.editField.text = "";
+
 
 
                     });
                     });
 
 
@@ -207,10 +217,17 @@ class DataBinding {
 
 
                         if (importer) {
                         if (importer) {
 
 
-                            var resource = Atomic.cache.getResource(attrInfo.resourceTypeName, importer.asset.path);
+                            var resource = asset.resource;
                             object.setAttribute(attrInfo.name, resource);
                             object.setAttribute(attrInfo.name, resource);
-                            if (resource)
-                                o.editField.text = resource.name;
+                            if (resource) {
+                                // use the asset name instead of the cache name
+                                if (asset.importer.requiresCacheFile())
+                                    o.editField.text = asset.name;
+                                else
+                                    o.editField.text = resource.name;
+                            }
+                            else
+                                o.editField.text = "";
 
 
                         }
                         }
                     }
                     }
@@ -315,12 +332,16 @@ class DataBinding {
 
 
         } else if (attrInfo.type == Atomic.VAR_RESOURCEREF && attrInfo.resourceTypeName) {
         } else if (attrInfo.type == Atomic.VAR_RESOURCEREF && attrInfo.resourceTypeName) {
 
 
+            // for cached resources, use the asset name, otherwise use the resource path name
             var resource = <Atomic.Resource> object.getAttribute(attrInfo.name);
             var resource = <Atomic.Resource> object.getAttribute(attrInfo.name);
+            var text = "";
+            if (resource) {
+                text = resource.name;
+                var asset = ToolCore.assetDatabase.getAssetByCachePath(resource.name);
+                text = asset.name;
+            }
 
 
-            if (resource)
-                widget["editField"].text = resource.name;
-            else
-                widget["editField"].text = "";
+            widget["editField"].text = text;
 
 
         }
         }
 
 

+ 6 - 0
Script/TypeScript/ToolCore.d.ts

@@ -245,6 +245,7 @@ declare module ToolCore {
       extension: string;
       extension: string;
       relativePath: string;
       relativePath: string;
       cachePath: string;
       cachePath: string;
+      resource: Atomic.Resource;
       importerType: string;
       importerType: string;
       importerTypeName: string;
       importerTypeName: string;
       importer: AssetImporter;
       importer: AssetImporter;
@@ -266,6 +267,7 @@ declare module ToolCore {
       // Get the path relative to project
       // Get the path relative to project
       getRelativePath(): string;
       getRelativePath(): string;
       getCachePath(): string;
       getCachePath(): string;
+      getResource(): Atomic.Resource;
       getImporterType(): string;
       getImporterType(): string;
       getImporterTypeName(): string;
       getImporterTypeName(): string;
       getImporter(): AssetImporter;
       getImporter(): AssetImporter;
@@ -309,6 +311,7 @@ declare module ToolCore {
    export class AssetImporter extends Atomic.AObject {
    export class AssetImporter extends Atomic.AObject {
 
 
       asset: Asset;
       asset: Asset;
+      resource: Atomic.Resource;
 
 
       // Construct.
       // Construct.
       constructor(asset: Asset);
       constructor(asset: Asset);
@@ -316,6 +319,7 @@ declare module ToolCore {
       setDefaults(): void;
       setDefaults(): void;
       preload(): boolean;
       preload(): boolean;
       getAsset(): Asset;
       getAsset(): Asset;
+      getResource(): Atomic.Resource;
       requiresCacheFile(): boolean;
       requiresCacheFile(): boolean;
 
 
    }
    }
@@ -371,6 +375,7 @@ declare module ToolCore {
       scale: number;
       scale: number;
       importAnimations: boolean;
       importAnimations: boolean;
       animationCount: number;
       animationCount: number;
+      resource: Atomic.Resource;
 
 
       // Construct.
       // Construct.
       constructor(asset: Asset);
       constructor(asset: Asset);
@@ -382,6 +387,7 @@ declare module ToolCore {
       setImportAnimations(importAnimations: boolean): void;
       setImportAnimations(importAnimations: boolean): void;
       getAnimationCount(): number;
       getAnimationCount(): number;
       setAnimationCount(count: number): void;
       setAnimationCount(count: number): void;
+      getResource(): Atomic.Resource;
       getAnimationInfo(index: number): AnimationImportInfo;
       getAnimationInfo(index: number): AnimationImportInfo;
 
 
    }
    }

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

@@ -343,4 +343,12 @@ bool Asset::SetPath(const String& path)
 
 
 }
 }
 
 
+Resource* Asset::GetResource()
+{
+    if (importer_)
+        return importer_->GetResource();
+
+    return 0;
+}
+
 }
 }

+ 3 - 0
Source/ToolCore/Assets/Asset.h

@@ -2,6 +2,7 @@
 #pragma once
 #pragma once
 
 
 #include <Atomic/Core/Object.h>
 #include <Atomic/Core/Object.h>
+#include <Atomic/Resource/Resource.h>
 
 
 #include "AssetImporter.h"
 #include "AssetImporter.h"
 
 
@@ -37,6 +38,8 @@ public:
     String GetRelativePath();
     String GetRelativePath();
     String GetCachePath() const;
     String GetCachePath() const;
 
 
+    Resource* GetResource();
+
     const StringHash GetImporterType() { return importer_.Null() ? String::EMPTY : importer_->GetType(); }
     const StringHash GetImporterType() { return importer_.Null() ? String::EMPTY : importer_->GetType(); }
     const String& GetImporterTypeName() { return importer_.Null() ? String::EMPTY : importer_->GetTypeName(); }
     const String& GetImporterTypeName() { return importer_.Null() ? String::EMPTY : importer_->GetTypeName(); }
 
 

+ 1 - 0
Source/ToolCore/Assets/AssetDatabase.cpp

@@ -484,6 +484,7 @@ String AssetDatabase::GetResourceImporterName(const String& resourceTypeName)
     if (resourceTypeToImporterType_.Empty())
     if (resourceTypeToImporterType_.Empty())
     {
     {
         resourceTypeToImporterType_["Sound"] = "AudioImporter";
         resourceTypeToImporterType_["Sound"] = "AudioImporter";
+        resourceTypeToImporterType_["Model"] = "ModelImporter";
     }
     }
 
 
     if (!resourceTypeToImporterType_.Contains(resourceTypeName))
     if (!resourceTypeToImporterType_.Contains(resourceTypeName))

+ 2 - 0
Source/ToolCore/Assets/AssetImporter.h

@@ -34,6 +34,8 @@ public:
 
 
     Asset* GetAsset() { return asset_; }
     Asset* GetAsset() { return asset_; }
 
 
+    virtual Resource* GetResource() { return 0; }
+
     bool RequiresCacheFile() const { return requiresCacheFile_; }
     bool RequiresCacheFile() const { return requiresCacheFile_; }
 
 
 protected:
 protected:

+ 11 - 0
Source/ToolCore/Assets/ModelImporter.cpp

@@ -7,6 +7,7 @@
 
 
 #include <Atomic/Atomic3D/AnimationController.h>
 #include <Atomic/Atomic3D/AnimationController.h>
 #include <Atomic/Atomic3D/Animation.h>
 #include <Atomic/Atomic3D/Animation.h>
+#include <Atomic/Atomic3D/Model.h>
 
 
 #include <Atomic/Resource/ResourceCache.h>
 #include <Atomic/Resource/ResourceCache.h>
 
 
@@ -294,5 +295,15 @@ bool ModelImporter::SaveSettingsInternal()
     return true;
     return true;
 }
 }
 
 
+Resource* ModelImporter::GetResource()
+{
+    ResourceCache* cache = GetSubsystem<ResourceCache>();
+
+    Model* model = cache->GetResource<Model>(asset_->GetCachePath() + ".mdl");
+
+    return model;
+
+}
+
 
 
 }
 }

+ 2 - 0
Source/ToolCore/Assets/ModelImporter.h

@@ -63,6 +63,8 @@ public:
     unsigned GetAnimationCount();
     unsigned GetAnimationCount();
     void SetAnimationCount(unsigned count);
     void SetAnimationCount(unsigned count);
 
 
+    Resource* GetResource();
+
     AnimationImportInfo* GetAnimationInfo(unsigned index) { return animationInfo_[index]; }
     AnimationImportInfo* GetAnimationInfo(unsigned index) { return animationInfo_[index]; }
 
 
 protected:
 protected: