Browse Source

Added support for shaders and techniques to be recognized and used within a Project

JohnnyWahib 9 years ago
parent
commit
cc4e8afa85

+ 15 - 0
Script/AtomicEditor/ui/frames/MainFrame.ts

@@ -68,6 +68,19 @@ class MainFrame extends ScriptWidget {
         this.subscribeToEvent("ProjectLoaded", (data) => {
         this.subscribeToEvent("ProjectLoaded", (data) => {
             this.showWelcomeFrame(false);
             this.showWelcomeFrame(false);
             this.enableProjectMenus();
             this.enableProjectMenus();
+
+        this.resourcePath = ToolCore.toolSystem.project.getResourcePath();
+        this.resourceCache = Atomic.getResourceCache();
+
+        //Check if a 'Techniques' folder exists within a project, if so, add it to ResourceCache Directory
+        if (Atomic.fileSystem.dirExists(this.resourcePath + "Techniques")){
+            this.resourceCache.addResourceDir(this.resourcePath + "Techniques");
+        }
+        //Check if a 'Shaders' folder exists within a project, if so, add it to ResourceCache Directory
+        if (Atomic.fileSystem.dirExists(this.resourcePath + "Shaders")) {
+            this.resourceCache.addResourceDir(this.resourcePath + "Shaders");
+        }
+
         });
         });
 
 
         this.subscribeToEvent(EditorEvents.ProjectUnloadedNotification, (data) => {
         this.subscribeToEvent(EditorEvents.ProjectUnloadedNotification, (data) => {
@@ -188,6 +201,8 @@ class MainFrame extends ScriptWidget {
     inspectorlayout: Atomic.UILayout;
     inspectorlayout: Atomic.UILayout;
     mainToolbar: MainToolbar;
     mainToolbar: MainToolbar;
     menu: MainFrameMenu;
     menu: MainFrameMenu;
+    resourceCache: Atomic.ResourceCache;
+    resourcePath: String;
 
 
 }
 }
 
 

+ 1 - 1
Script/AtomicEditor/ui/frames/ResourceFrame.ts

@@ -98,7 +98,7 @@ class ResourceFrame extends ScriptWidget {
 
 
         var editor: Editor.ResourceEditor = null;
         var editor: Editor.ResourceEditor = null;
 
 
-        if (ext == ".js" || ext == ".txt" || ext == ".json" || ext == ".ts") {
+        if (ext == ".js" || ext == ".txt" || ext == ".json" || ext == ".ts" || ext == ".xml" || ext == ".hlsl") {
 
 
             editor = new Editor.JSResourceEditor(path, this.tabcontainer);
             editor = new Editor.JSResourceEditor(path, this.tabcontainer);
 
 

+ 47 - 23
Script/AtomicEditor/ui/frames/inspector/MaterialInspector.ts

@@ -51,6 +51,8 @@ var lightmapSource = new Atomic.UIMenuItemSource();
 lightmapSource.addItem(new Atomic.UIMenuItem("Lightmap", "Lightmap"));
 lightmapSource.addItem(new Atomic.UIMenuItem("Lightmap", "Lightmap"));
 lightmapSource.addItem(new Atomic.UIMenuItem("Lightmap Alpha", "Lightmap Alpha"));
 lightmapSource.addItem(new Atomic.UIMenuItem("Lightmap Alpha", "Lightmap Alpha"));
 
 
+var projectSource = new Atomic.UIMenuItemSource();
+
 var _ = new Atomic.UIMenuItem("Solid");
 var _ = new Atomic.UIMenuItem("Solid");
 _.subSource = solidSource;
 _.subSource = solidSource;
 techniqueSource.addItem(_);
 techniqueSource.addItem(_);
@@ -63,6 +65,10 @@ _ = new Atomic.UIMenuItem("Lightmap");
 _.subSource = lightmapSource;
 _.subSource = lightmapSource;
 techniqueSource.addItem(_);
 techniqueSource.addItem(_);
 
 
+_ = new Atomic.UIMenuItem("Project");
+_.subSource = projectSource;
+techniqueSource.addItem(_);
+
 var techniqueLookup = {
 var techniqueLookup = {
     "Techniques/Diff.xml": "Diffuse",
     "Techniques/Diff.xml": "Diffuse",
     "Techniques/DiffEmissive.xml": "Diffuse Emissive",
     "Techniques/DiffEmissive.xml": "Diffuse Emissive",
@@ -80,6 +86,8 @@ var techniqueLookup = {
 
 
 var techniqueReverseLookup = {};
 var techniqueReverseLookup = {};
 
 
+var projectTechniques = {};
+
 for (var key in techniqueLookup) {
 for (var key in techniqueLookup) {
 
 
     techniqueReverseLookup[techniqueLookup[key]] = key;
     techniqueReverseLookup[techniqueLookup[key]] = key;
@@ -144,11 +152,11 @@ class MaterialInspector extends ScriptWidget {
             field.id = params[i].name;
             field.id = params[i].name;
             field.text = params[i].valueString;
             field.text = params[i].valueString;
 
 
-            field.subscribeToEvent(field, "WidgetEvent", function(ev: Atomic.UIWidgetEvent) {
+            field.subscribeToEvent(field, "WidgetEvent", function (ev: Atomic.UIWidgetEvent) {
 
 
                 if (ev.type == Atomic.UI_EVENT_TYPE_CHANGED) {
                 if (ev.type == Atomic.UI_EVENT_TYPE_CHANGED) {
 
 
-                    var field = <Atomic.UIEditField> ev.target;
+                    var field = <Atomic.UIEditField>ev.target;
                     this.material.setShaderParameter(field.id, field.text);
                     this.material.setShaderParameter(field.id, field.text);
 
 
                 }
                 }
@@ -181,7 +189,7 @@ class MaterialInspector extends ScriptWidget {
         var thumbnail = asset.cachePath + "_thumbnail.png";
         var thumbnail = asset.cachePath + "_thumbnail.png";
         var cache = Atomic.getResourceCache();
         var cache = Atomic.getResourceCache();
 
 
-        var thumb = <Atomic.Texture2D> cache.getTempResource("Texture2D", thumbnail);
+        var thumb = <Atomic.Texture2D>cache.getTempResource("Texture2D", thumbnail);
 
 
         if (thumb)
         if (thumb)
             return thumb;
             return thumb;
@@ -195,17 +203,22 @@ class MaterialInspector extends ScriptWidget {
         this.techniqueButton.text = techniqueName;
         this.techniqueButton.text = techniqueName;
 
 
         var cache = Atomic.getResourceCache();
         var cache = Atomic.getResourceCache();
-        var technique = <Atomic.Technique> cache.getResource("Technique", techniqueReverseLookup[techniqueName]);
-        this.material.setTechnique(0, technique);
+        var technique = <Atomic.Technique>cache.getResource("Technique", techniqueReverseLookup[techniqueName]);
+
+        if (technique == null)
+            technique = <Atomic.Technique>cache.getResource("Technique", techniqueName + ".xml");
 
 
+        this.material.setTechnique(0, technique);
     }
     }
 
 
     createTechniquePopup(): Atomic.UIWidget {
     createTechniquePopup(): Atomic.UIWidget {
 
 
+        this.loadProjectTechniques();
+
         var button = this.techniqueButton = new Atomic.UIButton();
         var button = this.techniqueButton = new Atomic.UIButton();
         var technique = this.material.getTechnique(0);
         var technique = this.material.getTechnique(0);
 
 
-        button.text = techniqueLookup[technique.name];
+        button.text = technique.name;
 
 
         button.fontDescription = this.fd;
         button.fontDescription = this.fd;
 
 
@@ -213,14 +226,14 @@ class MaterialInspector extends ScriptWidget {
         lp.width = 140;
         lp.width = 140;
         button.layoutParams = lp;
         button.layoutParams = lp;
 
 
-        button.onClick = function() {
+        button.onClick = function () {
 
 
             var menu = new Atomic.UIMenuWindow(button, "technique popup");
             var menu = new Atomic.UIMenuWindow(button, "technique popup");
 
 
             menu.fontDescription = this.fd;
             menu.fontDescription = this.fd;
             menu.show(techniqueSource);
             menu.show(techniqueSource);
 
 
-            button.subscribeToEvent(button, "WidgetEvent", function(ev: Atomic.UIWidgetEvent) {
+            button.subscribeToEvent(button, "WidgetEvent", function (ev: Atomic.UIWidgetEvent) {
 
 
                 if (ev.type != Atomic.UI_EVENT_TYPE_CLICK)
                 if (ev.type != Atomic.UI_EVENT_TYPE_CLICK)
                     return;
                     return;
@@ -245,7 +258,7 @@ class MaterialInspector extends ScriptWidget {
 
 
         if (dragObject.object && dragObject.object.typeName == "Asset") {
         if (dragObject.object && dragObject.object.typeName == "Asset") {
 
 
-            var asset = <ToolCore.Asset> dragObject.object;
+            var asset = <ToolCore.Asset>dragObject.object;
 
 
             if (asset.importerTypeName == importerTypeName) {
             if (asset.importerTypeName == importerTypeName) {
                 return asset.importer;
                 return asset.importer;
@@ -277,8 +290,8 @@ class MaterialInspector extends ScriptWidget {
 
 
     }
     }
 
 
-     // Big Texture Button(referenced texture file path in project frame)
-    createTextureButtonCallback(textureUnit:number, textureWidget:Atomic.UITextureWidget) {
+    // Big Texture Button(referenced texture file path in project frame)
+    createTextureButtonCallback(textureUnit: number, textureWidget: Atomic.UITextureWidget) {
 
 
         return () => {
         return () => {
 
 
@@ -290,13 +303,13 @@ class MaterialInspector extends ScriptWidget {
                 this.openTextureSelectionBox(textureUnit, textureWidget);
                 this.openTextureSelectionBox(textureUnit, textureWidget);
             }
             }
 
 
-        return true;
+            return true;
 
 
-      };
+        };
 
 
     }
     }
 
 
-   // Small Texture Button (Opens texture selection window)
+    // Small Texture Button (Opens texture selection window)
     createTextureReferenceButtonCallback(textureUnit: number, textureWidget: Atomic.UITextureWidget) {
     createTextureReferenceButtonCallback(textureUnit: number, textureWidget: Atomic.UITextureWidget) {
 
 
         return () => {
         return () => {
@@ -310,11 +323,11 @@ class MaterialInspector extends ScriptWidget {
     //Remove Texture Button
     //Remove Texture Button
     createTextureRemoveButtonCallback(textureUnit: number, textureWidget: Atomic.UITextureWidget) {
     createTextureRemoveButtonCallback(textureUnit: number, textureWidget: Atomic.UITextureWidget) {
 
 
-            var texture = this.material.getTexture(textureUnit);
+        var texture = this.material.getTexture(textureUnit);
 
 
-            if (texture != null && textureWidget != null) {
-                textureWidget.setTexture(null);
-            }
+        if (texture != null && textureWidget != null) {
+            textureWidget.setTexture(null);
+        }
 
 
     }
     }
 
 
@@ -333,7 +346,7 @@ class MaterialInspector extends ScriptWidget {
         section.contentRoot.addChild(attrsVerticalLayout);
         section.contentRoot.addChild(attrsVerticalLayout);
 
 
         // TODO: Filter on technique
         // TODO: Filter on technique
-        var textureUnits = [ Atomic.TU_DIFFUSE, Atomic.TU_NORMAL, Atomic.TU_SPECULAR, Atomic.TU_EMISSIVE ];
+        var textureUnits = [Atomic.TU_DIFFUSE, Atomic.TU_NORMAL, Atomic.TU_SPECULAR, Atomic.TU_EMISSIVE];
 
 
         for (var i in textureUnits) {
         for (var i in textureUnits) {
 
 
@@ -389,10 +402,10 @@ class MaterialInspector extends ScriptWidget {
 
 
                 if (importer) {
                 if (importer) {
 
 
-                    var textureImporter = <ToolCore.TextureImporter> importer;
+                    var textureImporter = <ToolCore.TextureImporter>importer;
                     var asset = textureImporter.asset;
                     var asset = textureImporter.asset;
 
 
-                    var texture = <Atomic.Texture2D> Atomic.cache.getResource("Texture2D", asset.path);
+                    var texture = <Atomic.Texture2D>Atomic.cache.getResource("Texture2D", asset.path);
 
 
                     if (texture) {
                     if (texture) {
 
 
@@ -410,9 +423,20 @@ class MaterialInspector extends ScriptWidget {
 
 
     }
     }
 
 
+    loadProjectTechniques() {
+
+        projectSource.clear();
+        var resourcePath = ToolCore.toolSystem.project.getResourcePath();
+        var TechniqueAssets = ToolCore.getAssetDatabase().getFolderAssets(resourcePath + "Techniques");
 
 
+        for (var key in TechniqueAssets) {
+            projectTechniques[key] = TechniqueAssets[key].name;
+            projectSource.addItem(new Atomic.UIMenuItem(projectTechniques[key], projectTechniques[key]));
+        }
+    }
 
 
     inspect(asset: ToolCore.Asset, material: Atomic.Material) {
     inspect(asset: ToolCore.Asset, material: Atomic.Material) {
+        // Add folders to resource directory
 
 
         this.asset = asset;
         this.asset = asset;
         this.material = material;
         this.material = material;
@@ -499,9 +523,9 @@ class MaterialInspector extends ScriptWidget {
         button.gravity = Atomic.UI_GRAVITY_RIGHT;
         button.gravity = Atomic.UI_GRAVITY_RIGHT;
         button.text = "Save";
         button.text = "Save";
 
 
-        button.onClick = function() {
+        button.onClick = function () {
 
 
-            var importer = <ToolCore.MaterialImporter> this.asset.getImporter();
+            var importer = <ToolCore.MaterialImporter>this.asset.getImporter();
             importer.saveMaterial();
             importer.saveMaterial();
 
 
         }.bind(this);
         }.bind(this);

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

@@ -318,7 +318,7 @@ bool Asset::CreateImporter()
         {
         {
             importer_ = new ParticleEffectImporter(context_, this);
             importer_ = new ParticleEffectImporter(context_, this);
         }
         }
-        else if (ext == ".txt")
+        else if (ext == ".txt" || ext == ".xml" || ext == ".hlsl" || ext == ".glsl")
         {
         {
             importer_ = new TextImporter(context_, this);
             importer_ = new TextImporter(context_, this);
         }
         }