map_range_node.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. function map_range_node_init() {
  2. array_push(nodes_material_utilities, map_range_node_def);
  3. map_set(parser_material_node_values, "MAPRANGE", map_range_node_value);
  4. }
  5. function map_range_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 fmin: string = parser_material_parse_value_input(node.inputs[1]);
  8. let fmax: string = parser_material_parse_value_input(node.inputs[2]);
  9. let tmin: string = parser_material_parse_value_input(node.inputs[3]);
  10. let tmax: string = parser_material_parse_value_input(node.inputs[4]);
  11. let use_clamp: bool = node.buttons[0].default_value[0] > 0;
  12. let a: string = "((" + tmin + " - " + tmax + ") / (" + fmin + " - " + fmax + "))";
  13. let out_val: string = "(" + a + " * " + val + " + " + tmin + " - " + a + " * " + fmin + ")";
  14. if (use_clamp) {
  15. return "(clamp(" + out_val + ", " + tmin + ", " + tmax + "))";
  16. }
  17. else {
  18. return out_val;
  19. }
  20. }
  21. let map_range_node_def: ui_node_t = {
  22. id : 0,
  23. name : _tr("Map Range"),
  24. type : "MAPRANGE",
  25. x : 0,
  26. y : 0,
  27. color : 0xff62676d,
  28. inputs : [
  29. {
  30. id : 0,
  31. node_id : 0,
  32. name : _tr("Value"),
  33. type : "VALUE",
  34. color : 0xffa1a1a1,
  35. default_value : f32_array_create_x(0.5),
  36. min : 0.0,
  37. max : 1.0,
  38. precision : 100,
  39. display : 0
  40. },
  41. {
  42. id : 0,
  43. node_id : 0,
  44. name : _tr("From Min"),
  45. type : "VALUE",
  46. color : 0xffa1a1a1,
  47. default_value : f32_array_create_x(0.0),
  48. min : 0.0,
  49. max : 1.0,
  50. precision : 100,
  51. display : 0
  52. },
  53. {
  54. id : 0,
  55. node_id : 0,
  56. name : _tr("From Max"),
  57. type : "VALUE",
  58. color : 0xffa1a1a1,
  59. default_value : f32_array_create_x(1.0),
  60. min : 0.0,
  61. max : 1.0,
  62. precision : 100,
  63. display : 0
  64. },
  65. {
  66. id : 0,
  67. node_id : 0,
  68. name : _tr("To Min"),
  69. type : "VALUE",
  70. color : 0xffa1a1a1,
  71. default_value : f32_array_create_x(0.0),
  72. min : 0.0,
  73. max : 1.0,
  74. precision : 100,
  75. display : 0
  76. },
  77. {
  78. id : 0,
  79. node_id : 0,
  80. name : _tr("To Max"),
  81. type : "VALUE",
  82. color : 0xffa1a1a1,
  83. default_value : f32_array_create_x(1.0),
  84. min : 0.0,
  85. max : 1.0,
  86. precision : 100,
  87. display : 0
  88. }
  89. ],
  90. outputs : [ {
  91. id : 0,
  92. node_id : 0,
  93. name : _tr("Value"),
  94. type : "VALUE",
  95. color : 0xffa1a1a1,
  96. default_value : f32_array_create_x(0.0),
  97. min : 0.0,
  98. max : 1.0,
  99. precision : 100,
  100. display : 0
  101. } ],
  102. buttons : [ {
  103. name : _tr("Clamp"),
  104. type : "BOOL",
  105. output : 0,
  106. default_value : f32_array_create_x(0),
  107. data : null,
  108. min : 0.0,
  109. max : 1.0,
  110. precision : 100,
  111. height : 0
  112. } ],
  113. width : 0,
  114. flags : 0
  115. };