2
0
Эх сурвалжийг харах

Fix bug on cond params + refresh editor

Tom SPIRA 6 жил өмнө
parent
commit
ad0c42ea18

+ 3 - 0
bin/style.css

@@ -1167,6 +1167,9 @@ input[type=checkbox]:checked:after {
 .shader-view .heaps-scene svg .parameters-group select {
 .shader-view .heaps-scene svg .parameters-group select {
   width: 100%;
   width: 100%;
 }
 }
+.shader-view .heaps-scene svg .parameters-group input[type=text].error {
+  border: red 1px solid;
+}
 .shader-view .heaps-scene svg .edge {
 .shader-view .heaps-scene svg .edge {
   stroke-width: 2;
   stroke-width: 2;
   stroke: #c8c8c8;
   stroke: #c8c8c8;

+ 3 - 0
bin/style.less

@@ -1307,6 +1307,9 @@ input[type=checkbox] {
 				input[type=text], select {
 				input[type=text], select {
 					width: 100%;
 					width: 100%;
 				}
 				}
+				input[type=text].error {
+					border: red 1px solid;
+				}
 			}
 			}
 
 
 			.edge {
 			.edge {

+ 11 - 8
hide/view/ShaderEditor.hx

@@ -327,7 +327,11 @@ class ShaderEditor extends FileView {
 			});
 			});
 		}
 		}
 
 
-		new Element("body").ready(function(e) {
+		listOfBoxes = [];
+		listOfEdges = [];
+
+		new Element("svg").ready(function(e) {
+
 			for (node in shaderGraph.getNodes()) {
 			for (node in shaderGraph.getNodes()) {
 				addBox(new Point(node.x, node.y), std.Type.getClass(node.instance), node.instance);
 				addBox(new Point(node.x, node.y), std.Type.getClass(node.instance), node.instance);
 			}
 			}
@@ -539,18 +543,17 @@ class ShaderEditor extends FileView {
 			endLinkNode = tmpNode;
 			endLinkNode = tmpNode;
 		}
 		}
 
 
-		var edge = { from: startLinkBox, nodeFrom : startLinkNode, to : endLinkBox, nodeTo : endLinkNode, elt : currentLink };
+		var newEdge = { from: startLinkBox, nodeFrom : startLinkNode, to : endLinkBox, nodeTo : endLinkNode, elt : currentLink };
 		if (endLinkNode.attr("hasLink") != null) {
 		if (endLinkNode.attr("hasLink") != null) {
-			var length = listOfEdges.length;
-			for (i in 0...length) {
-				var e = listOfEdges[length-i-1];
-				if (e.to == edge.to) {
-					removeEdge(e);
+			for (edge in listOfEdges) {
+				if (edge.nodeTo.is(endLinkNode)) {
+					removeEdge(edge);
+					break;
 				}
 				}
 			}
 			}
 		}
 		}
 		shaderGraph.addEdge({ idOutput: startLinkBox.getId(), nameOutput: startLinkNode.attr("field"), idInput: endLinkBox.getId(), nameInput: endLinkNode.attr("field") });
 		shaderGraph.addEdge({ idOutput: startLinkBox.getId(), nameOutput: startLinkNode.attr("field"), idInput: endLinkBox.getId(), nameInput: endLinkNode.attr("field") });
-		createEdgeInEditorGraph(edge);
+		createEdgeInEditorGraph(newEdge);
 		currentLink.removeClass("draft");
 		currentLink.removeClass("draft");
 		currentLink = null;
 		currentLink = null;
 	}
 	}

+ 11 - 2
hrt/shgraph/nodes/Cond.hx

@@ -46,9 +46,13 @@ class Cond extends ShaderNode {
 			};
 			};
 	}
 	}
 
 
-	var availableConditions = [OpEq, OpNotEq, OpGt, OpGte, OpLt, OpLte, OpAnd, OpOr];
+	var availableConditions : Array<Binop> = [OpEq, OpNotEq, OpGt, OpGte, OpLt, OpLte, OpAnd, OpOr];
 	var conditionStrings 	= ["==", "!=",    ">",  ">=",  "<",  "<=",  "AND", "OR"];
 	var conditionStrings 	= ["==", "!=",    ">",  ">=",  "<",  "<=",  "AND", "OR"];
 
 
+	override public function loadParameters(params : Dynamic) {
+		this.condition = std.Type.createEnum(Binop, Reflect.field(params, "condition"));
+	}
+
 	override public function saveParameters() : Dynamic {
 	override public function saveParameters() : Dynamic {
 		var parameters = {
 		var parameters = {
 			condition: this.condition.getName()
 			condition: this.condition.getName()
@@ -64,17 +68,22 @@ class Cond extends ShaderNode {
 		element.append('<span>Condition</span>');
 		element.append('<span>Condition</span>');
 		element.append(new Element('<select id="condition"></select>'));
 		element.append(new Element('<select id="condition"></select>'));
 
 
+		if (this.condition == null) {
+			this.condition = availableConditions[0];
+		}
 		var input = element.children("select");
 		var input = element.children("select");
 		var indexOption = 0;
 		var indexOption = 0;
 		for (c in conditionStrings) {
 		for (c in conditionStrings) {
 			input.append(new Element('<option value="${indexOption}">${c}</option>'));
 			input.append(new Element('<option value="${indexOption}">${c}</option>'));
+			if (this.condition == availableConditions[indexOption]) {
+				input.val(indexOption);
+			}
 			indexOption++;
 			indexOption++;
 		}
 		}
 		input.on("change", function(e) {
 		input.on("change", function(e) {
 			var value = input.val();
 			var value = input.val();
 			this.condition = availableConditions[value];
 			this.condition = availableConditions[value];
 		});
 		});
-		this.condition = availableConditions[0];
 
 
 		elements.push(element);
 		elements.push(element);
 
 

+ 7 - 4
hrt/shgraph/nodes/FloatConst.hx

@@ -33,10 +33,13 @@ class FloatConst extends ShaderConst {
 
 
 		var input = element.children("input");
 		var input = element.children("input");
 		input.on("change", function(e) {
 		input.on("change", function(e) {
-			try {
-				value = Std.parseFloat(input.val());
-			} catch (e : Dynamic) {
-
+			var tmpValue = Std.parseFloat(input.val());
+			if (Math.isNaN(tmpValue) ) {
+				input.addClass("error");
+			} else {
+				this.value = tmpValue;
+				input.val(tmpValue);
+				input.removeClass("error");
 			}
 			}
 		});
 		});
 
 

+ 30 - 0
hrt/shgraph/nodes/Sampler.hx

@@ -0,0 +1,30 @@
+package hrt.shgraph.nodes;
+
+import hxsl.*;
+
+using hxsl.Ast;
+
+/*
+@name("Sampler")
+@description("Get color from texture and UV")
+@group("AAAAA")
+*/
+class Sampler extends ShaderNode {
+
+	@input("u") var u = SType.Float;
+	@input("v") var v = SType.Float;
+
+	@output("rgba") var rgba = SType.Vec4;
+
+	var components = [X, Y, Z, W];
+	var componentsString = ["r", "g", "b", "a"];
+
+	override public function createOutputs() {
+		addOutput("rgba", TVec(4, VFloat));
+	}
+
+	override public function build(key : String) : TExpr {
+		return null;
+	}
+
+}