Browse Source

More controls when connecting inputs and outputs in the node editor

Nehon 10 years ago
parent
commit
f39cce5b93

+ 12 - 3
jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/Dot.java

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

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

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

+ 10 - 9
jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/OutBusPanel.java

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

+ 4 - 4
jme3-materialeditor/src/com/jme3/gde/shadernodedefinition/ShaderNodeSource

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