diff --git a/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/EditableMatDefFile.java b/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/EditableMatDefFile.java
index 6ce9dd2d9..73797cadc 100644
--- a/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/EditableMatDefFile.java
+++ b/sdk/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);
+ }
}
diff --git a/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/MatDefDataObject.java b/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/MatDefDataObject.java
index 5e7fb5083..634792505 100644
--- a/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/MatDefDataObject.java
+++ b/sdk/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());
-//
-// }
+
}
diff --git a/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/BackdropPanel.java b/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/BackdropPanel.java
index 5855d01f1..723d9b577 100644
--- a/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/BackdropPanel.java
+++ b/sdk/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.
diff --git a/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/Bundle.properties b/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/Bundle.properties
index 1e401f9a9..917191974 100644
--- a/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/Bundle.properties
+++ b/sdk/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
diff --git a/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/ConnectionCurve.java b/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/ConnectionCurve.java
index e0bf6664b..ec2f4aa98 100644
--- a/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/ConnectionCurve.java
+++ b/sdk/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;
+ }
+
+
}
diff --git a/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/Diagram.java b/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/Diagram.java
index 423a0c1be..9d344355e 100644
--- a/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/Diagram.java
+++ b/sdk/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) {
}
diff --git a/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/MatDefEditorToolBar.form b/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/MatDefEditorToolBar.form
index 38d7c8c1e..0fb4d449f 100644
--- a/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/MatDefEditorToolBar.form
+++ b/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/MatDefEditorToolBar.form
@@ -3,7 +3,7 @@
diff --git a/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/MatDefEditorToolBar.java b/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/MatDefEditorToolBar.java
index dbbdefb82..5ad859fcf 100644
--- a/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/MatDefEditorToolBar.java
+++ b/sdk/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 comboModel = new DefaultComboBoxModel();
+ private final DefaultComboBoxModel comboModel = new DefaultComboBoxModel();
+
/**
* Creates new form MatDefEditorToolBar
*/
@@ -32,25 +34,27 @@ public class MatDefEditorToolBar extends javax.swing.JPanel {
techniqueComboBox.setRenderer(new ListCellRenderer() {
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 tech){
+
+ public void addTechnique(List 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)
);
}// //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
}
diff --git a/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/MatDefEditorlElement.java b/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/MatDefEditorlElement.java
index 0184a29d8..762b24ef5 100644
--- a/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/MatDefEditorlElement.java
+++ b/sdk/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 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 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 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);
diff --git a/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/MatPanel.java b/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/MatPanel.java
index db8da01da..f92ed9491 100644
--- a/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/MatPanel.java
+++ b/sdk/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);
diff --git a/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/NodePanel.java b/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/NodePanel.java
index 81355ae44..49e04170d 100644
--- a/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/NodePanel.java
+++ b/sdk/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);
}
/**
diff --git a/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/OutBusPanel.java b/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/OutBusPanel.java
index ee3c18009..521776dce 100644
--- a/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/OutBusPanel.java
+++ b/sdk/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);
}
}
diff --git a/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/fileStructure/TechniqueBlock.java b/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/fileStructure/TechniqueBlock.java
index b364e6330..26bba097c 100644
--- a/sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/fileStructure/TechniqueBlock.java
+++ b/sdk/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;
diff --git a/sdk/jme3-materialeditor/src/com/jme3/gde/materials/MaterialPreviewRenderer.java b/sdk/jme3-materialeditor/src/com/jme3/gde/materials/MaterialPreviewRenderer.java
index 19b928d66..2c94e90f2 100644
--- a/sdk/jme3-materialeditor/src/com/jme3/gde/materials/MaterialPreviewRenderer.java
+++ b/sdk/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() {
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");