float_node.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. type float_node_t = {
  2. base?: logic_node_t;
  3. value?: f32;
  4. image?: image_t;
  5. };
  6. function float_node_create(raw: ui_node_t, args: f32_array_t): float_node_t {
  7. let n: float_node_t = {};
  8. n.base = logic_node_create(n);
  9. n.base.get = float_node_get;
  10. n.base.get_as_image = float_node_get_as_image;
  11. n.base.set = float_node_set;
  12. n.value = args == null ? 0.5 : args[0];
  13. return n;
  14. }
  15. function float_node_get(self: float_node_t, from: i32): logic_node_value_t {
  16. if (self.base.inputs.length > 0) {
  17. return logic_node_input_get(self.base.inputs[0]);
  18. }
  19. else {
  20. let v: logic_node_value_t = { _f32: self.value };
  21. return v;
  22. }
  23. }
  24. function float_node_get_as_image(self: float_node_t, from: i32): image_t {
  25. if (self.base.inputs.length > 0) {
  26. return logic_node_input_get_as_image(self.base.inputs[0]);
  27. }
  28. if (self.image != null) {
  29. image_unload(self.image);
  30. }
  31. let b: buffer_t = buffer_create(16);
  32. buffer_set_f32(b, 0, self.value);
  33. buffer_set_f32(b, 4, self.value);
  34. buffer_set_f32(b, 8, self.value);
  35. buffer_set_f32(b, 12, 1.0);
  36. self.image = image_from_bytes(b, 1, 1, tex_format_t.RGBA128);
  37. return self.image;
  38. }
  39. function float_node_set(self: float_node_t, value: f32_array_t) {
  40. if (self.base.inputs.length > 0) {
  41. logic_node_input_set(self.base.inputs[0], value);
  42. }
  43. else {
  44. self.value = value[0];
  45. }
  46. }
  47. let float_node_def: ui_node_t = {
  48. id: 0,
  49. name: _tr("Value"),
  50. type: "float_node",
  51. x: 0,
  52. y: 0,
  53. color: 0xffb34f5a,
  54. inputs: [
  55. {
  56. id: 0,
  57. node_id: 0,
  58. name: _tr("Value"),
  59. type: "VALUE",
  60. color: 0xffa1a1a1,
  61. default_value: f32_array_create_x(0.5),
  62. min: 0.0,
  63. max: 10.0,
  64. precision: 100,
  65. display: 0
  66. }
  67. ],
  68. outputs: [
  69. {
  70. id: 0,
  71. node_id: 0,
  72. name: _tr("Value"),
  73. type: "VALUE",
  74. color: 0xffa1a1a1,
  75. default_value: f32_array_create_x(0.5),
  76. min: 0.0,
  77. max: 1.0,
  78. precision: 100,
  79. display: 0
  80. }
  81. ],
  82. buttons: [],
  83. width: 0
  84. };