Browse Source

Merge pull request #793 from LumaDigital/ProjectTechniquesAndShaders

Project techniques and shaders
JoshEngebretson 9 years ago
parent
commit
f98f1c98ff

+ 4 - 0
Script/AtomicEditor/ui/ResourceEditorProvider.ts

@@ -26,6 +26,8 @@ import Scene3dResourceEditorBuilder from "./resourceEditors/Scene3dResourceEdito
 import TextFileResourceEditorBuilder from "./resourceEditors/TextFileResourceEditorBuilder";
 import TextFileResourceEditorBuilder from "./resourceEditors/TextFileResourceEditorBuilder";
 import TurboBadgerResourceEditorBuilder from "./resourceEditors/TurboBadgerResourceEditorBuilder";
 import TurboBadgerResourceEditorBuilder from "./resourceEditors/TurboBadgerResourceEditorBuilder";
 import TypescriptResourceEditorBuilder from "./resourceEditors/TypescriptResourceEditorBuilder";
 import TypescriptResourceEditorBuilder from "./resourceEditors/TypescriptResourceEditorBuilder";
+import XMLResourceEditorBuilder from "./resourceEditors/XMLResourceEditorBuilder";
+import ShaderResourceEditorBuilder from "./resourceEditors/ShaderResourceEditorBuilder";
 
 
 export default class ResourceEditorProvider {
 export default class ResourceEditorProvider {
     private standardEditorRegistry: Editor.Extensions.ResourceEditorBuilder[] = [];
     private standardEditorRegistry: Editor.Extensions.ResourceEditorBuilder[] = [];
@@ -88,6 +90,8 @@ export default class ResourceEditorProvider {
         this.registerStandardEditor(new JsonResourceEditorBuilder());
         this.registerStandardEditor(new JsonResourceEditorBuilder());
         this.registerStandardEditor(new TypescriptResourceEditorBuilder());
         this.registerStandardEditor(new TypescriptResourceEditorBuilder());
         this.registerStandardEditor(new Scene3dResourceEditorBuilder());
         this.registerStandardEditor(new Scene3dResourceEditorBuilder());
+        this.registerStandardEditor(new XMLResourceEditorBuilder());
+        this.registerStandardEditor(new ShaderResourceEditorBuilder());
 
 
         // this overrides the test resource editor so need to put it in the custom bucket
         // this overrides the test resource editor so need to put it in the custom bucket
         this.registerCustomEditor(new TurboBadgerResourceEditorBuilder());
         this.registerCustomEditor(new TurboBadgerResourceEditorBuilder());

+ 131 - 40
Script/AtomicEditor/ui/frames/inspector/MaterialInspector.ts

@@ -51,17 +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 _ = new Atomic.UIMenuItem("Solid");
-_.subSource = solidSource;
-techniqueSource.addItem(_);
-
-_ = new Atomic.UIMenuItem("Transparency");
-_.subSource = tranSource;
-techniqueSource.addItem(_);
-
-_ = new Atomic.UIMenuItem("Lightmap");
-_.subSource = lightmapSource;
-techniqueSource.addItem(_);
+var projectSource = new Atomic.UIMenuItemSource();
+var _ = new Atomic.UIMenuItem();
 
 
 var techniqueLookup = {
 var techniqueLookup = {
     "Techniques/Diff.xml": "Diffuse",
     "Techniques/Diff.xml": "Diffuse",
@@ -79,6 +70,8 @@ var techniqueLookup = {
 };
 };
 
 
 var techniqueReverseLookup = {};
 var techniqueReverseLookup = {};
+var projectTechniques = {};
+var projectTechniquesAddress = {};
 
 
 for (var key in techniqueLookup) {
 for (var key in techniqueLookup) {
 
 
@@ -86,7 +79,6 @@ for (var key in techniqueLookup) {
 
 
 }
 }
 
 
-
 class MaterialInspector extends ScriptWidget {
 class MaterialInspector extends ScriptWidget {
 
 
     currentTexture: Atomic.UITextureWidget = null;
     currentTexture: Atomic.UITextureWidget = null;
@@ -101,6 +93,7 @@ class MaterialInspector extends ScriptWidget {
         this.fd.size = 11;
         this.fd.size = 11;
 
 
         this.subscribeToEvent(EditorEvents.RemoveCurrentAssetAssigned, (ev: EditorEvents.RemoveCurrentAssetAssignedEvent) => this.createTextureRemoveButtonCallback(this.tunit, this.textureWidget));
         this.subscribeToEvent(EditorEvents.RemoveCurrentAssetAssigned, (ev: EditorEvents.RemoveCurrentAssetAssignedEvent) => this.createTextureRemoveButtonCallback(this.tunit, this.textureWidget));
+        this.subscribeToEvent("ResourceAdded", (ev: ToolCore.ResourceAddedEvent) => this.refreshTechniquesPopup());
     }
     }
 
 
     createShaderParametersSection(): Atomic.UISection {
     createShaderParametersSection(): Atomic.UISection {
@@ -144,11 +137,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);
 
 
                 }
                 }
@@ -160,12 +153,8 @@ class MaterialInspector extends ScriptWidget {
             attrsVerticalLayout.addChild(attrLayout);
             attrsVerticalLayout.addChild(attrLayout);
 
 
             // print(params[i].name, " : ", params[i].value, " : ", params[i].type);
             // print(params[i].name, " : ", params[i].value, " : ", params[i].type);
-
         }
         }
-
-
         return section;
         return section;
-
     }
     }
 
 
     getTextureThumbnail(texture: Atomic.Texture): Atomic.Texture {
     getTextureThumbnail(texture: Atomic.Texture): Atomic.Texture {
@@ -181,7 +170,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 +184,39 @@ 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]);
+        var resourcePath = ToolCore.toolSystem.project.getResourcePath();
 
 
+        if (technique == null) {
+            var techniquePath = "";
+
+            for (var i in projectTechniques) {
+                if (techniqueName == projectTechniques[i]) {
+                    techniquePath = projectTechniquesAddress[i];
+                    break;
+                }
+            }
+            techniquePath = techniquePath.replace(resourcePath, "");
+            technique = <Atomic.Technique>cache.getResource("Technique", techniquePath);
+        }
+        this.material.setTechnique(0, technique);
     }
     }
 
 
     createTechniquePopup(): Atomic.UIWidget {
     createTechniquePopup(): Atomic.UIWidget {
 
 
+        this.refreshTechniquesPopup();
+
         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);
+        var techniqueName = "";
 
 
-        button.text = techniqueLookup[technique.name];
+        if (technique != null) {
+            techniqueName = technique.name.replace("Techniques/", "").replace(".xml", "");
+        } else {
+            techniqueName = "UNDEFINED";
+        }
+
+        button.text = techniqueName;
 
 
         button.fontDescription = this.fd;
         button.fontDescription = this.fd;
 
 
@@ -213,14 +224,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 +256,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;
@@ -257,7 +268,6 @@ class MaterialInspector extends ScriptWidget {
 
 
     }
     }
 
 
