Browse Source

Working on material editor

Josh Engebretson 10 years ago
parent
commit
36e0c7e622

+ 140 - 26
Data/AtomicEditor/Resources/EditorData/AtomicEditor/typescript/ui/inspector/MaterialInspector.ts

@@ -4,12 +4,63 @@ import UIEvents = require("../UIEvents");
 
 
 import TextureSelector = require("./TextureSelector");
 import TextureSelector = require("./TextureSelector");
 
 
+var techniqueSource = new Atomic.UIMenuItemSource();
+
+var solidSource = new Atomic.UIMenuItemSource();
+solidSource.addItem(new Atomic.UIMenuItem("Diffuse", "Diffuse"));
+solidSource.addItem(new Atomic.UIMenuItem("Diffuse Emissive", "Diffuse Emissive"));
+solidSource.addItem(new Atomic.UIMenuItem("Diffuse Normal", "Diffuse Normal"));
+
+var tranSource = new Atomic.UIMenuItemSource();
+tranSource.addItem(new Atomic.UIMenuItem("Alpha", "Alpha"));
+tranSource.addItem(new Atomic.UIMenuItem("Alpha Mask", "Alpha Mask"));
+tranSource.addItem(new Atomic.UIMenuItem("Additive", "Additive"));
+tranSource.addItem(new Atomic.UIMenuItem("Additive Alpha", "Additive Alpha"));
+tranSource.addItem(new Atomic.UIMenuItem("Emissive Alpha", "Emissive Alpha"));
+tranSource.addItem(new Atomic.UIMenuItem("Alpha AO", "Alpha AO"));
+tranSource.addItem(new Atomic.UIMenuItem("Alpha Mask AO", "Alpha Mask AO"));
+
+var lightmapSource = new Atomic.UIMenuItemSource();
+lightmapSource.addItem(new Atomic.UIMenuItem("Lightmap", "Lightmap"));
+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 techniqueLookup = {
+    "Techniques/Diff.xml": "Diffuse",
+    "Techniques/DiffEmissive.xml": "Diffuse Emissive",
+    "Techniques/DiffNormal.xml": "Diffuse Normal",
+}
+
+var techniqueReverseLookup = {};
+
+for (var key in techniqueLookup) {
+
+  techniqueReverseLookup[techniqueLookup[key]] = key;
+
+}
+
+
 class MaterialInspector extends ScriptWidget {
 class MaterialInspector extends ScriptWidget {
 
 
     constructor() {
     constructor() {
 
 
         super();
         super();
 
 
+        this.fd.id = "Vera";
+        this.fd.size = 11;
+
+
     }
     }
 
 
     createShaderParametersSection(): Atomic.UISection {
     createShaderParametersSection(): Atomic.UISection {
@@ -17,6 +68,7 @@ class MaterialInspector extends ScriptWidget {
         var section = new Atomic.UISection();
         var section = new Atomic.UISection();
         section.text = "Shader Paramaters";
         section.text = "Shader Paramaters";
         section.value = 1;
         section.value = 1;
+        section.fontDescription = this.fd;
 
 
         return section;
         return section;
 
 
@@ -37,23 +89,69 @@ class MaterialInspector extends ScriptWidget {
 
 
         var thumb = <Atomic.Texture2D> cache.getTempResource("Texture2D", thumbnail);
         var thumb = <Atomic.Texture2D> cache.getTempResource("Texture2D", thumbnail);
 
 
-
         if (thumb)
         if (thumb)
-          return thumb;
+            return thumb;
 
 
         return texture;
         return texture;
 
 
     }
     }
 
 
+    onTechniqueSet(techniqueName:string) {
+
+      this.techniqueButton.text = techniqueName;
+
+      var cache = Atomic.getResourceCache();
+      var technique = <Atomic.Technique> cache.getResource("Technique", techniqueReverseLookup[techniqueName]);
+      this.material.setTechnique(0, technique);
+
+    }
+
+    createTechniquePopup(): Atomic.UIWidget {
+
+        var button = this.techniqueButton = new Atomic.UIButton();
+
+        var technique = this.material.getTechnique(0);
+
+        button.text = techniqueLookup[technique.name];
+
+        button.fontDescription = this.fd;
+
+        var lp = new Atomic.UILayoutParams();
+        lp.width = 140;
+        button.layoutParams = lp;
+
+        button.onClick = function() {
+
+            var menu = new Atomic.UIMenuWindow(button, "technique popup");
+
+            menu.fontDescription = this.fd;
+            menu.show(techniqueSource);
+
+            button.subscribeToEvent(button, "WidgetEvent", function(ev: Atomic.UIWidgetEvent) {
+
+                if (ev.type != Atomic.UI_EVENT_TYPE_CLICK)
+                    return;
+
+                if (ev.target && ev.target.id == "technique popup") {
+
+                    this.onTechniqueSet(ev.refid);
+
+                }
+
+            }.bind(this));
+
+        }.bind(this);
+
+        return button;
+
+    }
+
     createTextureSection(): Atomic.UISection {
     createTextureSection(): Atomic.UISection {
 
 
         var section = new Atomic.UISection();
         var section = new Atomic.UISection();
         section.text = "Textures";
         section.text = "Textures";
         section.value = 1;
         section.value = 1;
-
-        var fd = new Atomic.UIFontDescription();
-        fd.id = "Vera";
-        fd.size = 11;
+        section.fontDescription = this.fd;
 
 
         var attrsVerticalLayout = new Atomic.UILayout(Atomic.UI_AXIS_Y);
         var attrsVerticalLayout = new Atomic.UILayout(Atomic.UI_AXIS_Y);
         attrsVerticalLayout.spacing = 3;
         attrsVerticalLayout.spacing = 3;
@@ -63,8 +161,8 @@ 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_EMISSIVE, Atomic.TU_SPECULAR, Atomic.TU_ENVIRONMENT,
-            Atomic.TU_CUSTOM1, Atomic.TU_CUSTOM2];
+        var textureUnits = [Atomic.TU_DIFFUSE, Atomic.TU_NORMAL]// ,Atomic.TU_EMISSIVE, Atomic.TU_SPECULAR, Atomic.TU_ENVIRONMENT,
+            //Atomic.TU_CUSTOM1, Atomic.TU_CUSTOM2];
 
 
         for (var i in textureUnits) {
         for (var i in textureUnits) {
 
 
@@ -80,7 +178,7 @@ class MaterialInspector extends ScriptWidget {
             name.skinBg = "InspectorTextAttrName";
             name.skinBg = "InspectorTextAttrName";
 
 
             name.text = tunitName;
             name.text = tunitName;
-            name.fontDescription = fd;
+            name.fontDescription = this.fd;
 
 
             attrLayout.addChild(name);
             attrLayout.addChild(name);
 
 
@@ -88,8 +186,8 @@ class MaterialInspector extends ScriptWidget {
             textureWidget.texture = this.getTextureThumbnail(this.material.getTexture(tunit));
             textureWidget.texture = this.getTextureThumbnail(this.material.getTexture(tunit));
 
 
             var tlp = new Atomic.UILayoutParams();
             var tlp = new Atomic.UILayoutParams();
-            tlp.width = 32;
-            tlp.height = 32;
+            tlp.width = 64;
+            tlp.height = 64;
             textureWidget.layoutParams = tlp;
             textureWidget.layoutParams = tlp;
 
 
             attrLayout.addChild(textureWidget);
             attrLayout.addChild(textureWidget);
@@ -101,8 +199,8 @@ class MaterialInspector extends ScriptWidget {
             var callback = function(ev: Atomic.UIWidgetEvent) {
             var callback = function(ev: Atomic.UIWidgetEvent) {
 
 
                 if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
                 if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
-                  var tselect = new TextureSelector(ev.target.view);
-              }
+                    var tselect = new TextureSelector(ev.target.view);
+                }
 
 
             }.bind(editInfo);
             }.bind(editInfo);
 
 
@@ -118,10 +216,6 @@ class MaterialInspector extends ScriptWidget {
 
 
         this.material = material;
         this.material = material;
 
 
-        var fd = new Atomic.UIFontDescription();
-        fd.id = "Vera";
-        fd.size = 11;
-
         var mlp = new Atomic.UILayoutParams();
         var mlp = new Atomic.UILayoutParams();
         mlp.width = 304;
         mlp.width = 304;
 
 
@@ -138,6 +232,7 @@ class MaterialInspector extends ScriptWidget {
         var materialSection = new Atomic.UISection();
         var materialSection = new Atomic.UISection();
         materialSection.text = "Material";
         materialSection.text = "Material";
         materialSection.value = 1;
         materialSection.value = 1;
+        materialSection.fontDescription = this.fd;
         materialLayout.addChild(materialSection);
         materialLayout.addChild(materialSection);
 
 
         var attrsVerticalLayout = new Atomic.UILayout(Atomic.UI_AXIS_Y);
         var attrsVerticalLayout = new Atomic.UILayout(Atomic.UI_AXIS_Y);
@@ -145,34 +240,52 @@ class MaterialInspector extends ScriptWidget {
         attrsVerticalLayout.layoutPosition = Atomic.UI_LAYOUT_POSITION_LEFT_TOP;
         attrsVerticalLayout.layoutPosition = Atomic.UI_LAYOUT_POSITION_LEFT_TOP;
         attrsVerticalLayout.layoutSize = Atomic.UI_LAYOUT_SIZE_AVAILABLE;
         attrsVerticalLayout.layoutSize = Atomic.UI_LAYOUT_SIZE_AVAILABLE;
 
 
-        var attrLayout = new Atomic.UILayout();
-        attrLayout.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION_GRAVITY;
+        // NAME
+        var nameLayout = new Atomic.UILayout();
+        nameLayout.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION_GRAVITY;
 
 
         var name = new Atomic.UITextField();
         var name = new Atomic.UITextField();
         name.textAlign = Atomic.UI_TEXT_ALIGN_LEFT;
         name.textAlign = Atomic.UI_TEXT_ALIGN_LEFT;
         name.skinBg = "InspectorTextAttrName";
         name.skinBg = "InspectorTextAttrName";
 
 
         name.text = "Name";
         name.text = "Name";
-        name.fontDescription = fd;
-
-        attrLayout.addChild(name);
+        name.fontDescription = this.fd;
 
 
+        nameLayout.addChild(name);
 
 
         var field = new Atomic.UIEditField();
         var field = new Atomic.UIEditField();
         field.textAlign = Atomic.UI_TEXT_ALIGN_LEFT;
         field.textAlign = Atomic.UI_TEXT_ALIGN_LEFT;
         field.skinBg = "TBAttrEditorField";;
         field.skinBg = "TBAttrEditorField";;
-        field.fontDescription = fd;
+        field.fontDescription = this.fd;
         var lp = new Atomic.UILayoutParams();
         var lp = new Atomic.UILayoutParams();
         lp.width = 140;
         lp.width = 140;
         field.layoutParams = lp;
         field.layoutParams = lp;
 
 
         field.text = material.getTexture(Atomic.TU_DIFFUSE).name;
         field.text = material.getTexture(Atomic.TU_DIFFUSE).name;
 
 
-        attrLayout.addChild(field);
+        nameLayout.addChild(field);
+
+        attrsVerticalLayout.addChild(nameLayout);
+
+        // TECHNIQUE LAYOUT
+
+        var techniqueLayout = new Atomic.UILayout();
+        techniqueLayout.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION_GRAVITY;
 
 
+        name = new Atomic.UITextField();
+        name.textAlign = Atomic.UI_TEXT_ALIGN_LEFT;
+        name.skinBg = "InspectorTextAttrName";
+
+        name.text = "Technique";
+        name.fontDescription = this.fd;
 
 
-        attrsVerticalLayout.addChild(attrLayout);
+        techniqueLayout.addChild(name);
 
 
+        var techniquePopup = this.createTechniquePopup();
+
+        techniqueLayout.addChild(techniquePopup);
+
+        attrsVerticalLayout.addChild(techniqueLayout);
 
 
         materialSection.contentRoot.addChild(attrsVerticalLayout);
         materialSection.contentRoot.addChild(attrsVerticalLayout);
 
 
@@ -200,9 +313,10 @@ class MaterialInspector extends ScriptWidget {
 
 
     }
     }
 
 
+    techniqueButton:Atomic.UIButton;
     material: Atomic.Material;
     material: Atomic.Material;
-
     nameTextField: Atomic.UITextField;
     nameTextField: Atomic.UITextField;
+    fd: Atomic.UIFontDescription = new Atomic.UIFontDescription();
 
 
 
 
 }
 }

+ 0 - 1
Data/AtomicEditor/Resources/EditorData/AtomicEditor/typescript/ui/inspector/TextureSelector.ts

@@ -48,7 +48,6 @@ class TextureSelector extends Atomic.UIWindow {
 
 
         }
         }
 
 
-
         mainLayout.addChild(scrollContainer);
         mainLayout.addChild(scrollContainer);
 
 
         parent.addChild(this);
         parent.addChild(this);

+ 9 - 0
Source/Atomic/UI/UIMenuWindow.cpp

@@ -44,4 +44,13 @@ bool UIMenuWindow::OnEvent(const tb::TBWidgetEvent &ev)
     return false;
     return false;
 }
 }
 
 
+void UIMenuWindow::Close()
+{
+    if (!widget_)
+        return;
+
+    ((TBMenuWindow*)widget_)->Close();
+
+}
+
 }
 }

+ 2 - 0
Source/Atomic/UI/UIMenuWindow.h

@@ -20,6 +20,8 @@ public:
 
 
     void Show(UISelectItemSource* source);
     void Show(UISelectItemSource* source);
 
 
+    void Close();
+
 protected:
 protected:
 
 
     virtual bool OnEvent(const tb::TBWidgetEvent &ev);
     virtual bool OnEvent(const tb::TBWidgetEvent &ev);

+ 2 - 0
Source/Atomic/UI/UISceneView.cpp

@@ -205,6 +205,8 @@ void SceneViewWidget::OnPaint(const PaintProps &paint_props)
         size.x_ = rect.w;
         size.x_ = rect.w;
         size.y_ = rect.h;
         size.y_ = rect.h;
         sceneView_->SetResizeRequired();
         sceneView_->SetResizeRequired();
+        // early out here, responsible for flicker
+        // https://github.com/AtomicGameEngine/AtomicGameEngine/issues/115
         return;
         return;
     }
     }
 
 

+ 4 - 3
Source/Atomic/UI/UIWidget.cpp

@@ -91,9 +91,10 @@ void UIWidget::SetWidget(tb::TBWidget* widget)
 void UIWidget::ConvertEvent(UIWidget *handler, UIWidget* target, const tb::TBWidgetEvent &ev, VariantMap& data)
 void UIWidget::ConvertEvent(UIWidget *handler, UIWidget* target, const tb::TBWidgetEvent &ev, VariantMap& data)
 {
 {
     UI* ui = GetSubsystem<UI>();
     UI* ui = GetSubsystem<UI>();
-    String id;
 
 
-    ui->GetTBIDString(ev.ref_id, id);
+    String refid;
+
+    ui->GetTBIDString(ev.ref_id, refid);
 
 
     using namespace WidgetEvent;
     using namespace WidgetEvent;
     data[P_HANDLER] = handler;
     data[P_HANDLER] = handler;
@@ -107,7 +108,7 @@ void UIWidget::ConvertEvent(UIWidget *handler, UIWidget* target, const tb::TBWid
     data[P_KEY] = ev.key;
     data[P_KEY] = ev.key;
     data[P_SPECIALKEY] = (unsigned) ev.special_key;
     data[P_SPECIALKEY] = (unsigned) ev.special_key;
     data[P_MODIFIERKEYS] = (unsigned) ev.modifierkeys;
     data[P_MODIFIERKEYS] = (unsigned) ev.modifierkeys;
-    data[P_REFID] = id;
+    data[P_REFID] = refid;
     data[P_TOUCH] = (unsigned) ev.touch;
     data[P_TOUCH] = (unsigned) ev.touch;
 }
 }
 
 

+ 1 - 1
Source/AtomicJS/Javascript/JSUI.cpp

@@ -348,7 +348,7 @@ void JSUI::HandleWidgetEvent(StringHash eventType, VariantMap& eventData)
     }
     }
 
 
     // specific event handlers
     // specific event handlers
-    if (type == tb::EVENT_TYPE_CLICK)
+    if (type == tb::EVENT_TYPE_CLICK && handler == target)
     {
     {
         int top = duk_get_top(ctx_);
         int top = duk_get_top(ctx_);
         duk_push_heapptr(ctx_, handlerHeapPtr);
         duk_push_heapptr(ctx_, handlerHeapPtr);

+ 4 - 0
Source/ToolCore/Import/OpenAssetImporter.cpp

@@ -85,6 +85,10 @@ OpenAssetImporter::OpenAssetImporter(Context* context) : Object(context) ,
         aiProcess_FindInstances |
         aiProcess_FindInstances |
         aiProcess_OptimizeMeshes;
         aiProcess_OptimizeMeshes;
 
 
+    // TODO:  make this an option on importer
+
+    aiFlagsDefault_ |= aiProcess_CalcTangentSpace;
+
     aiCurrentFlags_ = aiFlagsDefault_;
     aiCurrentFlags_ = aiFlagsDefault_;
 
 
 }
 }