| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- package arm.logic;
- import iron.math.Vec4;
- import zui.Nodes;
- import arm.logic.LogicNode;
- import arm.logic.LogicParser.f32;
- import arm.Translator._tr;
- @:keep
- class VectorNode extends LogicNode {
- var value = new Vec4();
- var image: kha.Image = null;
- public function new(tree: LogicTree, x: Null<Float> = null, y: Null<Float> = null, z: Null<Float> = null) {
- super(tree);
- if (x != null) {
- addInput(new FloatNode(tree, x), 0);
- addInput(new FloatNode(tree, y), 0);
- addInput(new FloatNode(tree, z), 0);
- }
- }
- override function get(from: Int, done: Dynamic->Void) {
- inputs[0].get(function(x: Float) {
- inputs[1].get(function(y: Float) {
- inputs[2].get(function(z: Float) {
- value.x = x;
- value.y = y;
- value.z = z;
- done(value);
- });
- });
- });
- }
- override function getAsImage(from: Int, done: kha.Image->Void) {
- inputs[0].get(function(x: Float) {
- inputs[1].get(function(y: Float) {
- inputs[2].get(function(z: Float) {
- if (image != null) image.unload();
- var b = haxe.io.Bytes.alloc(16);
- b.setFloat(0, untyped inputs[0].node.value);
- b.setFloat(4, untyped inputs[1].node.value);
- b.setFloat(8, untyped inputs[2].node.value);
- b.setFloat(12, 1.0);
- image = kha.Image.fromBytes(b, 1, 1, kha.graphics4.TextureFormat.RGBA128);
- done(image);
- });
- });
- });
- }
- override function set(value: Dynamic) {
- inputs[0].set(value.x);
- inputs[1].set(value.y);
- inputs[2].set(value.z);
- }
- public static var def: TNode = {
- id: 0,
- name: _tr("Vector"),
- type: "VectorNode",
- x: 0,
- y: 0,
- color: 0xff4982a0,
- inputs: [
- {
- id: 0,
- node_id: 0,
- name: _tr("X"),
- type: "VALUE",
- color: 0xffa1a1a1,
- default_value: 0.0
- },
- {
- id: 0,
- node_id: 0,
- name: _tr("Y"),
- type: "VALUE",
- color: 0xffa1a1a1,
- default_value: 0.0
- },
- {
- id: 0,
- node_id: 0,
- name: _tr("Z"),
- type: "VALUE",
- color: 0xffa1a1a1,
- default_value: 0.0
- }
- ],
- outputs: [
- {
- id: 0,
- node_id: 0,
- name: _tr("Vector"),
- type: "VECTOR",
- color: 0xff6363c7,
- default_value: f32([0.0, 0.0, 0.0])
- }
- ],
- buttons: []
- };
- }
|