-
     openTextureSelectionBox(textureUnit: number, textureWidget: Atomic.UITextureWidget) {
     openTextureSelectionBox(textureUnit: number, textureWidget: Atomic.UITextureWidget) {
 
 
         var inspector = this;
         var inspector = this;
@@ -277,8 +287,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 +300,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 +320,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 +343,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 +399,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 +420,90 @@ class MaterialInspector extends ScriptWidget {
 
 
     }
     }
 
 
+    loadProjectTechniques(directory: string, menuItem: Atomic.UIMenuItemSource) {
 
 
+        var resourcePath = ToolCore.toolSystem.project.getResourcePath();
+        var TechniqueAssets = ToolCore.getAssetDatabase().getFolderAssets(directory);
+
+        for (var i = 0; i < TechniqueAssets.length; i++) {
+
+            var asset = TechniqueAssets[i];
+
+            if (TechniqueAssets[i].isFolder()) {
+
+                if (this.scanDirectoryForTechniques(asset.path)) {
+
+                    var subfoldersource = new Atomic.UIMenuItemSource();
+                    _ = new Atomic.UIMenuItem(TechniqueAssets[i].name);
+                    _.subSource = subfoldersource;
+                    menuItem.addItem(_);
+
+                    this.loadProjectTechniques(asset.path, subfoldersource);
+                }
+            }
+            else {
+                projectTechniques[i] = TechniqueAssets[i].name;
+                projectTechniquesAddress[i] = TechniqueAssets[i].path;
+                menuItem.addItem(new Atomic.UIMenuItem(projectTechniques[i], projectTechniques[i]));
+            }
+        }
+    }
+
+    scanDirectoryForTechniques(directory: string): boolean {
+
+        var techniqueAssets = ToolCore.getAssetDatabase().getFolderAssets(directory);
+
+        for (var i = 0; i < techniqueAssets.length; i++) {
+
+            var asset = techniqueAssets[i];
+
+            if (techniqueAssets[i].isFolder()) {
+                if (this.scanDirectoryForTechniques(asset.path)) {
+                    return true;
+                }
+            }
+            else if (techniqueAssets[i].getExtension() == ".xml") {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    refreshTechniquesPopup() {
+
+        techniqueSource.clear();
+
+        _ = new Atomic.UIMenuItem("Solid");
+        _.subSource = solidSource;
+        techniqueSource.addItem(_);
+
+        _ = new Atomic.UIMenuItem("Transparency");
+        _.subSource = tranSource;
+        techniqueSource.addItem(_);
+
+        _ = new Atomic.UIMenuItem("Lightmap");
+        _.subSource = lightmapSource;
+        techniqueSource.addItem(_);
+
+        var projectTechniquesPath = ToolCore.toolSystem.project.getResourcePath() + "Techniques";
+
+        if (Atomic.fileSystem.dirExists(projectTechniquesPath)) {
+
+            if (this.scanDirectoryForTechniques(projectTechniquesPath)) {
+
+                projectSource.clear();
+
+                _ = new Atomic.UIMenuItem("Project");
+                _.subSource = projectSource;
+                techniqueSource.addItem(_);
+
+                this.loadProjectTechniques(projectTechniquesPath, projectSource);
+            }
+        }
+    }
 
 
     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 +590,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);

+ 35 - 0
Script/AtomicEditor/ui/resourceEditors/ShaderResourceEditorBuilder.ts

@@ -0,0 +1,35 @@
+//
+// Copyright (c) 2014-2016 THUNDERBEAST GAMES LLC
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+
+import {AbstractTextResourceEditorBuilder} from "./AbstractTextResourceEditorBuilder";
+
+export default class ShaderResourceEditorBuilder extends AbstractTextResourceEditorBuilder {
+
+    constructor() {
+        super();
+    }
+
+    canHandleResource(resourcePath: string) : boolean {
+        var ext = Atomic.getExtension(resourcePath).toLowerCase();
+        return ext == ".hlsl" || ext == ".glsl";
+    }
+}

+ 35 - 0
Script/AtomicEditor/ui/resourceEditors/XMLResourceEditorBuilder.ts

@@ -0,0 +1,35 @@
+//
+// Copyright (c) 2014-2016 THUNDERBEAST GAMES LLC
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+
+import {AbstractTextResourceEditorBuilder} from "./AbstractTextResourceEditorBuilder";
+
+export default class XMLResourceEditorBuilder extends AbstractTextResourceEditorBuilder {
+
+    constructor() {
+        super();
+    }
+
+    canHandleResource(resourcePath: string) : boolean {
+        var ext = Atomic.getExtension(resourcePath).toLowerCase();
+        return ext == ".xml";
+    }
+}

+ 2 - 0
Script/tsconfig.json

@@ -102,6 +102,8 @@
         "./AtomicEditor/ui/resourceEditors/TextFileResourceEditorBuilder.ts",
         "./AtomicEditor/ui/resourceEditors/TextFileResourceEditorBuilder.ts",
         "./AtomicEditor/ui/resourceEditors/TurboBadgerResourceEditorBuilder.ts",
         "./AtomicEditor/ui/resourceEditors/TurboBadgerResourceEditorBuilder.ts",
         "./AtomicEditor/ui/resourceEditors/TypescriptResourceEditorBuilder.ts",
         "./AtomicEditor/ui/resourceEditors/TypescriptResourceEditorBuilder.ts",
+        "./AtomicEditor/ui/resourceEditors/XMLResourceEditorBuilder.ts",
+        "./AtomicEditor/ui/resourceEditors/ShaderResourceEditorBuilder.ts",
         "./AtomicEditor/ui/ScriptWidget.ts",
         "./AtomicEditor/ui/ScriptWidget.ts",
         "./AtomicEditor/ui/Shortcuts.ts",
         "./AtomicEditor/ui/Shortcuts.ts",
         "./AtomicEditor/ui/UIEvents.ts",
         "./AtomicEditor/ui/UIEvents.ts",

+ 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);
         }
         }