VectorNode.hx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. package arm.logic;
  2. import iron.math.Vec4;
  3. import zui.Nodes;
  4. import arm.logic.LogicNode;
  5. import arm.logic.LogicParser.f32;
  6. import arm.Translator._tr;
  7. @:keep
  8. class VectorNode extends LogicNode {
  9. var value = new Vec4();
  10. var image: kha.Image = null;
  11. public function new(tree: LogicTree, x: Null<Float> = null, y: Null<Float> = null, z: Null<Float> = null) {
  12. super(tree);
  13. if (x != null) {
  14. addInput(new FloatNode(tree, x), 0);
  15. addInput(new FloatNode(tree, y), 0);
  16. addInput(new FloatNode(tree, z), 0);
  17. }
  18. }
  19. override function get(from: Int, done: Dynamic->Void) {
  20. inputs[0].get(function(x: Float) {
  21. inputs[1].get(function(y: Float) {
  22. inputs[2].get(function(z: Float) {
  23. value.x = x;
  24. value.y = y;
  25. value.z = z;
  26. done(value);
  27. });
  28. });
  29. });
  30. }
  31. override function getAsImage(from: Int, done: kha.Image->Void) {
  32. inputs[0].get(function(x: Float) {
  33. inputs[1].get(function(y: Float) {
  34. inputs[2].get(function(z: Float) {
  35. if (image != null) image.unload();
  36. var b = haxe.io.Bytes.alloc(16);
  37. b.setFloat(0, untyped inputs[0].node.value);
  38. b.setFloat(4, untyped inputs[1].node.value);
  39. b.setFloat(8, untyped inputs[2].node.value);
  40. b.setFloat(12, 1.0);
  41. image = kha.Image.fromBytes(b, 1, 1, kha.graphics4.TextureFormat.RGBA128);
  42. done(image);
  43. });
  44. });
  45. });
  46. }
  47. override function set(value: Dynamic) {
  48. inputs[0].set(value.x);
  49. inputs[1].set(value.y);
  50. inputs[2].set(value.z);
  51. }
  52. public static var def: TNode = {
  53. id: 0,
  54. name: _tr("Vector"),
  55. type: "VectorNode",
  56. x: 0,
  57. y: 0,
  58. color: 0xff4982a0,
  59. inputs: [
  60. {
  61. id: 0,
  62. node_id: 0,
  63. name: _tr("X"),
  64. type: "VALUE",
  65. color: 0xffa1a1a1,
  66. default_value: 0.0
  67. },
  68. {
  69. id: 0,
  70. node_id: 0,
  71. name: _tr("Y"),
  72. type: "VALUE",
  73. color: 0xffa1a1a1,
  74. default_value: 0.0
  75. },
  76. {
  77. id: 0,
  78. node_id: 0,
  79. name: _tr("Z"),
  80. type: "VALUE",
  81. color: 0xffa1a1a1,
  82. default_value: 0.0
  83. }
  84. ],
  85. outputs: [
  86. {
  87. id: 0,
  88. node_id: 0,
  89. name: _tr("Vector"),
  90. type: "VECTOR",
  91. color: 0xff6363c7,
  92. default_value: f32([0.0, 0.0, 0.0])
  93. }
  94. ],
  95. buttons: []
  96. };
  97. }