From 8442cc6f195eb497ccca9e5b574e8a2b62fce921 Mon Sep 17 00:00:00 2001 From: Tanasart Date: Fri, 5 Jul 2024 09:50:07 +0700 Subject: [PATCH] auto align --- .../node_align_functions.gml | 35 +++++++++++++++++-- scripts/panel_graph/panel_graph.gml | 4 +++ shaders/sh_rm_primitive/sh_rm_primitive.fsh | 2 +- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/scripts/node_align_functions/node_align_functions.gml b/scripts/node_align_functions/node_align_functions.gml index 20a47562c..55599b616 100644 --- a/scripts/node_align_functions/node_align_functions.gml +++ b/scripts/node_align_functions/node_align_functions.gml @@ -110,7 +110,7 @@ function node_vdistribute(nodeList) { ds_priority_destroy(nodes); } -function node_hdistribute_dist(nodeList, anchor, distance = 0) { +function node_hdistribute_dist(nodeList, anchor = noone, distance = 0) { var amo = array_length(nodeList); var nodes = ds_priority_create(); @@ -130,6 +130,7 @@ function node_hdistribute_dist(nodeList, anchor, distance = 0) { ar[i] = ds_priority_delete_min(nodes); ds_priority_destroy(nodes); + if(anchor == noone) anchor = ar[0]; var an_ind = array_find(ar, anchor); var an_ind_x = anchor.x + anchor.w + distance; @@ -145,7 +146,7 @@ function node_hdistribute_dist(nodeList, anchor, distance = 0) { } } -function node_vdistribute_dist(nodeList, anchor, distance = 0) { +function node_vdistribute_dist(nodeList, anchor = noone, distance = 0) { var amo = array_length(nodeList); var nodes = ds_priority_create(); @@ -165,6 +166,7 @@ function node_vdistribute_dist(nodeList, anchor, distance = 0) { ar[i] = ds_priority_delete_min(nodes); ds_priority_destroy(nodes); + if(anchor == noone) anchor = ar[0]; var an_ind = array_find(ar, anchor); var an_ind_y = anchor.y + anchor.h + distance; @@ -179,3 +181,32 @@ function node_vdistribute_dist(nodeList, anchor, distance = 0) { an_ind_y -= ar[i].h + distance; } } + +function node_auto_align(nodeList) { + var h_avg = 0, h_var = 0; + var v_avg = 0, v_var = 0; + + var amo = array_length(nodeList); + + for( var i = 0; i < amo; i++ ) { + var _n = nodeList[i]; + var _x = _n.x; + var _y = _n.y; + + h_avg += _x; + v_avg += _y; + } + + h_avg /= amo; + v_avg /= amo; + + for( var i = 0; i < amo; i++ ) { + var _n = nodeList[i]; + + h_var += sqr(_n.x - h_avg); + v_var += sqr(_n.y - v_avg); + } + + if(h_var < v_var) { node_halign(nodeList); node_vdistribute(nodeList); } + else if(v_var < h_var) { node_valign(nodeList); node_hdistribute(nodeList); } +} \ No newline at end of file diff --git a/scripts/panel_graph/panel_graph.gml b/scripts/panel_graph/panel_graph.gml index c5c581cd2..85073cfa5 100644 --- a/scripts/panel_graph/panel_graph.gml +++ b/scripts/panel_graph/panel_graph.gml @@ -80,6 +80,8 @@ function panel_graph_duplicate() { CALL("graph_duplicate"); PANEL_GRAPH.doDuplicate(); } function panel_graph_copy() { CALL("graph_copy"); PANEL_GRAPH.doCopy(); } function panel_graph_paste() { CALL("graph_paste"); PANEL_GRAPH.doPaste(); } + + function panel_graph_auto_align() { CALL("graph_auto_align"); node_auto_align(PANEL_GRAPH.nodes_selecting);} function panel_graph_pan() { CALL("graph_pan"); @@ -391,6 +393,8 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor { addHotkey("Graph", "Pan", "", MOD_KEY.ctrl, panel_graph_pan); addHotkey("Graph", "Zoom", "", MOD_KEY.alt | MOD_KEY.ctrl, panel_graph_zoom); + + addHotkey("Graph", "Auto Align", "L", MOD_KEY.none, panel_graph_auto_align); #endregion #region ++++ toolbars ++++ diff --git a/shaders/sh_rm_primitive/sh_rm_primitive.fsh b/shaders/sh_rm_primitive/sh_rm_primitive.fsh index 85ec2d62a..d3924d619 100644 --- a/shaders/sh_rm_primitive/sh_rm_primitive.fsh +++ b/shaders/sh_rm_primitive/sh_rm_primitive.fsh @@ -537,9 +537,9 @@ float sceneSDF(int index, vec3 p) { mat3 irotMatrix = inverse(rotMatrix); float sca = objectScale[index]; - p /= sca; p -= position[index]; p = irotMatrix * p; + p /= sca; p = wave(waveAmp[index], waveShift[index], waveInt[index], p);