One can now add a new technique to a mat def with the node Editor.

Also added an experimental auto layout feature
experimental
Nehon 10 years ago
parent 0e6bc92d19
commit f1b038796e
  1. 21
      sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/EditableMatDefFile.java
  2. 36
      sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/MatDefDataObject.java
  3. 7
      sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/BackdropPanel.java
  4. 3
      sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/Bundle.properties
  5. 10
      sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/ConnectionCurve.java
  6. 72
      sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/Diagram.java
  7. 54
      sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/MatDefEditorToolBar.form
  8. 71
      sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/MatDefEditorToolBar.java
  9. 63
      sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/MatDefEditorlElement.java
  10. 5
      sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/MatPanel.java
  11. 7
      sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/OutBusPanel.java
  12. 5
      sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/fileStructure/TechniqueBlock.java
  13. 33
      sdk/jme3-materialeditor/src/com/jme3/gde/materials/MaterialPreviewRenderer.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);
}
}

@ -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);
@ -298,42 +299,13 @@ public class MatDefDataObject extends MultiDataObject {
if (loaded) {
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());
//
// }
}

@ -86,6 +86,13 @@ public class BackdropPanel extends javax.swing.JPanel implements MouseListener,
}
}
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.
* WARNING: Do NOT modify this code. The content of this method is always

@ -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

@ -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;
}
}

@ -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());
@ -421,7 +419,6 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
}
}
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) {
}

@ -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>

@ -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;
/**
@ -22,6 +23,7 @@ public class MatDefEditorToolBar extends javax.swing.JPanel {
private MatDefEditorlElement parent;
private final DefaultComboBoxModel<TechniqueBlock> comboModel = new DefaultComboBoxModel<TechniqueBlock>();
/**
* Creates new form MatDefEditorToolBar
*/
@ -32,9 +34,9 @@ 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;
}
});
@ -44,7 +46,9 @@ public class MatDefEditorToolBar extends javax.swing.JPanel {
this.parent = parent;
}
public void addTechnique(List<TechniqueBlock> tech){
public void addTechnique(List<TechniqueBlock> tech) {
comboModel.removeAllElements();
for (TechniqueBlock tech1 : tech) {
comboModel.addElement(tech1);
}
@ -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
}

@ -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);
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";
@ -288,8 +296,7 @@ public final class MatDefEditorlElement extends JPanel implements MultiViewEleme
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);
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);

@ -44,6 +44,11 @@ public class MatPanel extends javax.swing.JPanel implements MouseListener, Compo
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);
}

@ -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());
vmat.getAdditionalRenderState().setWireframe(true);
preview.showMaterial(vmat);
preview.showMaterial(vmat,technique);
}
}

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

@ -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");

Loading…
Cancel
Save