More controls when connecting inputs and outputs in the node editor

experimental
Nehon 10 years ago
parent 9500b43aa9
commit 1286fa0fba
  1. 15
      sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/Dot.java
  2. 3
      sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/NodePanel.java
  3. 19
      sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/OutBusPanel.java
  4. 8
      sdk/jme3-materialeditor/src/com/jme3/gde/shadernodedefinition/ShaderNodeSource

@ -5,6 +5,7 @@
package com.jme3.gde.materialdefinition.editor; package com.jme3.gde.materialdefinition.editor;
import com.jme3.gde.materialdefinition.icons.Icons; import com.jme3.gde.materialdefinition.icons.Icons;
import com.jme3.shader.Shader;
import com.jme3.shader.ShaderUtils; import com.jme3.shader.ShaderUtils;
import java.awt.Component; import java.awt.Component;
import java.awt.Dimension; import java.awt.Dimension;
@ -27,6 +28,7 @@ public class Dot extends JPanel implements MouseInputListener {
protected ImageIcon prevImg; protected ImageIcon prevImg;
private String type; private String type;
private ParamType paramType; private ParamType paramType;
protected Shader.ShaderType shaderType;
private String text = ""; private String text = "";
private DraggablePanel node; private DraggablePanel node;
private int index = 1; private int index = 1;
@ -46,6 +48,7 @@ public class Dot extends JPanel implements MouseInputListener {
Both Both
} }
@SuppressWarnings("LeakingThisInConstructor")
public Dot() { public Dot() {
super(); super();
setMaximumSize(new Dimension(10, 10)); setMaximumSize(new Dimension(10, 10));
@ -54,6 +57,11 @@ public class Dot extends JPanel implements MouseInputListener {
setSize(10, 10); setSize(10, 10);
addMouseMotionListener(this); addMouseMotionListener(this);
addMouseListener(this); addMouseListener(this);
}
public void setShaderTypr(Shader.ShaderType shaderType){
this.shaderType = shaderType;
} }
@Override @Override
@ -143,14 +151,15 @@ public class Dot extends JPanel implements MouseInputListener {
} }
public boolean canConnect(Dot pair) { public boolean canConnect(Dot pair) {
if (pair == null) {
if (pair == null || paramType == ParamType.Input ||
((pair.getNode() instanceof OutBusPanel || node instanceof OutBusPanel) && shaderType != pair.shaderType)) {
img = Icons.imgOrange; img = Icons.imgOrange;
repaint(); repaint();
return false; return false;
} }
if (matches(pair.getType(), type) && (pair.getParamType() != paramType if (matches(pair.getType(), type) && (pair.getParamType() != paramType
|| pair.getParamType() == ParamType.Both || pair.getParamType() == ParamType.Both
|| paramType == ParamType.Both) || paramType == ParamType.Both)

@ -54,6 +54,7 @@ public class NodePanel extends DraggablePanel implements Selectable, PropertyCha
private String techName; private String techName;
private NodeToolBar toolBar; private NodeToolBar toolBar;
protected List<String> filePaths = new ArrayList<String>(); protected List<String> filePaths = new ArrayList<String>();
protected Shader.ShaderType shaderType;
// private List listeners = Collections.synchronizedList(new LinkedList()); // private List listeners = Collections.synchronizedList(new LinkedList());
// //
@ -99,6 +100,7 @@ public class NodePanel extends DraggablePanel implements Selectable, PropertyCha
@SuppressWarnings("LeakingThisInConstructor") @SuppressWarnings("LeakingThisInConstructor")
public NodePanel(ShaderNodeBlock node, ShaderNodeDefinition def) { public NodePanel(ShaderNodeBlock node, ShaderNodeDefinition def) {
super(); super();
shaderType = def.getType();
if (def.getType() == Shader.ShaderType.Vertex) { if (def.getType() == Shader.ShaderType.Vertex) {
type = NodePanel.NodeType.Vertex; type = NodePanel.NodeType.Vertex;
} else { } else {
@ -419,6 +421,7 @@ public class NodePanel extends DraggablePanel implements Selectable, PropertyCha
public Dot createDot(String type, Dot.ParamType paramType, String paramName) { public Dot createDot(String type, Dot.ParamType paramType, String paramName) {
Dot dot1 = new Dot(); Dot dot1 = new Dot();
dot1.setShaderTypr(shaderType);
dot1.setNode(this); dot1.setNode(this);
dot1.setText(paramName); dot1.setText(paramName);
dot1.setParamType(paramType); dot1.setParamType(paramType);

@ -33,20 +33,16 @@ public class OutBusPanel extends DraggablePanel implements ComponentListener, Se
private Color color = new Color(220, 220, 70); private Color color = new Color(220, 220, 70);
private String name = ""; private String name = "";
private InnerPanel panel; private final InnerPanel panel;
private MatPanel preview; private final MatPanel preview;
private Shader.ShaderType type; private final Shader.ShaderType type;
public OutBusPanel(String name, Shader.ShaderType type) { public OutBusPanel(String name, Shader.ShaderType type) {
this(name); super(true);
this.type = type; this.type = type;
if (type == Shader.ShaderType.Fragment) { if (type == Shader.ShaderType.Fragment) {
this.color = new Color(114, 200, 255); this.color = new Color(114, 200, 255);
} }
}
private OutBusPanel(String name) {
super(true);
setBounds(0, 0, 300, 50); setBounds(0, 0, 300, 50);
JLabel title = new JLabel(); JLabel title = new JLabel();
this.name = name; this.name = name;
@ -96,7 +92,11 @@ public class OutBusPanel extends DraggablePanel implements ComponentListener, Se
}); });
} }
public Shader.ShaderType getType(){
return type;
}
@Override @Override
protected void paintComponent(Graphics g1) { protected void paintComponent(Graphics g1) {
Graphics2D g = (Graphics2D) g1; Graphics2D g = (Graphics2D) g1;
@ -236,6 +236,7 @@ public class OutBusPanel extends DraggablePanel implements ComponentListener, Se
boolean dragging = false; boolean dragging = false;
public InnerPanel() { public InnerPanel() {
this.shaderType = OutBusPanel.this.type;
setOpaque(false); setOpaque(false);
setNode(OutBusPanel.this); setNode(OutBusPanel.this);
setParamType(Dot.ParamType.Both); setParamType(Dot.ParamType.Both);

@ -1,11 +1,11 @@
void main(){ void main(){
<#list inputParams as param> <#list inputParams as param>
//@input ${param[0]} ${param[1]} ${param[2]} //@input ${param[0]} ${param[1]} ${param[2]}
</#list> </#list>
<#list outputParams as param> <#list outputParams as param>
//@output ${param[0]} ${param[1]} ${param[2]} //@output ${param[0]} ${param[1]} ${param[2]}
</#list> </#list>
//insert glsl code here //insert glsl code here
} }
Loading…
Cancel
Save