clamp_node.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. function clamp_node_init() {
  2. array_push(nodes_material_utilities, clamp_node_def);
  3. map_set(parser_material_node_values, "CLAMP", clamp_node_value);
  4. }
  5. function clamp_node_value(node: ui_node_t, socket: ui_node_socket_t): string {
  6. let val: string = parser_material_parse_value_input(node.inputs[0]);
  7. let min: string = parser_material_parse_value_input(node.inputs[1]);
  8. let max: string = parser_material_parse_value_input(node.inputs[2]);
  9. let but: ui_node_button_t = node.buttons[0]; // operation;
  10. let op: string = to_upper_case(u8_array_string_at(but.data, but.default_value[0]));
  11. op = string_replace_all(op, " ", "_");
  12. if (op == "MIN_MAX") {
  13. return "(clamp(" + val + ", " + min + ", " + max + "))";
  14. }
  15. else { // RANGE
  16. return "(clamp(" + val + ", min(" + min + ", " + max + "), max(" + min + ", " + max + ")))";
  17. }
  18. }
  19. let clamp_node_def: ui_node_t = {
  20. id : 0,
  21. name : _tr("Clamp"),
  22. type : "CLAMP",
  23. x : 0,
  24. y : 0,
  25. color : 0xff62676d,
  26. inputs : [
  27. {
  28. id : 0,
  29. node_id : 0,
  30. name : _tr("Value"),
  31. type : "VALUE",
  32. color : 0xffa1a1a1,
  33. default_value : f32_array_create_x(0.5),
  34. min : 0.0,
  35. max : 1.0,
  36. precision : 100,
  37. display : 0
  38. },
  39. {
  40. id : 0,
  41. node_id : 0,
  42. name : _tr("Min"),
  43. type : "VALUE",
  44. color : 0xffa1a1a1,
  45. default_value : f32_array_create_x(0.0),
  46. min : 0.0,
  47. max : 1.0,
  48. precision : 100,
  49. display : 0
  50. },
  51. {
  52. id : 0,
  53. node_id : 0,
  54. name : _tr("Max"),
  55. type : "VALUE",
  56. color : 0xffa1a1a1,
  57. default_value : f32_array_create_x(1.0),
  58. min : 0.0,
  59. max : 1.0,
  60. precision : 100,
  61. display : 0
  62. }
  63. ],
  64. outputs : [ {
  65. id : 0,
  66. node_id : 0,
  67. name : _tr("Value"),
  68. type : "VALUE",
  69. color : 0xffa1a1a1,
  70. default_value : f32_array_create_x(0.0),
  71. min : 0.0,
  72. max : 1.0,
  73. precision : 100,
  74. display : 0
  75. } ],
  76. buttons : [ {
  77. name : _tr("operation"),
  78. type : "ENUM",
  79. output : 0,
  80. default_value : f32_array_create_x(0),
  81. data : u8_array_create_from_string(_tr("Min Max") + "\n" + _tr("Range")),
  82. min : 0.0,
  83. max : 1.0,
  84. precision : 100,
  85. height : 0
  86. } ],
  87. width : 0,
  88. flags : 0
  89. };