| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- package arm.logic;
- import zui.Nodes;
- import arm.logic.LogicNode;
- import arm.Translator._tr;
- @:keep
- class MathNode extends LogicNode {
- public var operation: String;
- public var use_clamp: Bool;
- public function new(tree: LogicTree) {
- super(tree);
- }
- override function get(from: Int, done: Dynamic->Void) {
- inputs[0].get(function(v1: Float) {
- inputs[1].get(function(v2: Float) {
- var f = 0.0;
- switch (operation) {
- case "Add":
- f = v1 + v2;
- case "Multiply":
- f = v1 * v2;
- case "Sine":
- f = Math.sin(v1);
- case "Cosine":
- f = Math.cos(v1);
- case "Max":
- f = Math.max(v1, v2);
- case "Min":
- f = Math.min(v1, v2);
- case "Absolute":
- f = Math.abs(v1);
- case "Subtract":
- f = v1 - v2;
- case "Divide":
- f = v1 / (v2 == 0.0 ? 0.000001 : v2);
- case "Tangent":
- f = Math.tan(v1);
- case "Arcsine":
- f = Math.asin(v1);
- case "Arccosine":
- f = Math.acos(v1);
- case "Arctangent":
- f = Math.atan(v1);
- case "Arctan2":
- f = Math.atan2(v2, v1);
- case "Power":
- f = Math.pow(v1, v2);
- case "Logarithm":
- f = Math.log(v1);
- case "Round":
- f = Math.round(v1);
- case "Floor":
- f = Math.floor(v1);
- case "Ceil":
- f = Math.ceil(v1);
- case "Truncate":
- f = Math.ffloor(v1);
- case "Fraction":
- f = v1 - Math.floor(v1);
- case "Less Than":
- f = v1 < v2 ? 1.0 : 0.0;
- case "Greater Than":
- f = v1 > v2 ? 1.0 : 0.0;
- case "Modulo":
- f = v1 % v2;
- case "Snap":
- f = Math.floor(v1 / v2) * v2;
- case "Square Root":
- f = Math.sqrt(v1);
- case "Inverse Square Root":
- f = 1.0 / Math.sqrt(v1);
- case "Exponent":
- f = Math.exp(v1);
- case "Sign":
- f = v1 > 0 ? 1.0 : (v1 < 0 ? -1.0 : 0);
- case "Ping-Pong":
- f = (v2 != 0.0) ? v2 - Math.abs((Math.abs(v1) % (2 * v2)) - v2) : 0.0;
- case "Hyperbolic Sine":
- f = (Math.exp(v1) - Math.exp(-v1)) / 2.0;
- case "Hyperbolic Cosine":
- f = (Math.exp(v1) + Math.exp(-v1)) / 2.0;
- case "Hyperbolic Tangent":
- f = 1.0 - (2.0 / (Math.exp(2 * v1) + 1));
- case "To Radians":
- f = v1 / 180.0 * Math.PI;
- case "To Degrees":
- f = v1 / Math.PI * 180.0;
- }
- if (use_clamp) f = f < 0.0 ? 0.0 : (f > 1.0 ? 1.0 : f);
- done(f);
- });
- });
- }
- public static var def: TNode = {
- id: 0,
- name: _tr("Math"),
- type: "MathNode",
- x: 0,
- y: 0,
- color: 0xff4982a0,
- inputs: [
- {
- id: 0,
- node_id: 0,
- name: _tr("Value"),
- type: "VALUE",
- color: 0xffa1a1a1,
- default_value: 0.5
- },
- {
- id: 0,
- node_id: 0,
- name: _tr("Value"),
- type: "VALUE",
- color: 0xffa1a1a1,
- default_value: 0.5
- }
- ],
- outputs: [
- {
- id: 0,
- node_id: 0,
- name: _tr("Value"),
- type: "VALUE",
- color: 0xffa1a1a1,
- default_value: 0.0
- }
- ],
- buttons: [
- {
- name: _tr("operation"),
- type: "ENUM",
- data: ["Add", "Subtract", "Multiply", "Divide", "Power", "Logarithm", "Square Root", "Inverse Square Root", "Absolute", "Exponent", "Minimum", "Maximum", "Less Than", "Greater Than", "Sign", "Round", "Floor", "Ceil", "Truncate", "Fraction", "Modulo", "Snap", "Ping-Pong", "Sine", "Cosine", "Tangent", "Arcsine", "Arccosine", "Arctangent", "Arctan2", "Hyperbolic Sine", "Hyperbolic Cosine", "Hyperbolic Tangent", "To Radians", "To Degrees"],
- default_value: 0,
- output: 0
- },
- {
- name: _tr("use_clamp"),
- type: "BOOL",
- default_value: false,
- output: 0
- }
- ]
- };
- }
|