Browse Source

One can now add a new technique to a mat def with the node Editor.
Also added an experimental auto layout feature

Nehon 10 years ago
parent
commit
6e616e215c

+ 20 - 1
jme3-materialeditor/src/com/jme3/gde/materialdefinition/EditableMatDefFile.java

@@ -209,7 +209,7 @@ public class EditableMatDefFile {
         material = new Material(materialDef);
 
         try {
-            material.selectTechnique("Default", SceneApplication.getApplication().getRenderManager());
+            //material.selectTechnique("Default", SceneApplication.getApplication().getRenderManager());
             if (matToRemove != null) {
                 for (MatParam matParam : matToRemove.getParams()) {
                     try {
@@ -343,4 +343,23 @@ public class EditableMatDefFile {
         }
         updateLookupWithMaterialData(obj);
     }
+    
+    public void cleanup(){
+        if (matDefStructure != null) {
+            obj.getLookupContents().remove(matDefStructure);
+            matDefStructure = null;
+        }
+        if (materialDef != null) {
+            obj.getLookupContents().remove(materialDef);
+            materialDef = null;
+        }
+        if (material != null) {
+            obj.getLookupContents().remove(material);
+            matToRemove = material;
+            material = null;
+        }
+        
+        setCurrentTechnique(null);
+        setLoaded(false);
+    }
 }

+ 5 - 33
jme3-materialeditor/src/com/jme3/gde/materialdefinition/MatDefDataObject.java

@@ -132,6 +132,7 @@ public class MatDefDataObject extends MultiDataObject {
     private EditableMatDefFile file = null;
     private boolean loaded = false;
 
+    @SuppressWarnings("LeakingThisInConstructor")
     public MatDefDataObject(FileObject pf, MultiFileLoader loader) throws DataObjectExistsException, IOException {
         super(pf, loader);
         registerEditor("text/jme-materialdefinition", true);
@@ -296,44 +297,15 @@ public class MatDefDataObject extends MultiDataObject {
 
     public void unload() {
         if (loaded) {
-            loaded = false;
+            loaded = false;            
             getLookup().lookup(MatDefNavigatorPanel.class).updateData(null);
+            getEditableFile().cleanup();
+
         }
     }
 
     public InstanceContent getLookupContents() {
         return lookupContents;
     }
-//    @Override
-//    public synchronized void saveAsset() throws IOException {
-//        
-////        ProgressHandle progressHandle = ProgressHandleFactory.createHandle("Saving File..");
-////        progressHandle.start();
-// //      BinaryExporter exp = BinaryExporter.getInstance();
-//        FileLock lock = null;
-//        OutputStream out = null;
-//        try {
-//             PrintWriter to = new PrintWriter(getPrimaryFile().getOutputStream(lock));
-//            try {
-//                to.print(getEditableFile().getMatDefStructure().toString());
-//              
-//            } finally {
-//                to.close();
-//            }
-//        } finally {
-//            if (lock != null) {
-//                lock.releaseLock();
-//            }
-//            if (out != null) {
-//                out.close();
-//            }
-//        }
-//     //   progressHandle.finish();
-//        StatusDisplayer.getDefault().setStatusText(getPrimaryFile().getNameExt() + " saved.");
-//        setModified(false);
-//        
-////        getPrimaryFile().
-////                getOutputStream().write(getEditableFile().getMatDefStructure().toString().getBytes());        
-//       
-//    }
+
 }

+ 7 - 0
jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/BackdropPanel.java

@@ -85,6 +85,13 @@ public class BackdropPanel extends javax.swing.JPanel implements MouseListener,
             renderer.showMaterial(mat); 
         }
     }
+    
+     public void showMaterial(Material mat, String technique) {
+        if (isVisible()) {
+            this.mat = mat;
+            renderer.showMaterial(mat, technique); 
+        }
+    }
 
     /**
      * This method is called from within the constructor to initialize the form.

+ 3 - 0
jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/Bundle.properties

@@ -13,3 +13,6 @@ NodeToolBar.codeButton.toolTipText=Display code
 NodeToolBar.deleteButton.toolTipText=Delete node
 NodeToolBar.deleteButton.text=
 MatDefEditorToolBar.jLabel1.text=Technique
+MatDefEditorToolBar.jButton1.text=Add
+MatDefEditorToolBar.jButton1.toolTipText=Add a new technique
+MatDefEditorToolBar.jButton2.text=Auto layout

+ 10 - 0
jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/ConnectionCurve.java

@@ -434,4 +434,14 @@ public class ConnectionCurve extends JPanel implements ComponentListener, MouseI
         MappingBlock map = (MappingBlock) evt.getSource();
         key = MaterialUtils.makeKey(map, getDiagram().getCurrentTechniqueName());
     }
+
+    public Dot getStart() {
+        return start;
+    }
+
+    public Dot getEnd() {
+        return end;
+    }
+    
+    
 }

+ 65 - 9
jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/Diagram.java

@@ -5,7 +5,6 @@
 package com.jme3.gde.materialdefinition.editor;
 
 import com.jme3.gde.core.assets.ProjectAssetManager;
-import com.jme3.gde.core.scene.SceneApplication;
 import com.jme3.gde.materialdefinition.dialog.AddAttributeDialog;
 import com.jme3.gde.materialdefinition.dialog.AddMaterialParameterDialog;
 import com.jme3.gde.materialdefinition.dialog.AddNodeDialog;
@@ -23,7 +22,6 @@ import java.awt.Component;
 import java.awt.Cursor;
 import java.awt.Dimension;
 import java.awt.Font;
-import java.awt.Graphics;
 import java.awt.Point;
 import java.awt.Rectangle;
 import java.awt.event.ActionEvent;
@@ -106,16 +104,16 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
         } else if (e.getButton() == MouseEvent.BUTTON2) {
             setCursor(hndCursor);
             pp.setLocation(e.getPoint());
-            ((JScrollPane)getParent().getParent()).setWheelScrollingEnabled(false);
+            ((JScrollPane) getParent().getParent()).setWheelScrollingEnabled(false);
         }
     }
 
-    public void refreshPreviews(Material mat) {
+    public void refreshPreviews(Material mat, String technique) {
         for (OutBusPanel outBusPanel : outBuses) {
-            outBusPanel.updatePreview(mat);
+            outBusPanel.updatePreview(mat, technique);
         }
         if (backDrop.isVisible()) {
-            backDrop.showMaterial(mat);
+            backDrop.showMaterial(mat, technique);
         }
     }
 
@@ -148,7 +146,7 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
                 break;
             case MouseEvent.BUTTON2:
                 setCursor(defCursor);
-                 ((JScrollPane)getParent().getParent()).setWheelScrollingEnabled(true);
+                ((JScrollPane) getParent().getParent()).setWheelScrollingEnabled(true);
                 break;
             case MouseEvent.BUTTON3:
                 contextMenu.show(this, e.getX(), e.getY());
@@ -420,8 +418,7 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
                 return doSelect(outBusPanel);
             }
         }
-        
-        
+
         return doSelect(null);
     }
 
@@ -578,6 +575,65 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
         fixSize();
     }
 
+    public void autoLayout() {
+
+        int offset = 550;
+        for (OutBusPanel outBus : outBuses) {
+            if (outBus.getKey().equalsIgnoreCase("position")) {
+                outBus.setLocation(0, 100);
+                
+            } else {
+                outBus.setLocation(0, offset);
+                offset += 260;
+            }
+            getEditorParent().savePositionToMetaData(outBus.getKey(), outBus.getLocation().x, outBus.getLocation().y);
+        }
+        offset = 0;
+        String keys = "";
+        for (NodePanel node : nodes) {
+
+            if (node.getType() == NodePanel.NodeType.Vertex || node.getType() == NodePanel.NodeType.Fragment) {
+                node.setLocation(offset + 200, getNodeTop(node));
+                getEditorParent().savePositionToMetaData(node.getKey(), node.getLocation().x, node.getLocation().y);
+                int pad = getNodeTop(node);
+                for (Connection connection : connections) {
+                    if (connection.getEnd().getNode() == node) {
+                        if (connection.getStart().getNode() instanceof NodePanel) {
+                            NodePanel startP = (NodePanel) connection.getStart().getNode();
+                            if (startP.getType() != NodePanel.NodeType.Vertex && startP.getType() != NodePanel.NodeType.Fragment) {
+                                startP.setLocation(offset + 30, pad);
+                                getEditorParent().savePositionToMetaData(startP.getKey(), startP.getLocation().x, startP.getLocation().y);
+                                keys += startP.getKey() + "|";
+                                pad += 50;
+                            }
+                        }
+                    }
+                }
+            }
+            offset += 320;
+        }
+        offset = 0;
+        for (NodePanel node : nodes) {
+            if (node.getType() != NodePanel.NodeType.Vertex && node.getType() != NodePanel.NodeType.Fragment && !(keys.contains(node.getKey()))) {
+                node.setLocation(offset + 10, 0);
+                getEditorParent().savePositionToMetaData(node.getKey(), node.getLocation().x, node.getLocation().y);
+                offset += 130;
+            }
+        }
+
+    }
+
+    private int getNodeTop(NodePanel node) {
+        if (node.getType() == NodePanel.NodeType.Vertex) {
+            return 150;
+        }
+        if (node.getType() == NodePanel.NodeType.Fragment) {
+            return 400;
+        }
+        return 0;
+
+    }
+
     public void componentMoved(ComponentEvent e) {
     }
 

+ 50 - 4
jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/MatDefEditorToolBar.form

@@ -3,7 +3,7 @@
 <Form version="1.5" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
   <Properties>
     <Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
-      <Dimension value="[474, 25]"/>
+      <Dimension value="[474, 20]"/>
     </Property>
   </Properties>
   <AuxValues>
@@ -22,19 +22,28 @@
     <DimensionLayout dim="0">
       <Group type="103" groupAlignment="0" attributes="0">
           <Group type="102" alignment="0" attributes="0">
+              <Component id="jSeparator1" min="-2" max="-2" attributes="0"/>
+              <EmptySpace max="-2" attributes="0"/>
               <Component id="jLabel1" min="-2" pref="71" max="-2" attributes="0"/>
               <EmptySpace max="-2" attributes="0"/>
               <Component id="techniqueComboBox" min="-2" pref="136" max="-2" attributes="0"/>
-              <EmptySpace min="0" pref="337" max="32767" attributes="0"/>
+              <EmptySpace max="-2" attributes="0"/>
+              <Component id="jButton1" min="-2" pref="53" max="-2" attributes="0"/>
+              <EmptySpace max="-2" attributes="0"/>
+              <Component id="jButton2" min="-2" max="-2" attributes="0"/>
+              <EmptySpace min="0" pref="103" max="32767" attributes="0"/>
           </Group>
       </Group>
     </DimensionLayout>
     <DimensionLayout dim="1">
       <Group type="103" groupAlignment="0" attributes="0">
-          <Group type="103" alignment="0" groupAlignment="3" attributes="0">
-              <Component id="jLabel1" alignment="3" pref="25" max="32767" attributes="0"/>
+          <Group type="103" groupAlignment="3" attributes="0">
+              <Component id="jLabel1" alignment="3" max="32767" attributes="0"/>
               <Component id="techniqueComboBox" alignment="3" min="-2" max="-2" attributes="0"/>
+              <Component id="jButton1" alignment="3" min="-2" max="-2" attributes="0"/>
+              <Component id="jButton2" alignment="3" min="-2" max="-2" attributes="0"/>
           </Group>
+          <Component id="jSeparator1" alignment="0" max="32767" attributes="0"/>
       </Group>
     </DimensionLayout>
   </Layout>
@@ -62,5 +71,42 @@
         <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="techniqueComboBoxActionPerformed"/>
       </Events>
     </Component>
+    <Component class="javax.swing.JButton" name="jButton1">
+      <Properties>
+        <Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
+          <Image iconType="3" name="/com/jme3/gde/materialdefinition/icons/add.png"/>
+        </Property>
+        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
+          <ResourceString bundle="com/jme3/gde/materialdefinition/editor/Bundle.properties" key="MatDefEditorToolBar.jButton1.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
+        </Property>
+        <Property name="toolTipText" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
+          <ResourceString bundle="com/jme3/gde/materialdefinition/editor/Bundle.properties" key="MatDefEditorToolBar.jButton1.toolTipText" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
+        </Property>
+        <Property name="margin" type="java.awt.Insets" editor="org.netbeans.beaninfo.editors.InsetsEditor">
+          <Insets value="[2, 5, 2, 5]"/>
+        </Property>
+        <Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
+          <Dimension value="[71, 25]"/>
+        </Property>
+      </Properties>
+      <Events>
+        <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton1ActionPerformed"/>
+      </Events>
+    </Component>
+    <Component class="javax.swing.JSeparator" name="jSeparator1">
+      <Properties>
+        <Property name="orientation" type="int" value="1"/>
+      </Properties>
+    </Component>
+    <Component class="javax.swing.JButton" name="jButton2">
+      <Properties>
+        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
+          <ResourceString bundle="com/jme3/gde/materialdefinition/editor/Bundle.properties" key="MatDefEditorToolBar.jButton2.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
+        </Property>
+      </Properties>
+      <Events>
+        <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton2ActionPerformed"/>
+      </Events>
+    </Component>
   </SubComponents>
 </Form>

+ 68 - 13
jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/MatDefEditorToolBar.java

@@ -12,6 +12,7 @@ import javax.swing.DefaultComboBoxModel;
 import javax.swing.DefaultListCellRenderer;
 import javax.swing.JLabel;
 import javax.swing.JList;
+import javax.swing.JOptionPane;
 import javax.swing.ListCellRenderer;
 
 /**
@@ -21,7 +22,8 @@ import javax.swing.ListCellRenderer;
 public class MatDefEditorToolBar extends javax.swing.JPanel {
 
     private MatDefEditorlElement parent;
-    private final DefaultComboBoxModel<TechniqueBlock> comboModel = new DefaultComboBoxModel<TechniqueBlock>();   
+    private final DefaultComboBoxModel<TechniqueBlock> comboModel = new DefaultComboBoxModel<TechniqueBlock>();
+
     /**
      * Creates new form MatDefEditorToolBar
      */
@@ -32,25 +34,27 @@ public class MatDefEditorToolBar extends javax.swing.JPanel {
         techniqueComboBox.setRenderer(new ListCellRenderer<TechniqueBlock>() {
 
             public Component getListCellRendererComponent(JList list, TechniqueBlock value, int index, boolean isSelected, boolean cellHasFocus) {
-                JLabel c = (JLabel)renderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
+                JLabel c = (JLabel) renderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                 c.setText(value.getName());
-                return  c;
+                return c;
             }
         });
-        
+
     }
 
     public void setParent(MatDefEditorlElement parent) {
         this.parent = parent;
     }
-    
-    public void addTechnique(List<TechniqueBlock> tech){
+
+    public void addTechnique(List<TechniqueBlock> tech) {
+        comboModel.removeAllElements();
+                
         for (TechniqueBlock tech1 : tech) {
             comboModel.addElement(tech1);
         }
-        
+
     }
-    
+
     /**
      * This method is called from within the constructor to initialize the form.
      * WARNING: Do NOT modify this code. The content of this method is always
@@ -62,8 +66,11 @@ public class MatDefEditorToolBar extends javax.swing.JPanel {
 
         jLabel1 = new javax.swing.JLabel();
         techniqueComboBox = new javax.swing.JComboBox();
+        jButton1 = new javax.swing.JButton();
+        jSeparator1 = new javax.swing.JSeparator();
+        jButton2 = new javax.swing.JButton();
 
-        setPreferredSize(new java.awt.Dimension(474, 25));
+        setPreferredSize(new java.awt.Dimension(474, 20));
 
         jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
         org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(MatDefEditorToolBar.class, "MatDefEditorToolBar.jLabel1.text")); // NOI18N
@@ -75,31 +82,79 @@ public class MatDefEditorToolBar extends javax.swing.JPanel {
             }
         });
 
+        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/jme3/gde/materialdefinition/icons/add.png"))); // NOI18N
+        org.openide.awt.Mnemonics.setLocalizedText(jButton1, org.openide.util.NbBundle.getMessage(MatDefEditorToolBar.class, "MatDefEditorToolBar.jButton1.text")); // NOI18N
+        jButton1.setToolTipText(org.openide.util.NbBundle.getMessage(MatDefEditorToolBar.class, "MatDefEditorToolBar.jButton1.toolTipText")); // NOI18N
+        jButton1.setMargin(new java.awt.Insets(2, 5, 2, 5));
+        jButton1.setPreferredSize(new java.awt.Dimension(71, 25));
+        jButton1.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
+                jButton1ActionPerformed(evt);
+            }
+        });
+
+        jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL);
+
+        org.openide.awt.Mnemonics.setLocalizedText(jButton2, org.openide.util.NbBundle.getMessage(MatDefEditorToolBar.class, "MatDefEditorToolBar.jButton2.text")); // NOI18N
+        jButton2.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
+                jButton2ActionPerformed(evt);
+            }
+        });
+
         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
         this.setLayout(layout);
         layout.setHorizontalGroup(
             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
             .addGroup(layout.createSequentialGroup()
+                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                 .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                 .addComponent(techniqueComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE)
-                .addGap(0, 337, Short.MAX_VALUE))
+                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
+                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+                .addComponent(jButton2)
+                .addGap(0, 103, Short.MAX_VALUE))
         );
         layout.setVerticalGroup(
             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
             .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
-                .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)
-                .addComponent(techniqueComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
+                .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+                .addComponent(techniqueComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+                .addComponent(jButton2))
+            .addComponent(jSeparator1)
         );
     }// </editor-fold>//GEN-END:initComponents
 
     private void techniqueComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_techniqueComboBoxActionPerformed
-        parent.switchTechnique((TechniqueBlock)techniqueComboBox.getSelectedItem());
+        parent.switchTechnique((TechniqueBlock) techniqueComboBox.getSelectedItem());
     }//GEN-LAST:event_techniqueComboBoxActionPerformed
 
+    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
+        String techName = JOptionPane.showInputDialog("Enter a name for the new technique");
+
+        if (techName != null) {
+            TechniqueBlock tech = new TechniqueBlock(techName);
+            parent.notifyAddTechnique(tech);
+            comboModel.addElement(tech);
+            comboModel.setSelectedItem(tech);
+            parent.autoLayout();
+        }
+    }//GEN-LAST:event_jButton1ActionPerformed
+
+    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
+       parent.getDiagram().autoLayout();
+    }//GEN-LAST:event_jButton2ActionPerformed
+
 
     // Variables declaration - do not modify//GEN-BEGIN:variables
+    private javax.swing.JButton jButton1;
+    private javax.swing.JButton jButton2;
     private javax.swing.JLabel jLabel1;
+    private javax.swing.JSeparator jSeparator1;
     private javax.swing.JComboBox techniqueComboBox;
     // End of variables declaration//GEN-END:variables
 }

+ 57 - 10
jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/MatDefEditorlElement.java

@@ -31,6 +31,7 @@
  */
 package com.jme3.gde.materialdefinition.editor;
 
+import com.jme3.asset.ShaderNodeDefinitionKey;
 import com.jme3.gde.core.assets.ProjectAssetManager;
 import com.jme3.gde.core.scene.SceneApplication;
 import com.jme3.gde.materialdefinition.EditableMatDefFile;
@@ -45,7 +46,6 @@ import com.jme3.gde.materialdefinition.fileStructure.leaves.MatParamBlock;
 import com.jme3.gde.materialdefinition.fileStructure.leaves.OutputMappingBlock;
 import com.jme3.gde.materialdefinition.fileStructure.leaves.WorldParamBlock;
 import com.jme3.gde.materialdefinition.navigator.MatDefNavigatorPanel;
-import com.jme3.gde.materialdefinition.shadervisual.MatDefShaderElement;
 import com.jme3.gde.materialdefinition.utils.MaterialUtils;
 import com.jme3.material.Material;
 import com.jme3.shader.Shader;
@@ -116,9 +116,12 @@ public final class MatDefEditorlElement extends JPanel implements MultiViewEleme
         final EditableMatDefFile file = obj.getEditableFile();
         shaderEditPanel1.setVisible(false);
         shaderEditPanel1.setParent(this);
+        if(!file.isLoaded()){
+            file.load(lkp);
+        }
+        reload(file, lkp);        
         toolbar.setParent(this);
         toolbar.addTechnique(lkp.lookup(MatDefBlock.class).getTechniques());
-        reload(file, lkp);        
     }
 
     private void initDiagram(Lookup lkp) throws NumberFormatException {
@@ -222,16 +225,15 @@ public final class MatDefEditorlElement extends JPanel implements MultiViewEleme
         diagram1.revalidate();
         jScrollPane1.addComponentListener(diagram1);
 
-        mat.selectTechnique(obj.getEditableFile().getCurrentTechnique().getName(), SceneApplication.getApplication().getRenderManager());
-        diagram1.refreshPreviews(mat);
+        
+        diagram1.refreshPreviews(mat,obj.getEditableFile().getCurrentTechnique().getName());
         final Lookup.Result<Material> resMat = obj.getLookup().lookupResult(Material.class);
         resMat.addLookupListener(new LookupListener() {
             public void resultChanged(LookupEvent ev) {
                 Collection<? extends Material> col = (Collection<? extends Material>) resMat.allInstances();
                 if (!col.isEmpty()) {
-                    Material material = col.iterator().next();
-                    material.selectTechnique(obj.getEditableFile().getCurrentTechnique().getName(), SceneApplication.getApplication().getRenderManager());
-                    diagram1.refreshPreviews(material);
+                    Material material = col.iterator().next();                    
+                    diagram1.refreshPreviews(material,obj.getEditableFile().getCurrentTechnique().getName());
                 }
             }
         });
@@ -257,6 +259,12 @@ public final class MatDefEditorlElement extends JPanel implements MultiViewEleme
         reload(obj.getEditableFile(), obj.getLookup());
     }
 
+    public Diagram getDiagram() {
+        return diagram1;
+    }
+    
+    
+
     @Override
     public String getName() {
         return "MatDefVisualElement";
@@ -287,9 +295,8 @@ public final class MatDefEditorlElement extends JPanel implements MultiViewEleme
         Lookup.Result<Material> resMat = obj.getLookup().lookupResult(Material.class);
         Collection<? extends Material> col = (Collection<? extends Material>) resMat.allInstances();
         if (!col.isEmpty()) {
-            Material material = col.iterator().next();
-            material.selectTechnique(obj.getEditableFile().getCurrentTechnique().getName(), SceneApplication.getApplication().getRenderManager());
-            diagram1.refreshPreviews(material);
+            Material material = col.iterator().next();            
+            diagram1.refreshPreviews(material,obj.getEditableFile().getCurrentTechnique().getName());
         }
 
     }
@@ -441,6 +448,10 @@ public final class MatDefEditorlElement extends JPanel implements MultiViewEleme
 
     @Override
     public void componentOpened() {
+        if (!obj.getEditableFile().isLoaded()) {
+            obj.getEditableFile().load(obj.getLookup());
+            reload(obj.getEditableFile(), obj.getLookup());
+        }
     }
 
     @Override
@@ -449,6 +460,10 @@ public final class MatDefEditorlElement extends JPanel implements MultiViewEleme
 
     @Override
     public void componentShowing() {
+        if (!obj.getEditableFile().isLoaded()) {
+            obj.getEditableFile().load(obj.getLookup());
+            reload(obj.getEditableFile(), obj.getLookup());
+        }
     }
 
     @Override
@@ -529,6 +544,38 @@ public final class MatDefEditorlElement extends JPanel implements MultiViewEleme
         }
     }
 
+    public void notifyAddTechnique(TechniqueBlock tech) {
+       
+        String path = "Common/MatDefs/ShaderNodes/Common/Unshaded.j3sn";
+        ShaderNodeDefinitionKey key =  new ShaderNodeDefinitionKey(path);
+        List<ShaderNodeDefinition> defs = getAssetManager().loadAsset(key);
+        ShaderNodeBlock node = new ShaderNodeBlock(defs.get(0), path);
+        tech.addFragmentShaderNode(node);
+        node.addOutputMapping(new OutputMappingBlock("color", "color", "", "", "Global", "Unshaded", null));
+        
+        path = "Common/MatDefs/ShaderNodes/Common/CommonVert.j3sn";
+        key =  new ShaderNodeDefinitionKey(path);
+        defs = getAssetManager().loadAsset(key);
+        node = new ShaderNodeBlock(defs.get(0), path);
+        tech.addVertexShaderNode(node);
+        
+        node.addInputMapping(new InputMappingBlock("worldViewProjectionMatrix", "WorldViewProjectionMatrix", "", "", "CommonVert", "WorldParam", null));
+        node.addInputMapping(new InputMappingBlock("modelPosition", "position", "", "xyz", "CommonVert", "Global", null));        
+        
+        node.addOutputMapping(new OutputMappingBlock("position", "projPosition", "", "", "Global", "CommonVert", null));
+        
+        
+        WorldParamBlock param = new WorldParamBlock("WorldViewProjectionMatrix");
+        tech.addWorldParam(param);
+        
+        obj.getEditableFile().getMatDefStructure().addTechnique(tech);     
+        
+    }
+
+    public void autoLayout(){
+        diagram1.autoLayout();
+    }
+    
     public void notifyAddMapParam(String type, String name) {
         MatDefBlock matDef = obj.getLookup().lookup(MatDefBlock.class);
         MatParamBlock param = new MatParamBlock(type, name, null, null);

+ 5 - 0
jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/MatPanel.java

@@ -43,6 +43,11 @@ public class MatPanel extends javax.swing.JPanel implements MouseListener, Compo
         this.mat = mat;
         renderer.showMaterial(mat);       
     }
+    
+    public void showMaterial(Material mat, String technique) {
+        this.mat = mat;
+        renderer.showMaterial(mat, technique);       
+    }
 
     public void setExpandActionListener(ActionListener action){        
         expandButton.addActionListener(action);

+ 1 - 1
jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/NodePanel.java

@@ -115,7 +115,7 @@ public class NodePanel extends DraggablePanel implements Selectable, PropertyCha
         this.filePaths.addAll(def.getShadersPath());
         String defPath = ((DefinitionBlock) node.getContents().get(0)).getPath();
         this.filePaths.add(defPath);
-        toolBar = new NodeToolBar(this);
+        toolBar = new NodeToolBar(this);        
     }
 
     /**

+ 4 - 5
jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/OutBusPanel.java

@@ -179,14 +179,13 @@ public class OutBusPanel extends DraggablePanel implements ComponentListener, Se
         return panel;
     }
 
-    public void updatePreview(Material mat) {
+    public void updatePreview(Material mat, String technique) {
         if (type == Shader.ShaderType.Fragment) {
-            preview.showMaterial(mat);
+            preview.showMaterial(mat,technique);
         } else {
-            Material vmat = mat.clone();
-            vmat.selectTechnique(mat.getActiveTechnique().getDef().getName(), SceneApplication.getApplication().getRenderManager());
+            Material vmat = mat.clone();            
             vmat.getAdditionalRenderState().setWireframe(true);
-            preview.showMaterial(vmat);
+            preview.showMaterial(vmat,technique);
         }
     }
 

+ 5 - 0
jme3-materialeditor/src/com/jme3/gde/materialdefinition/fileStructure/TechniqueBlock.java

@@ -59,6 +59,11 @@ public class TechniqueBlock extends UberStatement {
             name = s[1];
         }
     }
+    
+    public TechniqueBlock(String name){
+        super(0, "Technique "+name);        
+        this.name = name;                
+    }
 
     public String getName() {
         return name;

+ 23 - 10
jme3-materialeditor/src/com/jme3/gde/materials/MaterialPreviewRenderer.java

@@ -94,12 +94,23 @@ public class MaterialPreviewRenderer implements SceneListener {
     }
     
     public void showMaterial(final Material m) {
+        showMaterial(m, null);
+    }
+    
+    public void showMaterial(final Material m,final String techniqueName) {
         if (!init) {
             init();
         }
         SceneApplication.getApplication().enqueue(new Callable<Material>() {
 
             public Material call() throws Exception {
+                if(techniqueName!= null){
+                    try {
+                        m.selectTechnique(techniqueName, SceneApplication.getApplication().getRenderManager());
+                    } catch (Exception e) {
+                        //
+                    }
+                }
                 final Material mat = reloadMaterial(m);
                 if (mat != null) {
                     java.awt.EventQueue.invokeLater(new Runnable() {
@@ -145,18 +156,17 @@ public class MaterialPreviewRenderer implements SceneListener {
         
         //creating a dummy mat with the mat def of the mat to reload
         Material dummy = new Material(mat.getMaterialDef());
+        try {
+            for (MatParam matParam : mat.getParams()) {
+                dummy.setParam(matParam.getName(), matParam.getVarType(), matParam.getValue());
+            }
+            dummy.selectTechnique(mat.getActiveTechnique().getDef().getName(), SceneApplication.getApplication().getRenderManager());
+            dummy.getAdditionalRenderState().set(mat.getAdditionalRenderState());        
 
-        for (MatParam matParam : mat.getParams()) {
-            dummy.setParam(matParam.getName(), matParam.getVarType(), matParam.getValue());
-        }
-        dummy.selectTechnique(mat.getActiveTechnique().getDef().getName(), SceneApplication.getApplication().getRenderManager());
-        dummy.getAdditionalRenderState().set(mat.getAdditionalRenderState());        
-
-        //creating a dummy geom and assigning the dummy material to it
-        Geometry dummyGeom = new Geometry("dummyGeom", new Box(1f, 1f, 1f));
-        dummyGeom.setMaterial(dummy);
+            //creating a dummy geom and assigning the dummy material to it
+            Geometry dummyGeom = new Geometry("dummyGeom", new Box(1f, 1f, 1f));
+            dummyGeom.setMaterial(dummy);
 
-        try {
             //preloading the dummyGeom, this call will compile the shader again
            SceneApplication.getApplication().getRenderManager().preloadScene(dummyGeom);
         } catch (RendererException e) {
@@ -171,6 +181,9 @@ public class MaterialPreviewRenderer implements SceneListener {
                 }
             });
             return null;
+        } catch (NullPointerException npe){
+            //utterly bad, but for some reason I get random NPE here and can't figure out why so to avoid bigger issues, I just catch it.
+            return null;
         }
 
         //Logger.getLogger(MaterialDebugAppState.class.getName()).log(Level.INFO, "Material succesfully reloaded");