|
@@ -2,16 +2,40 @@ package hrt.shgraph.nodes;
|
|
|
|
|
|
using hxsl.Ast;
|
|
|
|
|
|
+import hrt.shgraph.AstTools.*;
|
|
|
+
|
|
|
@name("Condition")
|
|
|
@description("Create a custom condition between two inputs")
|
|
|
@group("Condition")
|
|
|
class Cond extends ShaderNode {
|
|
|
|
|
|
+ override public function getShaderDef(domain: ShaderGraph.Domain, getNewIdFn : () -> Int, ?inputTypes: Array<Type>) : ShaderGraph.ShaderNodeDef {
|
|
|
+
|
|
|
+ var a : TVar = {name : "a", id: getNewIdFn(), type: TFloat, kind: Local, qualifiers: []};
|
|
|
+ var b : TVar = {name : "b", id: getNewIdFn(), type: TFloat, kind: Local, qualifiers: []};
|
|
|
+
|
|
|
+ var out : TVar = {name: "out", id: getNewIdFn(), type: TBool, kind: Local, qualifiers: []};
|
|
|
+
|
|
|
+ var cond = makeExpr(TBinop(condition, makeVar(a), makeVar(b)), TBool);
|
|
|
+ var expr = makeAssign(makeVar(out), cond);
|
|
|
+ return {
|
|
|
+ expr: expr,
|
|
|
+ inVars: [{v:a, internal: false, defVal: Const(0.0), isDynamic: false}, {v:b, internal: false, defVal: Const(0.0), isDynamic: false}],
|
|
|
+ outVars:[{v:out, internal: false, isDynamic: false}],
|
|
|
+ inits: [],
|
|
|
+ externVars: []
|
|
|
+ };
|
|
|
+ };
|
|
|
+
|
|
|
+ override function canHavePreview():Bool {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
// @input("Left") var leftVar = SType.Number;
|
|
|
// @input("Right") var rightVar = SType.Number;
|
|
|
|
|
|
|
|
|
- // @prop() var condition : Binop;
|
|
|
+ @prop() var condition : Binop = OpEq;
|
|
|
|
|
|
// override public function checkValidityInput(key : String, type : ShaderType.SType) : Bool {
|
|
|
|
|
@@ -55,51 +79,54 @@ class Cond extends ShaderNode {
|
|
|
// };
|
|
|
// }
|
|
|
|
|
|
- // var availableConditions = [OpEq, OpNotEq, OpGt, OpGte, OpLt, OpLte, OpAnd, OpOr];
|
|
|
- // var conditionStrings = ["==", "!=", ">", ">=", "<", "<=", "AND", "OR"];
|
|
|
-
|
|
|
- // override public function loadProperties(props : Dynamic) {
|
|
|
- // this.condition = std.Type.createEnum(Binop, Reflect.field(props, "Condition"));
|
|
|
- // }
|
|
|
-
|
|
|
- // override public function saveProperties() : Dynamic {
|
|
|
- // if (this.condition == null)
|
|
|
- // this.condition = availableConditions[0];
|
|
|
- // var properties = {
|
|
|
- // condition: this.condition.getName()
|
|
|
- // };
|
|
|
-
|
|
|
- // return properties;
|
|
|
- // }
|
|
|
-
|
|
|
- // #if editor
|
|
|
- // override public function getPropertiesHTML(width : Float) : Array<hide.Element> {
|
|
|
- // var elements = super.getPropertiesHTML(width);
|
|
|
- // var element = new hide.Element('<div style="width: ${width * 0.8}px; height: 40px"></div>');
|
|
|
- // element.append('<span>Condition</span>');
|
|
|
- // element.append(new hide.Element('<select id="condition"></select>'));
|
|
|
-
|
|
|
- // if (this.condition == null) {
|
|
|
- // this.condition = availableConditions[0];
|
|
|
- // }
|
|
|
- // var input = element.children("select");
|
|
|
- // var indexOption = 0;
|
|
|
- // for (c in conditionStrings) {
|
|
|
- // input.append(new hide.Element('<option value="${indexOption}">${c}</option>'));
|
|
|
- // if (this.condition == availableConditions[indexOption]) {
|
|
|
- // input.val(indexOption);
|
|
|
- // }
|
|
|
- // indexOption++;
|
|
|
- // }
|
|
|
- // input.on("change", function(e) {
|
|
|
- // var value = input.val();
|
|
|
- // this.condition = availableConditions[value];
|
|
|
- // });
|
|
|
-
|
|
|
- // elements.push(element);
|
|
|
-
|
|
|
- // return elements;
|
|
|
- // }
|
|
|
- // #end
|
|
|
+ static var availableConditions = [OpEq, OpNotEq, OpGt, OpGte, OpLt, OpLte, OpAnd, OpOr];
|
|
|
+ static var conditionStrings = ["==", "!=", ">", ">=", "<", "<=", "AND", "OR"];
|
|
|
+
|
|
|
+ override public function loadProperties(props : Dynamic) {
|
|
|
+ if (Reflect.hasField(props, "condition"))
|
|
|
+ this.condition = std.Type.createEnum(Binop, Reflect.field(props, "condition"));
|
|
|
+ else
|
|
|
+ this.condition = OpEq;
|
|
|
+ }
|
|
|
+
|
|
|
+ override public function saveProperties() : Dynamic {
|
|
|
+ if (this.condition == null)
|
|
|
+ this.condition = availableConditions[0];
|
|
|
+ var properties = {
|
|
|
+ condition: this.condition.getName()
|
|
|
+ };
|
|
|
+
|
|
|
+ return properties;
|
|
|
+ }
|
|
|
+
|
|
|
+ #if editor
|
|
|
+ override public function getPropertiesHTML(width : Float) : Array<hide.Element> {
|
|
|
+ var elements = super.getPropertiesHTML(width);
|
|
|
+ var element = new hide.Element('<div style="width: ${width * 0.8}px; height: 40px"></div>');
|
|
|
+ element.append('<span>Condition</span>');
|
|
|
+ element.append(new hide.Element('<select id="condition"></select>'));
|
|
|
+
|
|
|
+ if (this.condition == null) {
|
|
|
+ this.condition = availableConditions[0];
|
|
|
+ }
|
|
|
+ var input = element.children("select");
|
|
|
+ var indexOption = 0;
|
|
|
+ for (c in conditionStrings) {
|
|
|
+ input.append(new hide.Element('<option value="${indexOption}">${c}</option>'));
|
|
|
+ if (this.condition == availableConditions[indexOption]) {
|
|
|
+ input.val(indexOption);
|
|
|
+ }
|
|
|
+ indexOption++;
|
|
|
+ }
|
|
|
+ input.on("change", function(e) {
|
|
|
+ var value = input.val();
|
|
|
+ this.condition = availableConditions[value];
|
|
|
+ });
|
|
|
+
|
|
|
+ elements.push(element);
|
|
|
+
|
|
|
+ return elements;
|
|
|
+ }
|
|
|
+ #end
|
|
|
|
|
|
}
|