ui_nodes.ts 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534
  1. ///if (is_paint || is_sculpt)
  2. let ui_nodes_show: bool = false;
  3. ///end
  4. ///if is_lab
  5. let ui_nodes_show: bool = true;
  6. ///end
  7. let ui_nodes_wx: i32;
  8. let ui_nodes_wy: i32;
  9. let ui_nodes_ww: i32;
  10. let ui_nodes_wh: i32;
  11. let ui_nodes_ui: zui_t;
  12. let ui_nodes_canvas_type = canvas_type_t.MATERIAL;
  13. let ui_nodes_show_menu: bool = false;
  14. let ui_nodes_show_menu_first: bool = true;
  15. let ui_nodes_hide_menu: bool = false;
  16. let ui_nodes_menu_category: i32 = 0;
  17. let ui_nodes_popup_x: f32 = 0.0;
  18. let ui_nodes_popup_y: f32 = 0.0;
  19. let ui_nodes_uichanged_last: bool = false;
  20. let ui_nodes_recompile_mat: bool = false; // Mat preview
  21. let ui_nodes_recompile_mat_final: bool = false;
  22. let ui_nodes_node_search_spawn: zui_node_t = null;
  23. let ui_nodes_node_search_offset: i32 = 0;
  24. let ui_nodes_last_canvas: zui_node_canvas_t = null;
  25. let ui_nodes_last_node_selected_id: i32 = -1;
  26. let ui_nodes_release_link: bool = false;
  27. let ui_nodes_is_node_menu_op: bool = false;
  28. let ui_nodes_grid: image_t = null;
  29. let ui_nodes_hwnd: zui_handle_t = zui_handle_create();
  30. let ui_nodes_group_stack: node_group_t[] = [];
  31. let ui_nodes_controls_down: bool = false;
  32. function ui_nodes_init() {
  33. zui_set_on_link_drag(ui_nodes_on_link_drag);
  34. zui_set_on_socket_released(ui_nodes_on_socket_released);
  35. zui_set_on_canvas_released(ui_nodes_on_canvas_released);
  36. zui_set_on_canvas_control(ui_nodes_on_canvas_control);
  37. let scale: f32 = config_raw.window_scale;
  38. let ops: zui_options_t = {
  39. theme: base_theme,
  40. font: base_font,
  41. color_wheel: base_color_wheel,
  42. black_white_gradient: base_color_wheel_gradient,
  43. scale_factor: scale
  44. };
  45. ui_nodes_ui = zui_create(ops);
  46. ui_nodes_ui.scroll_enabled = false;
  47. }
  48. let _ui_nodes_on_link_drag_link_drag: zui_node_link_t;
  49. function ui_nodes_on_link_drag(link_drag_id: i32, is_new_link: bool) {
  50. if (is_new_link) {
  51. let nodes: zui_nodes_t = ui_nodes_get_nodes();
  52. let link_drag: zui_node_link_t = zui_get_link(ui_nodes_get_canvas(true).links, link_drag_id);
  53. let node: zui_node_t = zui_get_node(ui_nodes_get_canvas(true).nodes, link_drag.from_id > -1 ? link_drag.from_id : link_drag.to_id);
  54. let link_x: i32 = ui_nodes_ui._window_x + zui_nodes_NODE_X(node);
  55. let link_y: i32 = ui_nodes_ui._window_y + zui_nodes_NODE_Y(node);
  56. if (link_drag.from_id > -1) {
  57. link_x += zui_nodes_NODE_W(node);
  58. link_y += zui_nodes_OUTPUT_Y(node.outputs, link_drag.from_socket);
  59. }
  60. else {
  61. link_y += zui_nodes_INPUT_Y(ui_nodes_get_canvas(true), node.inputs, link_drag.to_socket) + zui_nodes_OUTPUTS_H(node.outputs) + zui_nodes_BUTTONS_H(node);
  62. }
  63. if (math_abs(mouse_x - link_x) > 5 || math_abs(mouse_y - link_y) > 5) { // Link length
  64. _ui_nodes_on_link_drag_link_drag = link_drag;
  65. ui_nodes_node_search(-1, -1, function () {
  66. let link_drag: zui_node_link_t = _ui_nodes_on_link_drag_link_drag;
  67. let n: zui_node_t = zui_get_node(ui_nodes_get_canvas(true).nodes, nodes.nodes_selected_id[0]);
  68. if (link_drag.to_id == -1 && n.inputs.length > 0) {
  69. link_drag.to_id = n.id;
  70. let from_type: string = node.outputs[link_drag.from_socket].type;
  71. // Connect to the first socket
  72. link_drag.to_socket = 0;
  73. // Try to find the first type-matching socket and use it if present
  74. for (let i: i32 = 0; i < n.inputs.length; ++i) {
  75. let socket: zui_node_socket_t = n.inputs[i];
  76. if (socket.type == from_type) {
  77. link_drag.to_socket = array_index_of(n.inputs, socket);
  78. break;
  79. }
  80. }
  81. array_push(ui_nodes_get_canvas(true).links, link_drag);
  82. }
  83. else if (link_drag.from_id == -1 && n.outputs.length > 0) {
  84. link_drag.from_id = n.id;
  85. link_drag.from_socket = 0;
  86. array_push(ui_nodes_get_canvas(true).links, link_drag);
  87. }
  88. ///if is_lab
  89. parser_logic_parse(ui_nodes_get_canvas(true));
  90. context_raw.rdirty = 5;
  91. ///end
  92. });
  93. }
  94. // Selecting which node socket to preview
  95. else if (node.id == nodes.nodes_selected_id[0]) {
  96. context_raw.node_preview_socket = link_drag.from_id > -1 ? link_drag.from_socket : 0;
  97. ///if (is_paint || is_sculpt)
  98. context_raw.node_preview_dirty = true;
  99. ///end
  100. }
  101. }
  102. }
  103. let _ui_nodes_on_socket_released_socket: zui_node_socket_t;
  104. let _ui_nodes_on_socket_released_node: zui_node_t;
  105. let _ui_nodes_htype: zui_handle_t = zui_handle_create();
  106. let _ui_nodes_hname: zui_handle_t = zui_handle_create();
  107. let _ui_nodes_hmin: zui_handle_t = zui_handle_create();
  108. let _ui_nodes_hmax: zui_handle_t = zui_handle_create();
  109. let _ui_nodes_hval0: zui_handle_t = zui_handle_create();
  110. let _ui_nodes_hval1: zui_handle_t = zui_handle_create();
  111. let _ui_nodes_hval2: zui_handle_t = zui_handle_create();
  112. let _ui_nodes_hval3: zui_handle_t = zui_handle_create();
  113. function ui_nodes_on_socket_released(socket_id: i32) {
  114. let nodes: zui_nodes_t = ui_nodes_get_nodes();
  115. let canvas: zui_node_canvas_t = ui_nodes_get_canvas(true);
  116. let socket: zui_node_socket_t = zui_get_socket(canvas.nodes, socket_id);
  117. let node: zui_node_t = zui_get_node(canvas.nodes, socket.node_id);
  118. if (ui_nodes_ui.input_released_r) {
  119. if (node.type == "GROUP_INPUT" || node.type == "GROUP_OUTPUT") {
  120. _ui_nodes_on_socket_released_socket = socket;
  121. _ui_nodes_on_socket_released_node = node;
  122. app_notify_on_next_frame(function () {
  123. ui_menu_draw(function (ui: zui_t) {
  124. let socket: zui_node_socket_t = _ui_nodes_on_socket_released_socket;
  125. let node: zui_node_t = _ui_nodes_on_socket_released_node;
  126. if (ui_menu_button(ui, tr("Edit"))) {
  127. _ui_nodes_htype.position = socket.type == "RGBA" ? 0 : socket.type == "VECTOR" ? 1 : 2;
  128. _ui_nodes_hname.text = socket.name;
  129. _ui_nodes_hmin.value = socket.min;
  130. _ui_nodes_hmax.value = socket.max;
  131. if (socket.type == "RGBA" || socket.type == "VECTOR") {
  132. _ui_nodes_hval0.value = socket.default_value[0];
  133. _ui_nodes_hval1.value = socket.default_value[1];
  134. _ui_nodes_hval2.value = socket.default_value[2];
  135. if (socket.type == "RGBA") {
  136. _ui_nodes_hval3.value = socket.default_value[3];
  137. }
  138. }
  139. else {
  140. _ui_nodes_hval0.value = socket.default_value[0];
  141. }
  142. app_notify_on_next_frame(function () {
  143. zui_end_input();
  144. ui_box_show_custom(function (ui: zui_t) {
  145. let socket: zui_node_socket_t = _ui_nodes_on_socket_released_socket;
  146. let node: zui_node_t = _ui_nodes_on_socket_released_node;
  147. if (zui_tab(zui_handle(__ID__), tr("Socket"))) {
  148. let type_combo: string[] = [tr("Color"), tr("Vector"), tr("Value")];
  149. let type: i32 = zui_combo(_ui_nodes_htype, type_combo, tr("Type"), true);
  150. if (_ui_nodes_htype.changed) {
  151. _ui_nodes_hname.text = type == 0 ? tr("Color") : type == 1 ? tr("Vector") : tr("Value");
  152. }
  153. let name: string = zui_text_input(_ui_nodes_hname, tr("Name"));
  154. let min: f32 = zui_float_input(_ui_nodes_hmin, tr("Min"));
  155. let max: f32 = zui_float_input(_ui_nodes_hmax, tr("Max"));
  156. let default_value: any = null;
  157. if (type == 0) {
  158. let row: f32[] = [1 / 4, 1 / 4, 1 / 4, 1 / 4];
  159. zui_row(row);
  160. zui_float_input(_ui_nodes_hval0, tr("R"));
  161. zui_float_input(_ui_nodes_hval1, tr("G"));
  162. zui_float_input(_ui_nodes_hval2, tr("B"));
  163. zui_float_input(_ui_nodes_hval3, tr("A"));
  164. default_value = f32_array_create_xyzw(_ui_nodes_hval0.value, _ui_nodes_hval1.value, _ui_nodes_hval2.value, _ui_nodes_hval3.value);
  165. }
  166. else if (type == 1) {
  167. let row: f32[] = [1 / 3, 1 / 3, 1 / 3];
  168. zui_row(row);
  169. _ui_nodes_hval0.value = zui_float_input(_ui_nodes_hval0, tr("X"));
  170. _ui_nodes_hval1.value = zui_float_input(_ui_nodes_hval1, tr("Y"));
  171. _ui_nodes_hval2.value = zui_float_input(_ui_nodes_hval2, tr("Z"));
  172. default_value = f32_array_create_xyz(_ui_nodes_hval0.value, _ui_nodes_hval1.value, _ui_nodes_hval2.value);
  173. }
  174. else {
  175. default_value = zui_float_input(_ui_nodes_hval0, tr("default_value"));
  176. }
  177. if (zui_button(tr("OK"))) { // || ui.isReturnDown
  178. socket.name = name;
  179. socket.type = type == 0 ? "RGBA" : type == 1 ? "VECTOR" : "VALUE";
  180. socket.color = nodes_material_get_socket_color(socket.type);
  181. socket.min = min;
  182. socket.max = max;
  183. socket.default_value = default_value;
  184. ui_box_hide();
  185. nodes_material_sync_sockets(node);
  186. ui_nodes_hwnd.redraws = 2;
  187. }
  188. }
  189. }, 400, 250);
  190. });
  191. }
  192. if (ui_menu_button(ui, tr("Delete"))) {
  193. let i: i32 = 0;
  194. // Remove links connected to the socket
  195. while (i < canvas.links.length) {
  196. let l: zui_node_link_t = canvas.links[i];
  197. if ((l.from_id == node.id && l.from_socket == array_index_of(node.outputs, socket)) ||
  198. (l.to_id == node.id && l.to_socket == array_index_of(node.inputs, socket))) {
  199. array_splice(canvas.links, i, 1);
  200. }
  201. else {
  202. i++;
  203. }
  204. }
  205. // Remove socket
  206. array_remove(node.inputs, socket);
  207. array_remove(node.outputs, socket);
  208. nodes_material_sync_sockets(node);
  209. }
  210. }, 2);
  211. });
  212. }
  213. else ui_nodes_on_canvas_released();
  214. }
  215. // Selecting which node socket to preview
  216. else if (node.id == nodes.nodes_selected_id[0]) {
  217. let i: i32 = array_index_of(node.outputs, socket);
  218. if (i > -1) {
  219. context_raw.node_preview_socket = i;
  220. ///if (is_paint || is_sculpt)
  221. context_raw.node_preview_dirty = true;
  222. ///end
  223. }
  224. }
  225. }
  226. let _ui_nodes_on_canvas_released_selected: zui_node_t;
  227. function ui_nodes_on_canvas_released() {
  228. if (ui_nodes_ui.input_released_r && math_abs(ui_nodes_ui.input_x - ui_nodes_ui.input_started_x) < 2 && math_abs(ui_nodes_ui.input_y - ui_nodes_ui.input_started_y) < 2) {
  229. // Node selection
  230. let nodes: zui_nodes_t = ui_nodes_get_nodes();
  231. let canvas: zui_node_canvas_t = ui_nodes_get_canvas(true);
  232. let selected: zui_node_t = null;
  233. for (let i: i32 = 0; i < canvas.nodes.length; ++i) {
  234. let node: zui_node_t = canvas.nodes[i];
  235. if (zui_get_input_in_rect(ui_nodes_ui._window_x + zui_nodes_NODE_X(node), ui_nodes_ui._window_y + zui_nodes_NODE_Y(node), zui_nodes_NODE_W(node), zui_nodes_NODE_H(canvas, node))) {
  236. selected = node;
  237. break;
  238. }
  239. }
  240. if (selected == null) {
  241. nodes.nodes_selected_id = [];
  242. }
  243. else if (array_index_of(nodes.nodes_selected_id, selected.id) == -1) {
  244. nodes.nodes_selected_id = [selected.id];
  245. }
  246. // Node context menu
  247. if (!zui_socket_released()) {
  248. let number_of_entries: i32 = 5;
  249. if (ui_nodes_canvas_type == canvas_type_t.MATERIAL) {
  250. ++number_of_entries;
  251. }
  252. if (selected != null && selected.type == "RGB") {
  253. ++number_of_entries;
  254. }
  255. _ui_nodes_on_canvas_released_selected = selected;
  256. ui_menu_draw(function (ui_menu: zui_t) {
  257. let selected: zui_node_t = _ui_nodes_on_canvas_released_selected;
  258. ui_menu._y += 1;
  259. let is_protected: bool = selected == null ||
  260. ///if (is_paint || is_sculpt)
  261. selected.type == "OUTPUT_MATERIAL_PBR" ||
  262. ///end
  263. selected.type == "GROUP_INPUT" ||
  264. selected.type == "GROUP_OUTPUT" ||
  265. selected.type == "brush_output_node";
  266. ui_menu.enabled = !is_protected;
  267. if (ui_menu_button(ui_menu, tr("Cut"), "ctrl+x")) {
  268. app_notify_on_next_frame(function () {
  269. ui_nodes_hwnd.redraws = 2;
  270. zui_set_is_copy(true);
  271. zui_set_is_cut(true);
  272. ui_nodes_is_node_menu_op = true;
  273. });
  274. }
  275. if (ui_menu_button(ui_menu, tr("Copy"), "ctrl+c")) {
  276. app_notify_on_next_frame(function () {
  277. zui_set_is_copy(true);
  278. ui_nodes_is_node_menu_op = true;
  279. });
  280. }
  281. ui_menu.enabled = zui_clipboard != "";
  282. if (ui_menu_button(ui_menu, tr("Paste"), "ctrl+v")) {
  283. app_notify_on_next_frame(function () {
  284. ui_nodes_hwnd.redraws = 2;
  285. zui_set_is_paste(true);
  286. ui_nodes_is_node_menu_op = true;
  287. });
  288. }
  289. ui_menu.enabled = !is_protected;
  290. if (ui_menu_button(ui_menu, tr("Delete"), "delete")) {
  291. app_notify_on_next_frame(function () {
  292. ui_nodes_hwnd.redraws = 2;
  293. ui_nodes_ui.is_delete_down = true;
  294. ui_nodes_is_node_menu_op = true;
  295. });
  296. }
  297. if (ui_menu_button(ui_menu, tr("Duplicate"))) {
  298. app_notify_on_next_frame(function () {
  299. ui_nodes_hwnd.redraws = 2;
  300. zui_set_is_copy(true);
  301. zui_set_is_paste(true);
  302. ui_nodes_is_node_menu_op = true;
  303. });
  304. }
  305. if (selected != null && selected.type == "RGB") {
  306. if (ui_menu_button(ui_menu, tr("Add Swatch"))) {
  307. let color: any = selected.outputs[0].default_value;
  308. let new_swatch: swatch_color_t = make_swatch(color_from_floats(color[0], color[1], color[2], color[3]));
  309. context_set_swatch(new_swatch);
  310. array_push(project_raw.swatches, new_swatch);
  311. ui_base_hwnds[tab_area_t.STATUS].redraws = 1;
  312. }
  313. }
  314. if (ui_nodes_canvas_type == canvas_type_t.MATERIAL) {
  315. ui_menu_separator(ui_menu);
  316. if (ui_menu_button(ui_menu, tr("2D View"))) {
  317. ui_base_show_2d_view(view_2d_type_t.NODE);
  318. }
  319. }
  320. ui_menu.enabled = true;
  321. }, number_of_entries);
  322. }
  323. }
  324. if (ui_nodes_ui.input_released) {
  325. let nodes: zui_nodes_t = ui_nodes_get_nodes();
  326. let canvas: zui_node_canvas_t = ui_nodes_get_canvas(true);
  327. for (let i: i32 = 0; i < canvas.nodes.length; ++i) {
  328. let node: zui_node_t = canvas.nodes[i];
  329. if (zui_get_input_in_rect(ui_nodes_ui._window_x + zui_nodes_NODE_X(node), ui_nodes_ui._window_y + zui_nodes_NODE_Y(node), zui_nodes_NODE_W(node), zui_nodes_NODE_H(canvas, node))) {
  330. if (node.id == nodes.nodes_selected_id[0]) {
  331. ui_view2d_hwnd.redraws = 2;
  332. if (time_time() - context_raw.select_time < 0.25) ui_base_show_2d_view(view_2d_type_t.NODE);
  333. context_raw.select_time = time_time();
  334. }
  335. break;
  336. }
  337. }
  338. }
  339. }
  340. function ui_nodes_on_canvas_control(): zui_canvas_control_t {
  341. let control: zui_canvas_control_t = ui_nodes_get_canvas_control(ui_nodes_ui, ui_nodes_controls_down);
  342. ui_nodes_controls_down = control.controls_down;
  343. return control;
  344. }
  345. function ui_nodes_get_canvas_control(ui: zui_t, controls_down: bool): zui_canvas_control_t {
  346. if (config_raw.wrap_mouse && controls_down) {
  347. if (ui.input_x < ui._window_x) {
  348. ui.input_x = ui._window_x + ui._window_w;
  349. krom_set_mouse_position(math_floor(ui.input_x), math_floor(ui.input_y));
  350. }
  351. else if (ui.input_x > ui._window_x + ui._window_w) {
  352. ui.input_x = ui._window_x;
  353. krom_set_mouse_position(math_floor(ui.input_x), math_floor(ui.input_y));
  354. }
  355. else if (ui.input_y < ui._window_y) {
  356. ui.input_y = ui._window_y + ui._window_h;
  357. krom_set_mouse_position(math_floor(ui.input_x), math_floor(ui.input_y));
  358. }
  359. else if (ui.input_y > ui._window_y + ui._window_h) {
  360. ui.input_y = ui._window_y;
  361. krom_set_mouse_position(math_floor(ui.input_x), math_floor(ui.input_y));
  362. }
  363. }
  364. if (operator_shortcut(map_get(config_keymap, "action_pan"), shortcut_type_t.STARTED) ||
  365. operator_shortcut(map_get(config_keymap, "action_zoom"), shortcut_type_t.STARTED) ||
  366. ui.input_started_r ||
  367. ui.input_wheel_delta != 0.0) {
  368. controls_down = true;
  369. }
  370. else if (!operator_shortcut(map_get(config_keymap, "action_pan"), shortcut_type_t.DOWN) &&
  371. !operator_shortcut(map_get(config_keymap, "action_zoom"), shortcut_type_t.DOWN) &&
  372. !ui.input_down_r &&
  373. ui.input_wheel_delta == 0.0) {
  374. controls_down = false;
  375. }
  376. if (!controls_down) {
  377. return {
  378. pan_x: 0,
  379. pan_y: 0,
  380. zoom: 0,
  381. controls_down: controls_down
  382. }
  383. }
  384. let pan: bool = ui.input_down_r || operator_shortcut(map_get(config_keymap, "action_pan"), shortcut_type_t.DOWN);
  385. let zoom_delta: f32 = operator_shortcut(map_get(config_keymap, "action_zoom"), shortcut_type_t.DOWN) ? ui_nodes_get_zoom_delta(ui) / 100.0 : 0.0;
  386. let control: zui_canvas_control_t = {
  387. pan_x: pan ? ui.input_dx : 0.0,
  388. pan_y: pan ? ui.input_dy : 0.0,
  389. zoom: ui.input_wheel_delta != 0.0 ? -ui.input_wheel_delta / 10 : zoom_delta,
  390. controls_down: controls_down
  391. };
  392. if (base_is_combo_selected()) {
  393. control.zoom = 0.0;
  394. }
  395. return control;
  396. }
  397. function ui_nodes_get_zoom_delta(ui: zui_t): f32 {
  398. return config_raw.zoom_direction == zoom_direction_t.VERTICAL ? -ui.input_dy :
  399. config_raw.zoom_direction == zoom_direction_t.VERTICAL_INVERTED ? -ui.input_dy :
  400. config_raw.zoom_direction == zoom_direction_t.HORIZONTAL ? ui.input_dx :
  401. config_raw.zoom_direction == zoom_direction_t.HORIZONTAL_INVERTED ? ui.input_dx :
  402. -(ui.input_dy - ui.input_dx);
  403. }
  404. function ui_nodes_get_canvas(groups: bool = false): zui_node_canvas_t {
  405. ///if (is_paint || is_sculpt)
  406. if (ui_nodes_canvas_type == canvas_type_t.MATERIAL) {
  407. if (groups && ui_nodes_group_stack.length > 0) {
  408. return ui_nodes_group_stack[ui_nodes_group_stack.length - 1].canvas;
  409. }
  410. else {
  411. return ui_nodes_get_canvas_material();
  412. }
  413. }
  414. else {
  415. return context_raw.brush.canvas;
  416. }
  417. ///end
  418. ///if is_lab
  419. return project_canvas;
  420. ///end
  421. }
  422. ///if (is_paint || is_sculpt)
  423. function ui_nodes_get_canvas_material(): zui_node_canvas_t {
  424. return context_raw.material.canvas;
  425. }
  426. ///end
  427. function ui_nodes_get_nodes(): zui_nodes_t {
  428. ///if (is_paint || is_sculpt)
  429. if (ui_nodes_canvas_type == canvas_type_t.MATERIAL) {
  430. if (ui_nodes_group_stack.length > 0) {
  431. return ui_nodes_group_stack[ui_nodes_group_stack.length - 1].nodes;
  432. }
  433. else {
  434. return context_raw.material.nodes;
  435. }
  436. }
  437. else {
  438. return context_raw.brush.nodes;
  439. }
  440. ///end
  441. ///if is_lab
  442. if (ui_nodes_group_stack.length > 0) {
  443. return ui_nodes_group_stack[ui_nodes_group_stack.length - 1].nodes;
  444. }
  445. else {
  446. return project_nodes;
  447. }
  448. ///end
  449. }
  450. function ui_nodes_update() {
  451. if (!ui_nodes_show || !base_ui_enabled) {
  452. return;
  453. }
  454. ///if (is_paint || is_sculpt)
  455. ui_nodes_wx = math_floor(app_w()) + ui_toolbar_w;
  456. ///end
  457. ///if is_lab
  458. ui_nodes_wx = math_floor(app_w());
  459. ///end
  460. ui_nodes_wy = ui_header_h * 2;
  461. if (ui_view2d_show) {
  462. ui_nodes_wy += app_h() - config_raw.layout[layout_size_t.NODES_H];
  463. }
  464. let ww: i32 = config_raw.layout[layout_size_t.NODES_W];
  465. if (!ui_base_show) {
  466. ///if (is_paint || is_sculpt)
  467. ww += config_raw.layout[layout_size_t.SIDEBAR_W] + ui_toolbar_w;
  468. ui_nodes_wx -= ui_toolbar_w;
  469. ///end
  470. ui_nodes_wy = 0;
  471. }
  472. let mx: i32 = mouse_x;
  473. let my: i32 = mouse_y;
  474. if (mx < ui_nodes_wx || mx > ui_nodes_wx + ww || my < ui_nodes_wy) {
  475. return;
  476. }
  477. if (ui_nodes_ui.is_typing || !ui_nodes_ui.input_enabled) {
  478. return;
  479. }
  480. let nodes: zui_nodes_t = ui_nodes_get_nodes();
  481. if (nodes.nodes_selected_id.length > 0 && ui_nodes_ui.is_key_pressed) {
  482. if (ui_nodes_ui.key == key_code_t.LEFT) {
  483. for (let i: i32 = 0; i < nodes.nodes_selected_id.length; ++i) {
  484. let n: i32 = nodes.nodes_selected_id[i];
  485. zui_get_node(ui_nodes_get_canvas(true).nodes, n).x -= 1;
  486. }
  487. }
  488. else if (ui_nodes_ui.key == key_code_t.RIGHT) {
  489. for (let i: i32 = 0; i < nodes.nodes_selected_id.length; ++i) {
  490. let n: i32 = nodes.nodes_selected_id[i];
  491. zui_get_node(ui_nodes_get_canvas(true).nodes, n).x += 1;
  492. }
  493. }
  494. if (ui_nodes_ui.key == key_code_t.UP) {
  495. for (let i: i32 = 0; i < nodes.nodes_selected_id.length; ++i) {
  496. let n: i32 = nodes.nodes_selected_id[i];
  497. zui_get_node(ui_nodes_get_canvas(true).nodes, n).y -= 1;
  498. }
  499. }
  500. else if (ui_nodes_ui.key == key_code_t.DOWN) {
  501. for (let i: i32 = 0; i < nodes.nodes_selected_id.length; ++i) {
  502. let n: i32 = nodes.nodes_selected_id[i];
  503. zui_get_node(ui_nodes_get_canvas(true).nodes, n).y += 1;
  504. }
  505. }
  506. }
  507. // Node search popup
  508. if (operator_shortcut(map_get(config_keymap, "node_search"))) ui_nodes_node_search();
  509. if (ui_nodes_node_search_spawn != null) {
  510. ui_nodes_ui.input_x = mouse_x; // Fix inputDX after popup removal
  511. ui_nodes_ui.input_y = mouse_y;
  512. ui_nodes_node_search_spawn = null;
  513. }
  514. if (operator_shortcut(map_get(config_keymap, "view_reset"))) {
  515. nodes.pan_x = 0.0;
  516. nodes.pan_y = 0.0;
  517. nodes.zoom = 1.0;
  518. }
  519. }
  520. function ui_nodes_canvas_changed() {
  521. ui_nodes_recompile_mat = true;
  522. ui_nodes_recompile_mat_final = true;
  523. }
  524. let _ui_nodes_node_search_first: bool;
  525. let _ui_nodes_node_search_done: ()=>void;
  526. function ui_nodes_node_search(x: i32 = -1, y: i32 = -1, done: ()=>void = null) {
  527. _ui_nodes_node_search_first = true;
  528. _ui_nodes_node_search_done = done;
  529. ui_menu_draw(function (ui: zui_t) {
  530. let search_handle: zui_handle_t = zui_handle(__ID__);
  531. g2_set_color(ui.ops.theme.SEPARATOR_COL);
  532. zui_draw_rect(true, ui._x, ui._y, ui._w, zui_ELEMENT_H(ui) * 8);
  533. g2_set_color(0xffffffff);
  534. let search: string = to_lower_case(zui_text_input(search_handle, "", zui_align_t.LEFT, true, true));
  535. ui.changed = false;
  536. if (_ui_nodes_node_search_first) {
  537. _ui_nodes_node_search_first = false;
  538. search_handle.text = "";
  539. zui_start_text_edit(search_handle); // Focus search bar
  540. }
  541. if (search_handle.changed) {
  542. ui_nodes_node_search_offset = 0;
  543. }
  544. if (ui.is_key_pressed) { // Move selection
  545. if (ui.key == key_code_t.DOWN && ui_nodes_node_search_offset < 6) {
  546. ui_nodes_node_search_offset++;
  547. }
  548. if (ui.key == key_code_t.UP && ui_nodes_node_search_offset > 0) {
  549. ui_nodes_node_search_offset--;
  550. }
  551. }
  552. let enter: bool = keyboard_down("enter");
  553. let count: i32 = 0;
  554. let BUTTON_COL: i32 = ui.ops.theme.BUTTON_COL;
  555. ///if (is_paint || is_sculpt)
  556. let node_list: zui_node_t[][] = ui_nodes_canvas_type == canvas_type_t.MATERIAL ? nodes_material_list : nodes_brush_list;
  557. ///end
  558. ///if is_lab
  559. let node_list: zui_node_t[][] = nodes_brush_list;
  560. ///end
  561. for (let i: i32 = 0; i < node_list.length; ++i) {
  562. let list: zui_node_t[] = node_list[i];
  563. for (let i: i32 = 0; i < list.length; ++i) {
  564. let n: zui_node_t = list[i];
  565. if (string_index_of(to_lower_case(tr(n.name)), search) >= 0) {
  566. ui.ops.theme.BUTTON_COL = count == ui_nodes_node_search_offset ? ui.ops.theme.HIGHLIGHT_COL : ui.ops.theme.SEPARATOR_COL;
  567. if (zui_button(tr(n.name), zui_align_t.LEFT) || (enter && count == ui_nodes_node_search_offset)) {
  568. ui_nodes_push_undo();
  569. let nodes: zui_nodes_t = ui_nodes_get_nodes();
  570. let canvas: zui_node_canvas_t = ui_nodes_get_canvas(true);
  571. ui_nodes_node_search_spawn = ui_nodes_make_node(n, nodes, canvas); // Spawn selected node
  572. array_push(canvas.nodes, ui_nodes_node_search_spawn);
  573. nodes.nodes_selected_id = [ui_nodes_node_search_spawn.id];
  574. nodes.nodes_drag = true;
  575. ///if is_lab
  576. parser_logic_parse(canvas);
  577. ///end
  578. ui_nodes_hwnd.redraws = 2;
  579. if (enter) {
  580. ui.changed = true;
  581. count = 6; // Trigger break
  582. }
  583. if (_ui_nodes_node_search_done != null) {
  584. _ui_nodes_node_search_done();
  585. }
  586. }
  587. if (++count > 6) {
  588. break;
  589. }
  590. }
  591. }
  592. if (count > 6) {
  593. break;
  594. }
  595. }
  596. if (enter && count == 0) { // Hide popup on enter when node is not found
  597. ui.changed = true;
  598. search_handle.text = "";
  599. }
  600. ui.ops.theme.BUTTON_COL = BUTTON_COL;
  601. }, 8, x, y);
  602. }
  603. function ui_nodes_get_node_x(): i32 {
  604. return math_floor((mouse_x - ui_nodes_wx - zui_nodes_PAN_X()) / zui_nodes_SCALE());
  605. }
  606. function ui_nodes_get_node_y(): i32 {
  607. return math_floor((mouse_y - ui_nodes_wy - zui_nodes_PAN_Y()) / zui_nodes_SCALE());
  608. }
  609. function ui_nodes_draw_grid() {
  610. let ww: i32 = config_raw.layout[layout_size_t.NODES_W];
  611. ///if (is_paint || is_sculpt)
  612. if (!ui_base_show) {
  613. ww += config_raw.layout[layout_size_t.SIDEBAR_W] + ui_toolbar_w;
  614. }
  615. ///end
  616. let wh: i32 = app_h();
  617. let step: f32 = 100 * zui_SCALE(ui_nodes_ui);
  618. let w: i32 = math_floor(ww + step * 3);
  619. let h: i32 = math_floor(wh + step * 3);
  620. if (w < 1) {
  621. w = 1;
  622. }
  623. if (h < 1) {
  624. h = 1;
  625. }
  626. ui_nodes_grid = image_create_render_target(w, h);
  627. g2_begin(ui_nodes_grid);
  628. g2_clear(ui_nodes_ui.ops.theme.SEPARATOR_COL);
  629. g2_set_color(ui_nodes_ui.ops.theme.SEPARATOR_COL - 0x00050505);
  630. step = 20 * zui_SCALE(ui_nodes_ui);
  631. for (let i: i32 = 0; i < math_floor(h / step) + 1; ++i) {
  632. g2_draw_line(0, i * step, w, i * step);
  633. }
  634. for (let i: i32 = 0; i < math_floor(w / step) + 1; ++i) {
  635. g2_draw_line(i * step, 0, i * step, h);
  636. }
  637. g2_set_color(ui_nodes_ui.ops.theme.SEPARATOR_COL - 0x00090909);
  638. step = 100 * zui_SCALE(ui_nodes_ui);
  639. for (let i: i32 = 0; i < math_floor(h / step) + 1; ++i) {
  640. g2_draw_line(0, i * step, w, i * step);
  641. }
  642. for (let i: i32 = 0; i < math_floor(w / step) + 1; ++i) {
  643. g2_draw_line(i * step, 0, i * step, h);
  644. }
  645. g2_end();
  646. }
  647. let _ui_nodes_render_tmp: (col: i32)=>void;
  648. function ui_nodes_render() {
  649. if (ui_nodes_recompile_mat) {
  650. ///if (is_paint || is_sculpt)
  651. if (ui_nodes_canvas_type == canvas_type_t.BRUSH) {
  652. make_material_parse_brush();
  653. util_render_make_brush_preview();
  654. ui_base_hwnds[tab_area_t.SIDEBAR1].redraws = 2;
  655. }
  656. else {
  657. base_is_fill_material() ? base_update_fill_layers() : util_render_make_material_preview();
  658. if (ui_view2d_show && ui_view2d_type == view_2d_type_t.NODE) {
  659. ui_view2d_hwnd.redraws = 2;
  660. }
  661. }
  662. ui_base_hwnds[tab_area_t.SIDEBAR1].redraws = 2;
  663. if (context_raw.split_view) {
  664. context_raw.ddirty = 2;
  665. }
  666. ///end
  667. ///if is_lab
  668. parser_logic_parse(project_canvas);
  669. ///end
  670. ui_nodes_recompile_mat = false;
  671. }
  672. else if (ui_nodes_recompile_mat_final) {
  673. ///if (is_paint || is_sculpt)
  674. make_material_parse_paint_material();
  675. if (ui_nodes_canvas_type == canvas_type_t.MATERIAL && base_is_fill_material()) {
  676. base_update_fill_layers();
  677. util_render_make_material_preview();
  678. }
  679. let decal: bool = context_raw.tool == workspace_tool_t.DECAL || context_raw.tool == workspace_tool_t.TEXT;
  680. if (decal) {
  681. util_render_make_decal_preview();
  682. }
  683. ui_base_hwnds[tab_area_t.SIDEBAR0].redraws = 2;
  684. context_raw.node_preview_dirty = true;
  685. ///end
  686. ui_nodes_recompile_mat_final = false;
  687. }
  688. let nodes: zui_nodes_t = ui_nodes_get_nodes();
  689. if (nodes.nodes_selected_id.length > 0 && nodes.nodes_selected_id[0] != ui_nodes_last_node_selected_id) {
  690. ui_nodes_last_node_selected_id = nodes.nodes_selected_id[0];
  691. ///if (is_paint || is_sculpt)
  692. context_raw.node_preview_dirty = true;
  693. ///end
  694. ///if is_lab
  695. context_raw.ddirty = 2; // Show selected node texture in viewport
  696. ui_header_handle.redraws = 2;
  697. ///end
  698. context_raw.node_preview_socket = 0;
  699. }
  700. // Remove dragged link when mouse is released out of the node viewport
  701. let c: zui_node_canvas_t = ui_nodes_get_canvas(true);
  702. if (ui_nodes_release_link && nodes.link_drag_id != -1) {
  703. array_remove(c.links, zui_get_link(c.links, nodes.link_drag_id));
  704. nodes.link_drag_id = -1;
  705. }
  706. ui_nodes_release_link = ui_nodes_ui.input_released;
  707. if (!ui_nodes_show || sys_width() == 0 || sys_height() == 0) {
  708. return;
  709. }
  710. ui_nodes_ui.input_enabled = base_ui_enabled;
  711. g2_end();
  712. if (ui_nodes_grid == null) {
  713. ui_nodes_draw_grid();
  714. }
  715. ///if (is_paint || is_sculpt)
  716. if (config_raw.node_preview && context_raw.node_preview_dirty) {
  717. ui_nodes_make_node_preview();
  718. }
  719. ///end
  720. // Start with UI
  721. zui_begin(ui_nodes_ui);
  722. // Make window
  723. ui_nodes_ww = config_raw.layout[layout_size_t.NODES_W];
  724. ///if (is_paint || is_sculpt)
  725. ui_nodes_wx = math_floor(app_w()) + ui_toolbar_w;
  726. ///end
  727. ///if is_lab
  728. ui_nodes_wx = math_floor(app_w());
  729. ///end
  730. ui_nodes_wy = 0;
  731. ///if (is_paint || is_sculpt)
  732. if (!ui_base_show) {
  733. ui_nodes_ww += config_raw.layout[layout_size_t.SIDEBAR_W] + ui_toolbar_w;
  734. ui_nodes_wx -= ui_toolbar_w;
  735. }
  736. ///end
  737. let ew: i32 = math_floor(zui_ELEMENT_W(ui_nodes_ui) * 0.7);
  738. ui_nodes_wh = app_h() + ui_header_h;
  739. if (config_raw.layout[layout_size_t.HEADER] == 1) {
  740. ui_nodes_wh += ui_header_h;
  741. }
  742. if (ui_view2d_show) {
  743. ui_nodes_wh = config_raw.layout[layout_size_t.NODES_H];
  744. ui_nodes_wy = app_h() - config_raw.layout[layout_size_t.NODES_H] + ui_header_h;
  745. if (config_raw.layout[layout_size_t.HEADER] == 1) {
  746. ui_nodes_wy += ui_header_h;
  747. }
  748. if (!ui_base_show) {
  749. ui_nodes_wy -= ui_header_h * 2;
  750. }
  751. }
  752. if (zui_window(ui_nodes_hwnd, ui_nodes_wx, ui_nodes_wy, ui_nodes_ww, ui_nodes_wh)) {
  753. zui_tab(zui_handle(__ID__), tr("Nodes"));
  754. // Grid
  755. g2_set_color(0xffffffff);
  756. let step: f32 = 100 * zui_SCALE(ui_nodes_ui);
  757. g2_draw_image(ui_nodes_grid, (nodes.pan_x * zui_nodes_SCALE()) % step - step, (nodes.pan_y * zui_nodes_SCALE()) % step - step);
  758. // Undo
  759. if (ui_nodes_ui.input_started || ui_nodes_ui.is_key_pressed) {
  760. ui_nodes_last_canvas = json_parse(json_stringify(ui_nodes_get_canvas(true)));
  761. }
  762. // Nodes
  763. let _input_enabled: bool = ui_nodes_ui.input_enabled;
  764. ui_nodes_ui.input_enabled = _input_enabled && !ui_nodes_show_menu;
  765. ///if (is_paint || is_sculpt)
  766. ui_nodes_ui.window_border_right = config_raw.layout[layout_size_t.SIDEBAR_W];
  767. ///end
  768. ui_nodes_ui.window_border_top = ui_header_h * 2;
  769. ui_nodes_ui.window_border_bottom = config_raw.layout[layout_size_t.STATUS_H];
  770. zui_node_canvas(nodes, ui_nodes_ui, c);
  771. ui_nodes_ui.input_enabled = _input_enabled;
  772. if (nodes.color_picker_callback != null) {
  773. context_raw.color_picker_previous_tool = context_raw.tool;
  774. context_select_tool(workspace_tool_t.PICKER);
  775. _ui_nodes_render_tmp = nodes.color_picker_callback;
  776. context_raw.color_picker_callback = function (color: swatch_color_t) {
  777. _ui_nodes_render_tmp(color.base);
  778. ui_nodes_hwnd.redraws = 2;
  779. ///if (is_paint || is_sculpt)
  780. let material_live: bool = config_raw.material_live;
  781. ///end
  782. ///if is_lab
  783. let material_live: bool = true;
  784. ///end
  785. if (material_live) {
  786. ui_nodes_canvas_changed();
  787. }
  788. };
  789. nodes.color_picker_callback = null;
  790. }
  791. // Remove nodes with unknown id for this canvas type
  792. if (zui_is_paste()) {
  793. ///if (is_paint || is_sculpt)
  794. let node_list: zui_node_t[][] = ui_nodes_canvas_type == canvas_type_t.MATERIAL ? nodes_material_list : nodes_brush_list;
  795. ///end
  796. ///if is_lab
  797. let node_list: zui_node_t[][] = nodes_brush_list;
  798. ///end
  799. let i: i32 = 0;
  800. while (i++ < c.nodes.length) {
  801. let canvas_node: zui_node_t = c.nodes[i - 1];
  802. if (array_index_of(zui_exclude_remove, canvas_node.type) >= 0) {
  803. continue;
  804. }
  805. let found: bool = false;
  806. for (let i: i32 = 0; i < node_list.length; ++i) {
  807. let list: zui_node_t[] = node_list[i];
  808. for (let i: i32 = 0; i < list.length; ++i) {
  809. let list_node: zui_node_t = list[i];
  810. if (canvas_node.type == list_node.type) {
  811. found = true;
  812. break;
  813. }
  814. }
  815. if (found) {
  816. break;
  817. }
  818. }
  819. if (canvas_node.type == "GROUP" && !ui_nodes_can_place_group(canvas_node.name)) {
  820. found = false;
  821. }
  822. if (!found) {
  823. zui_remove_node(canvas_node, c);
  824. array_remove(nodes.nodes_selected_id, canvas_node.id);
  825. i--;
  826. }
  827. }
  828. }
  829. if (ui_nodes_is_node_menu_op) {
  830. zui_set_is_copy(false);
  831. zui_set_is_cut(false);
  832. zui_set_is_paste(false);
  833. ui_nodes_ui.is_delete_down = false;
  834. }
  835. // Recompile material on change
  836. if (ui_nodes_ui.changed) {
  837. ///if (is_paint || is_sculpt)
  838. ui_nodes_recompile_mat = (ui_nodes_ui.input_dx != 0 || ui_nodes_ui.input_dy != 0 || !ui_nodes_uichanged_last) && config_raw.material_live; // Instant preview
  839. ///end
  840. ///if is_lab
  841. ui_nodes_recompile_mat = (ui_nodes_ui.input_dx != 0 || ui_nodes_ui.input_dy != 0 || !ui_nodes_uichanged_last); // Instant preview
  842. ///end
  843. }
  844. else if (ui_nodes_uichanged_last) {
  845. ui_nodes_canvas_changed();
  846. ui_nodes_push_undo(ui_nodes_last_canvas);
  847. }
  848. ui_nodes_uichanged_last = ui_nodes_ui.changed;
  849. // Node previews
  850. if (config_raw.node_preview && nodes.nodes_selected_id.length > 0) {
  851. let img: image_t = null;
  852. let sel: zui_node_t = zui_get_node(c.nodes, nodes.nodes_selected_id[0]);
  853. ///if (is_paint || is_sculpt)
  854. let single_channel: bool = sel.type == "LAYER_MASK";
  855. if (sel.type == "LAYER" || sel.type == "LAYER_MASK") {
  856. let id: any = sel.buttons[0].default_value;
  857. if (id < project_layers.length) {
  858. ///if is_paint
  859. img = project_layers[id].texpaint_preview;
  860. ///end
  861. }
  862. }
  863. else if (sel.type == "MATERIAL") {
  864. let id: any = sel.buttons[0].default_value;
  865. if (id < project_materials.length) {
  866. img = project_materials[id].image;
  867. }
  868. }
  869. else if (sel.type == "OUTPUT_MATERIAL_PBR") {
  870. img = context_raw.material.image;
  871. }
  872. else if (sel.type == "brush_output_node") {
  873. img = context_raw.brush.image;
  874. }
  875. else if (ui_nodes_canvas_type == canvas_type_t.MATERIAL) {
  876. img = context_raw.node_preview;
  877. }
  878. ///else
  879. let brush_node: logic_node_t = parser_logic_get_logic_node(sel);
  880. if (brush_node != null) {
  881. img = logic_node_get_cached_image(brush_node);
  882. }
  883. ///end
  884. if (img != null) {
  885. let tw: f32 = 128 * zui_SCALE(ui_nodes_ui);
  886. let th: f32 = tw * (img.height / img.width);
  887. let tx: f32 = ui_nodes_ww - tw - 8 * zui_SCALE(ui_nodes_ui);
  888. let ty: f32 = ui_nodes_wh - th - 8 * zui_SCALE(ui_nodes_ui);
  889. ///if krom_opengl
  890. let invert_y: bool = sel.type == "MATERIAL";
  891. ///else
  892. let invert_y: bool = false;
  893. ///end
  894. ///if (is_paint || is_sculpt)
  895. if (single_channel) {
  896. g2_set_pipeline(ui_view2d_pipe);
  897. ///if krom_opengl
  898. krom_g4_set_pipeline(ui_view2d_pipe.pipeline_);
  899. ///end
  900. krom_g4_set_int(ui_view2d_channel_loc, 1);
  901. }
  902. ///end
  903. g2_set_color(0xffffffff);
  904. invert_y ?
  905. g2_draw_scaled_image(img, tx, ty + th, tw, -th) :
  906. g2_draw_scaled_image(img, tx, ty, tw, th);
  907. ///if (is_paint || is_sculpt)
  908. if (single_channel) {
  909. g2_set_pipeline(null);
  910. }
  911. ///end
  912. }
  913. }
  914. // Menu
  915. g2_set_color(ui_nodes_ui.ops.theme.SEPARATOR_COL);
  916. g2_fill_rect(0, zui_ELEMENT_H(ui_nodes_ui), ui_nodes_ww, zui_ELEMENT_H(ui_nodes_ui) + zui_ELEMENT_OFFSET(ui_nodes_ui) * 2);
  917. g2_set_color(0xffffffff);
  918. let start_y: i32 = zui_ELEMENT_H(ui_nodes_ui) + zui_ELEMENT_OFFSET(ui_nodes_ui);
  919. ui_nodes_ui._x = 0;
  920. ui_nodes_ui._y = 2 + start_y;
  921. ui_nodes_ui._w = ew;
  922. ///if (is_paint || is_sculpt)
  923. // Editable canvas name
  924. let h: zui_handle_t = zui_handle(__ID__);
  925. h.text = c.name;
  926. ui_nodes_ui._w = math_floor(math_min(g2_font_width(ui_nodes_ui.ops.font, ui_nodes_ui.font_size, h.text) + 15 * zui_SCALE(ui_nodes_ui), 100 * zui_SCALE(ui_nodes_ui)));
  927. let new_name: string = zui_text_input(h, "");
  928. ui_nodes_ui._x += ui_nodes_ui._w + 3;
  929. ui_nodes_ui._y = 2 + start_y;
  930. ui_nodes_ui._w = ew;
  931. if (h.changed) { // Check whether renaming is possible and update group links
  932. if (ui_nodes_group_stack.length > 0) {
  933. let can_rename: bool = true;
  934. for (let i: i32 = 0; i < project_material_groups.length; ++i) {
  935. let m: node_group_t = project_material_groups[i];
  936. if (m.canvas.name == new_name) {
  937. can_rename = false; // Name already used
  938. }
  939. }
  940. if (can_rename) {
  941. let old_name: string = c.name;
  942. c.name = new_name;
  943. let canvases: zui_node_canvas_t[] = [];
  944. for (let i: i32 = 0; i < project_materials.length; ++i) {
  945. let m: slot_material_t = project_materials[i];
  946. array_push(canvases, m.canvas);
  947. }
  948. for (let i: i32 = 0; i < project_material_groups.length; ++i) {
  949. let m: node_group_t = project_material_groups[i];
  950. array_push(canvases, m.canvas);
  951. }
  952. for (let i: i32 = 0; i < canvases.length; ++i) {
  953. let canvas: zui_node_canvas_t = canvases[i];
  954. for (let i: i32 = 0; i < canvas.nodes.length; ++i) {
  955. let n: zui_node_t = canvas.nodes[i];
  956. if (n.type == "GROUP" && n.name == old_name) {
  957. n.name = c.name;
  958. }
  959. }
  960. }
  961. }
  962. }
  963. else {
  964. c.name = new_name;
  965. }
  966. }
  967. ///end
  968. ///if is_lab
  969. ui_nodes_ui.window_border_top = 0;
  970. ui_nodes_ext_draw_buttons(ew, start_y);
  971. ///end
  972. let _BUTTON_COL: i32 = ui_nodes_ui.ops.theme.BUTTON_COL;
  973. ui_nodes_ui.ops.theme.BUTTON_COL = ui_nodes_ui.ops.theme.SEPARATOR_COL;
  974. ///if (is_paint || is_sculpt)
  975. let cats: string[] = ui_nodes_canvas_type == canvas_type_t.MATERIAL ? nodes_material_categories : nodes_brush_categories;
  976. ///end
  977. ///if is_lab
  978. let cats: string[] = nodes_brush_categories;
  979. ///end
  980. for (let i: i32 = 0; i < cats.length; ++i) {
  981. if ((zui_menu_button(tr(cats[i]))) || (ui_nodes_ui.is_hovered && ui_nodes_show_menu)) {
  982. ui_nodes_show_menu = true;
  983. ui_nodes_menu_category = i;
  984. ui_nodes_popup_x = ui_nodes_wx + ui_nodes_ui._x;
  985. ui_nodes_popup_y = ui_nodes_wy + ui_nodes_ui._y;
  986. if (config_raw.touch_ui) {
  987. ui_nodes_show_menu_first = true;
  988. let menuw: i32 = math_floor(ew * 2.3);
  989. ui_nodes_popup_x -= menuw / 2;
  990. ui_nodes_popup_x += ui_nodes_ui._w / 2;
  991. }
  992. ui_menu_category_w = ui_nodes_ui._w;
  993. ui_menu_category_h = math_floor(zui_MENUBAR_H(ui_nodes_ui));
  994. }
  995. ui_nodes_ui._x += ui_nodes_ui._w + 3;
  996. ui_nodes_ui._y = 2 + start_y;
  997. }
  998. if (config_raw.touch_ui) {
  999. let _w: i32 = ui_nodes_ui._w;
  1000. ui_nodes_ui._w = math_floor(36 * zui_SCALE(ui_nodes_ui));
  1001. ui_nodes_ui._y = 4 * zui_SCALE(ui_nodes_ui) + start_y;
  1002. if (ui_menubar_icon_button(ui_nodes_ui, 2, 3)) {
  1003. ui_nodes_node_search(math_floor(ui_nodes_ui._window_x + ui_nodes_ui._x), math_floor(ui_nodes_ui._window_y + ui_nodes_ui._y));
  1004. }
  1005. ui_nodes_ui._w = _w;
  1006. }
  1007. else {
  1008. if (zui_menu_button(tr("Search"))) {
  1009. ui_nodes_node_search(math_floor(ui_nodes_ui._window_x + ui_nodes_ui._x), math_floor(ui_nodes_ui._window_y + ui_nodes_ui._y));
  1010. }
  1011. }
  1012. if (ui_nodes_ui.is_hovered) {
  1013. zui_tooltip(tr("Search for nodes") + " (" + map_get(config_keymap, "node_search") + ")");
  1014. }
  1015. ui_nodes_ui._x += ui_nodes_ui._w + 3;
  1016. ui_nodes_ui._y = 2 + start_y;
  1017. ui_nodes_ui.ops.theme.BUTTON_COL = _BUTTON_COL;
  1018. // Close node group
  1019. if (ui_nodes_group_stack.length > 0 && zui_menu_button(tr("Close"))) {
  1020. ui_nodes_group_stack.pop();
  1021. }
  1022. }
  1023. zui_end(!ui_nodes_show_menu);
  1024. g2_begin(null);
  1025. if (ui_nodes_show_menu) {
  1026. ///if (is_paint || is_sculpt)
  1027. let list:zui_node_t[][] = ui_nodes_canvas_type == canvas_type_t.MATERIAL ? nodes_material_list : nodes_brush_list;
  1028. ///end
  1029. ///if is_lab
  1030. let list:zui_node_t[][] = nodes_brush_list;
  1031. ///end
  1032. let num_nodes: i32 = list[ui_nodes_menu_category].length;
  1033. ///if (is_paint || is_sculpt)
  1034. let is_group_category: bool = ui_nodes_canvas_type == canvas_type_t.MATERIAL && nodes_material_categories[ui_nodes_menu_category] == "Group";
  1035. ///end
  1036. ///if is_lab
  1037. let is_group_category: bool = nodes_material_categories[ui_nodes_menu_category] == "Group";
  1038. ///end
  1039. if (is_group_category) num_nodes += project_material_groups.length;
  1040. let py: i32 = ui_nodes_popup_y;
  1041. let menuw: i32 = math_floor(ew * 2.3);
  1042. zui_begin_region(ui_nodes_ui, math_floor(ui_nodes_popup_x), math_floor(py), menuw);
  1043. let _BUTTON_COL: i32 = ui_nodes_ui.ops.theme.BUTTON_COL;
  1044. ui_nodes_ui.ops.theme.BUTTON_COL = ui_nodes_ui.ops.theme.SEPARATOR_COL;
  1045. let _ELEMENT_OFFSET: i32 = ui_nodes_ui.ops.theme.ELEMENT_OFFSET;
  1046. ui_nodes_ui.ops.theme.ELEMENT_OFFSET = 0;
  1047. let _ELEMENT_H: i32 = ui_nodes_ui.ops.theme.ELEMENT_H;
  1048. ui_nodes_ui.ops.theme.ELEMENT_H = config_raw.touch_ui ? (28 + 2) : 28;
  1049. ui_menu_start(ui_nodes_ui);
  1050. for (let i: i32 = 0; i < list[ui_nodes_menu_category].length; ++i) {
  1051. let n: zui_node_t = list[ui_nodes_menu_category][i];
  1052. if (ui_menu_button(ui_nodes_ui, tr(n.name))) {
  1053. ui_nodes_push_undo();
  1054. let canvas: zui_node_canvas_t = ui_nodes_get_canvas(true);
  1055. let nodes: zui_nodes_t = ui_nodes_get_nodes();
  1056. let node: zui_node_t = ui_nodes_make_node(n, nodes, canvas);
  1057. array_push(canvas.nodes, node);
  1058. nodes.nodes_selected_id = [node.id];
  1059. nodes.nodes_drag = true;
  1060. ///if is_lab
  1061. parser_logic_parse(canvas);
  1062. ///end
  1063. }
  1064. // Next column
  1065. if (ui_nodes_ui._y - ui_nodes_wy + zui_ELEMENT_H(ui_nodes_ui) / 2 > ui_nodes_wh) {
  1066. ui_nodes_ui._x += menuw;
  1067. ui_nodes_ui._y = py;
  1068. }
  1069. }
  1070. if (is_group_category) {
  1071. for (let i: i32 = 0; i < project_material_groups.length; ++i) {
  1072. let g: node_group_t = project_material_groups[i];
  1073. zui_fill(0, 1, ui_nodes_ui._w / zui_SCALE(ui_nodes_ui), ui_nodes_ui.ops.theme.BUTTON_H + 2, ui_nodes_ui.ops.theme.ACCENT_SELECT_COL);
  1074. zui_fill(1, 1, ui_nodes_ui._w / zui_SCALE(ui_nodes_ui) - 2, ui_nodes_ui.ops.theme.BUTTON_H + 1, ui_nodes_ui.ops.theme.SEPARATOR_COL);
  1075. ui_nodes_ui.enabled = ui_nodes_can_place_group(g.canvas.name);
  1076. ui_menu_fill(ui_nodes_ui);
  1077. let row: f32[] = [5 / 6, 1 / 6];
  1078. zui_row(row);
  1079. if (zui_button(config_button_spacing + g.canvas.name, zui_align_t.LEFT)) {
  1080. ui_nodes_push_undo();
  1081. let canvas: zui_node_canvas_t = ui_nodes_get_canvas(true);
  1082. let nodes: zui_nodes_t = ui_nodes_get_nodes();
  1083. let node: zui_node_t = ui_nodes_make_group_node(g.canvas, nodes, canvas);
  1084. array_push(canvas.nodes, node);
  1085. nodes.nodes_selected_id = [node.id];
  1086. nodes.nodes_drag = true;
  1087. }
  1088. ///if (is_paint || is_sculpt)
  1089. ui_nodes_ui.enabled = !project_is_material_group_in_use(g);
  1090. if (zui_button("x", zui_align_t.CENTER)) {
  1091. history_delete_material_group(g);
  1092. array_remove(project_material_groups, g);
  1093. }
  1094. ///end
  1095. ui_nodes_ui.enabled = true;
  1096. }
  1097. }
  1098. ui_nodes_hide_menu = ui_nodes_ui.combo_selected_handle_ptr == 0 && !ui_nodes_show_menu_first && (ui_nodes_ui.changed || ui_nodes_ui.input_released || ui_nodes_ui.input_released_r || ui_nodes_ui.is_escape_down);
  1099. ui_nodes_show_menu_first = false;
  1100. ui_nodes_ui.ops.theme.BUTTON_COL = _BUTTON_COL;
  1101. ui_nodes_ui.ops.theme.ELEMENT_OFFSET = _ELEMENT_OFFSET;
  1102. ui_nodes_ui.ops.theme.ELEMENT_H = _ELEMENT_H;
  1103. zui_end_region();
  1104. }
  1105. if (ui_nodes_hide_menu) {
  1106. ui_nodes_show_menu = false;
  1107. ui_nodes_show_menu_first = true;
  1108. }
  1109. }
  1110. function ui_nodes_contains_node_group_recursive(group: node_group_t, group_name: string): bool {
  1111. if (group.canvas.name == group_name) {
  1112. return true;
  1113. }
  1114. for (let i: i32 = 0; i < group.canvas.nodes.length; ++i) {
  1115. let n: zui_node_t = group.canvas.nodes[i];
  1116. if (n.type == "GROUP") {
  1117. let g: node_group_t = project_get_material_group_by_name(n.name);
  1118. if (g != null && ui_nodes_contains_node_group_recursive(g, group_name)) {
  1119. return true;
  1120. }
  1121. }
  1122. }
  1123. return false;
  1124. }
  1125. function ui_nodes_can_place_group(group_name: string): bool {
  1126. // Prevent Recursive node groups
  1127. // The group to place must not contain the current group or a group that contains the current group
  1128. if (ui_nodes_group_stack.length > 0) {
  1129. for (let i: i32 = 0; i < ui_nodes_group_stack.length; ++i) {
  1130. let g: node_group_t = ui_nodes_group_stack[i];
  1131. if (ui_nodes_contains_node_group_recursive(project_get_material_group_by_name(group_name), g.canvas.name)) return false;
  1132. }
  1133. }
  1134. // Group was deleted / renamed
  1135. let group_exists: bool = false;
  1136. for (let i: i32 = 0; i < project_material_groups.length; ++i) {
  1137. let group: node_group_t = project_material_groups[i];
  1138. if (group_name == group.canvas.name) {
  1139. group_exists = true;
  1140. }
  1141. }
  1142. if (!group_exists) {
  1143. return false;
  1144. }
  1145. return true;
  1146. }
  1147. function ui_nodes_push_undo(last_canvas: zui_node_canvas_t = null) {
  1148. if (last_canvas == null) {
  1149. last_canvas = ui_nodes_get_canvas(true);
  1150. }
  1151. let canvas_group: i32 = ui_nodes_group_stack.length > 0 ? array_index_of(project_material_groups, ui_nodes_group_stack[ui_nodes_group_stack.length - 1]) : null;
  1152. ///if (is_paint || is_sculpt)
  1153. ui_base_hwnds[tab_area_t.SIDEBAR0].redraws = 2;
  1154. history_edit_nodes(last_canvas, ui_nodes_canvas_type, canvas_group);
  1155. ///end
  1156. ///if is_lab
  1157. history_edit_nodes(last_canvas, canvas_group);
  1158. ///end
  1159. }
  1160. function ui_nodes_accept_asset_drag(index: i32) {
  1161. ui_nodes_push_undo();
  1162. let g: node_group_t = ui_nodes_group_stack.length > 0 ? ui_nodes_group_stack[ui_nodes_group_stack.length - 1] : null;
  1163. ///if (is_paint || is_sculpt)
  1164. let n: zui_node_t = ui_nodes_canvas_type == canvas_type_t.MATERIAL ? nodes_material_create_node("TEX_IMAGE", g) : nodes_brush_create_node("TEX_IMAGE");
  1165. ///end
  1166. ///if is_lab
  1167. let n: zui_node_t = nodes_brush_create_node("ImageTextureNode");
  1168. ///end
  1169. n.buttons[0].default_value[0] = index;
  1170. ui_nodes_get_nodes().nodes_selected_id = [n.id];
  1171. ///if is_lab
  1172. parser_logic_parse(project_canvas);
  1173. ///end
  1174. }
  1175. ///if (is_paint || is_sculpt)
  1176. function ui_nodes_accept_layer_drag(index: i32) {
  1177. ui_nodes_push_undo();
  1178. if (slot_layer_is_group(project_layers[index])) {
  1179. return;
  1180. }
  1181. let g: node_group_t = ui_nodes_group_stack.length > 0 ? ui_nodes_group_stack[ui_nodes_group_stack.length - 1] : null;
  1182. let n: zui_node_t = nodes_material_create_node(slot_layer_is_mask(context_raw.layer) ? "LAYER_MASK" : "LAYER", g);
  1183. n.buttons[0].default_value[0] = index;
  1184. ui_nodes_get_nodes().nodes_selected_id = [n.id];
  1185. }
  1186. function ui_nodes_accept_material_drag(index: i32) {
  1187. ui_nodes_push_undo();
  1188. let g: node_group_t = ui_nodes_group_stack.length > 0 ? ui_nodes_group_stack[ui_nodes_group_stack.length - 1] : null;
  1189. let n: zui_node_t = nodes_material_create_node("MATERIAL", g);
  1190. n.buttons[0].default_value[0] = index;
  1191. ui_nodes_get_nodes().nodes_selected_id = [n.id];
  1192. }
  1193. ///end
  1194. function ui_nodes_accept_swatch_drag(swatch: swatch_color_t) {
  1195. ///if (is_paint || is_sculpt)
  1196. ui_nodes_push_undo();
  1197. let g: node_group_t = ui_nodes_group_stack.length > 0 ? ui_nodes_group_stack[ui_nodes_group_stack.length - 1] : null;
  1198. let n: zui_node_t = nodes_material_create_node("RGB", g);
  1199. n.outputs[0].default_value = f32_array_create_xyzw(
  1200. color_get_rb(swatch.base) / 255,
  1201. color_get_gb(swatch.base) / 255,
  1202. color_get_bb(swatch.base) / 255,
  1203. color_get_ab(swatch.base) / 255
  1204. );
  1205. ui_nodes_get_nodes().nodes_selected_id = [n.id];
  1206. ///end
  1207. }
  1208. function ui_nodes_make_node(n: zui_node_t, nodes: zui_nodes_t, canvas: zui_node_canvas_t): zui_node_t {
  1209. let node: zui_node_t = {};
  1210. node.id = zui_get_node_id(canvas.nodes);
  1211. node.name = n.name;
  1212. node.type = n.type;
  1213. node.x = ui_nodes_get_node_x();
  1214. node.y = ui_nodes_get_node_y();
  1215. node.color = n.color;
  1216. node.inputs = [];
  1217. node.outputs = [];
  1218. node.buttons = [];
  1219. node.width = 0;
  1220. let count: i32 = 0;
  1221. for (let i: i32 = 0; i < n.inputs.length; ++i) {
  1222. let soc: zui_node_socket_t = {}
  1223. soc.id = zui_get_socket_id(canvas.nodes) + count;
  1224. count++;
  1225. soc.node_id = node.id;
  1226. soc.name = n.inputs[i].name;
  1227. soc.type = n.inputs[i].type;
  1228. soc.color = n.inputs[i].color;
  1229. soc.default_value = n.inputs[i].default_value;
  1230. soc.min = n.inputs[i].min;
  1231. soc.max = n.inputs[i].max;
  1232. soc.precision = n.inputs[i].precision;
  1233. soc.display = n.inputs[i].display;
  1234. array_push(node.inputs, soc);
  1235. }
  1236. for (let i: i32 = 0; i < n.outputs.length; ++i) {
  1237. let soc: zui_node_socket_t = {};
  1238. soc.id = zui_get_socket_id(canvas.nodes) + count;
  1239. count++;
  1240. soc.node_id = node.id;
  1241. soc.name = n.outputs[i].name;
  1242. soc.type = n.outputs[i].type;
  1243. soc.color = n.outputs[i].color;
  1244. soc.default_value = n.outputs[i].default_value;
  1245. soc.min = n.outputs[i].min;
  1246. soc.max = n.outputs[i].max;
  1247. soc.precision = n.outputs[i].precision;
  1248. soc.display = n.outputs[i].display;
  1249. array_push(node.outputs, soc);
  1250. }
  1251. for (let i: i32 = 0; i < n.buttons.length; ++i) {
  1252. let but: zui_node_button_t = {};
  1253. but.name = n.buttons[i].name;
  1254. but.type = n.buttons[i].type;
  1255. but.output = n.buttons[i].output;
  1256. but.default_value = n.buttons[i].default_value;
  1257. but.data = n.buttons[i].data;
  1258. but.min = n.buttons[i].min;
  1259. but.max = n.buttons[i].max;
  1260. but.precision = n.buttons[i].precision;
  1261. but.height = n.buttons[i].height;
  1262. array_push(node.buttons, but);
  1263. }
  1264. return node;
  1265. }
  1266. function ui_nodes_make_group_node(group_canvas: zui_node_canvas_t, nodes: zui_nodes_t, canvas: zui_node_canvas_t): zui_node_t {
  1267. let n: zui_node_t = nodes_material_list[5][0];
  1268. let node: zui_node_t = json_parse(json_stringify(n));
  1269. node.name = group_canvas.name;
  1270. node.id = zui_get_node_id(canvas.nodes);
  1271. node.x = ui_nodes_get_node_x();
  1272. node.y = ui_nodes_get_node_y();
  1273. let group_input: zui_node_t = null;
  1274. let group_output: zui_node_t = null;
  1275. for (let i: i32 = 0; i < project_material_groups.length; ++i) {
  1276. let g: node_group_t = project_material_groups[i];
  1277. if (g.canvas.name == node.name) {
  1278. for (let i: i32 = 0; i < g.canvas.nodes.length; ++i) {
  1279. let n: zui_node_t = g.canvas.nodes[i];
  1280. if (n.type == "GROUP_INPUT") {
  1281. group_input = n;
  1282. }
  1283. else if (n.type == "GROUP_OUTPUT") {
  1284. group_output = n;
  1285. }
  1286. }
  1287. break;
  1288. }
  1289. }
  1290. if (group_input != null && group_output != null) {
  1291. for (let i: i32 = 0; i < group_input.outputs.length; ++i) {
  1292. let soc: zui_node_socket_t = group_input.outputs[i];
  1293. array_push(node.inputs, nodes_material_create_socket(nodes, node, soc.name, soc.type, canvas, soc.min, soc.max, soc.default_value));
  1294. }
  1295. for (let i: i32 = 0; i < group_output.inputs.length; ++i) {
  1296. let soc: zui_node_socket_t = group_output.inputs[i];
  1297. array_push(node.outputs, nodes_material_create_socket(nodes, node, soc.name, soc.type, canvas, soc.min, soc.max, soc.default_value));
  1298. }
  1299. }
  1300. return node;
  1301. }
  1302. ///if (is_paint || is_sculpt)
  1303. function ui_nodes_make_node_preview() {
  1304. let nodes: zui_nodes_t = context_raw.material.nodes;
  1305. if (nodes.nodes_selected_id.length == 0) {
  1306. return;
  1307. }
  1308. let node: zui_node_t = zui_get_node(context_raw.material.canvas.nodes, nodes.nodes_selected_id[0]);
  1309. // if (node == null) return;
  1310. context_raw.node_preview_name = node.name;
  1311. if (node.type == "LAYER" ||
  1312. node.type == "LAYER_MASK" ||
  1313. node.type == "MATERIAL" ||
  1314. node.type == "OUTPUT_MATERIAL_PBR") {
  1315. return;
  1316. }
  1317. if (array_index_of(context_raw.material.canvas.nodes, node) == -1) {
  1318. return;
  1319. }
  1320. if (context_raw.node_preview == null) {
  1321. context_raw.node_preview = image_create_render_target(util_render_material_preview_size, util_render_material_preview_size);
  1322. }
  1323. context_raw.node_preview_dirty = false;
  1324. ui_nodes_hwnd.redraws = 2;
  1325. util_render_make_node_preview(context_raw.material.canvas, node, context_raw.node_preview);
  1326. }
  1327. ///end
  1328. function ui_nodes_has_group(c: zui_node_canvas_t): bool {
  1329. for (let i: i32 = 0; i < c.nodes.length; ++i) {
  1330. let n: zui_node_t = c.nodes[i];
  1331. if (n.type == "GROUP") {
  1332. return true;
  1333. }
  1334. }
  1335. return false;
  1336. }
  1337. function ui_nodes_traverse_group(mgroups: zui_node_canvas_t[], c: zui_node_canvas_t) {
  1338. for (let i: i32 = 0; i < c.nodes.length; ++i) {
  1339. let n: zui_node_t = c.nodes[i];
  1340. if (n.type == "GROUP") {
  1341. if (ui_nodes_get_group(mgroups, n.name) == null) {
  1342. let canvases: zui_node_canvas_t[] = [];
  1343. for (let i: i32 = 0; i < project_material_groups.length; ++i) {
  1344. let g: node_group_t = project_material_groups[i];
  1345. array_push(canvases, g.canvas);
  1346. }
  1347. let group: zui_node_canvas_t = ui_nodes_get_group(canvases, n.name);
  1348. array_push(mgroups, json_parse(json_stringify(group)));
  1349. ui_nodes_traverse_group(mgroups, group);
  1350. }
  1351. }
  1352. }
  1353. }
  1354. function ui_nodes_get_group(canvases: zui_node_canvas_t[], name: string): zui_node_canvas_t {
  1355. for (let i: i32 = 0; i < canvases.length; ++i) {
  1356. let c: zui_node_canvas_t = canvases[i];
  1357. if (c.name == name) {
  1358. return c;
  1359. }
  1360. }
  1361. return null;
  1362. }