From d9b81b0706a18ca5da297689d6d48ae80e689e36 Mon Sep 17 00:00:00 2001 From: Tanasart Date: Thu, 16 Jan 2025 13:27:35 +0700 Subject: [PATCH] plot function cache --- datafiles/data/Nodes/Internal.zip | Bin 9092560 -> 9092560 bytes .../node_armature_path/node_armature_path.gml | 12 -- scripts/node_line/node_line.gml | 35 ++- scripts/node_path_plot/node_path_plot.gml | 201 +++++++++++++----- scripts/pcx_ast/pcx_ast.gml | 4 +- 5 files changed, 171 insertions(+), 81 deletions(-) diff --git a/datafiles/data/Nodes/Internal.zip b/datafiles/data/Nodes/Internal.zip index dd56c1612776bf9849efa2c66c6ddecd086d35a5..c4527b1b425b1c7bc6c76e5360e6e5e51d7821cc 100644 GIT binary patch delta 1312 zcmZ9~OH5Q}6bEqS;Q)#j9Z}1b#~^}=Frrr8^0=KD2CJi1R0gSU#rFeRZ7YNJ-x=<8 zWu0S8i$iZsl`ETm&L=HNYKU@qptiTTLH0xZNLypJqsSd47sAQyRX zAsmYYVm<0mj|Mc})PtUc zh7MKg)3ek$kDe~Y=_VGt_IlFPs7Fte&Ml9=LUPKZuatCp^-vz>A7xxYMUEw=+xi`Sdwb-0DuPY38A9iqe3K}YB)9i!uPf=<#YI!$Nj zEOk;BeM+CvIXX|D(--t5U7&6XQ4d|DOY~JV;K%t>33`W`xPwYb$6c&rM(gh4wnG{( zzelxwKvR!?fb)&-pX07^RLS_ean#z!izC_hL0?C+?}vX(mhSVP!)22E5nXEX&#>d| zC4mRwRq?U=@32FSJ_x5thZC2|O^qb0Cw3>c!mUN#SrKbrU;J+SvRv5iilnH}gtd{K zHQXHG2PhI9o9O-H7x^dY?>EXNfA2TeOXdt1Rg!H3MvdgR14gyvuLDM{U2AIXpph%Z z_Ccdg@|!_x$Pa7k-$5fsnwdk^=D?6qDK%45!$U^46h93a6_Qs%rlxX+jY27Sho<%q z8?JcKZx?)>rk)KO`7((W1tV6$_i5_ji1nV{5o@a~iar@JmX6A|Srp_Q`7LIN6kA(N zFEe_z#jH+}Mn)T_|FxQK`>0>CGiWwTjs?w)%qR~{B} zkH1P>q+zT;0#+gsNq80xtU@wU@ElfS4b~zR>yU=^NQV;}uo2JW1-yutkO2*wkclj0 zBL^(SSzmMAKD0 z=t*$5sZyVwp$0wr8Yzx8v*F`bE`&4GPjgtiI?%E*(fN%0vCZ2` zWZY;c-&rbk?7i2Tb*B`+G+R$w;kS0ho_NO-Nsa{kI=x07@{*65$xkixI_;v}^acfJ z54F->YNLJBP94-qU9_Kq)J;9qOK;KvdW#Oy+tf#g=rFxQ{q!!qNAJ@I^dWsjAJY*! zN(1x>9i!v)DV?A}I!UMKGy0rP(-4Jdm`3Ofos9`1l;EWqf50b@uV%Naj4~Tr_h&{6ms-|F{`0ljM)+Qj5QZ z9sgevxE0~xKws>BuU+~JFyjREwXGyto`+-O&R&q@@*Cdc}H%$St7;W zcGJs@e%Wr;BuXQ#o72Ddn{NB4U-DScY>}J|n!A}%9$Lzg#y_XcoszM4cMh2aQj83l rjq&FF|C*Z03z>QGNq@*X&d)YUQyb>Zk3wdlUFiRwj1CQ(t+h`83h>)f diff --git a/scripts/node_armature_path/node_armature_path.gml b/scripts/node_armature_path/node_armature_path.gml index 2622d8e05..74c079fdc 100644 --- a/scripts/node_armature_path/node_armature_path.gml +++ b/scripts/node_armature_path/node_armature_path.gml @@ -40,18 +40,6 @@ function Node_Armature_Path(_x, _y, _group = noone) : Node(_x, _y, _group) const static getLength = function() { return current_length; } static getAccuLength = function() { return [ 0, current_length ]; } - static getWeightDistance = function (_dist, _ind = 0) { return getWeightRatio(_dist / current_length, _ind); } - - static getWeightRatio = function (_rat, _ind = 0) { - var _p0 = lines[_ind][0]; - var _p1 = lines[_ind][1]; - - if(!is_array(_p0) || array_length(_p0) < 3) return 1; - if(!is_array(_p1) || array_length(_p1) < 3) return 1; - - return lerp(_p0[2], _p1[2], _rat); - } - static getPointDistance = function(_dist, _ind = 0, out = undefined) { return getPointRatio(_dist / current_length, _ind, out); } static getPointRatio = function(_rat, _ind = 0, out = undefined) { diff --git a/scripts/node_line/node_line.gml b/scripts/node_line/node_line.gml index 29160c715..cb0ff51d0 100644 --- a/scripts/node_line/node_line.gml +++ b/scripts/node_line/node_line.gml @@ -83,13 +83,21 @@ function Node_Line(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) cons newInput(35, nodeValue_Bool("Force Loop", self, false)); + newInput(36, nodeValue_Bool("Apply Weight", self, true)); + + newInput(37, nodeValue_Gradient("Color Weight", self, new gradientObject(cola(c_white)))); + + newInput(38, nodeValue_Vec2("Color Range", self, [ 0, 1 ])); + input_display_list = [ - ["Output", true], 0, 1, 30, 31, - ["Line data", false], 27, 6, 7, 28, 32, 33, 35, 19, 2, 20, - ["Line settings", false], 17, 3, 11, 12, 8, 25, 9, 26, 13, 14, - ["Wiggle", false], 4, 5, - ["Render", false], 10, 24, 15, 16, 34, - ["Texture", false], 18, 21, 22, 23, 29, + ["Output", true], 0, 1, 30, 31, 16, + ["Line data", false], 27, 6, 7, 28, 32, 33, 35, 19, 2, 20, + ["Width", false], 17, 3, 11, 12, 36, + ["Line settings", false], 8, 25, 9, 26, 13, 14, + ["Wiggle", false], 4, 5, + ["Color", false], 10, 24, 15, 37, 38, + ["Texture", false], 18, 21, 22, 23, 29, + ["Render", false], 34, ]; newOutput(0, nodeValue_Output("Surface out", self, VALUE_TYPE.surface, noone)); @@ -232,6 +240,10 @@ function Node_Line(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) cons var _aa = power(2, _data[34]); var _loop = _data[35]; + var _wg2wid = _data[36]; + + var _wg2clr = _data[37]; + var _wg2clrR = _data[38]; if(_dtype == 1 && _pat == noone) _dtype = 0; @@ -429,7 +441,7 @@ function Node_Line(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) cons y: _ny, prog: (_prog_total - _pathStr) / (_pathEnd - _pathStr), progCrop: _prog_curr / _pathLength, - weight: wght + weight: wght, } minx = min(minx, _nx); @@ -552,6 +564,8 @@ function Node_Line(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) cons var _padx = _pbbox * (_ppadd[2] - minx); var _pady = _pbbox * (_ppadd[1] - miny); + var _wg2clrRng = _wg2clrR[1] - _wg2clrR[0]; + temp_surface[0] = surface_verify(temp_surface[0], _surfDim[0] * _aa, _surfDim[1] * _aa, attrDepth()); var _cPassAA = temp_surface[0]; @@ -603,9 +617,12 @@ function Node_Line(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) cons if(!ds_map_exists(widthMap, widProg)) widthMap[? widProg] = eval_curve_x(_widc, widProg, 0.1); _nw *= widthMap[? widProg]; - _nw *= p0.weight / 2; - _nc = colorMultiply(_col_base, _color.eval(_colP? prog : prgc)); + if(_wg2wid) _nw *= p0.weight / 2; + + _nc = _col_base; + _nc = colorMultiply(_nc, _color.eval(_colP? prog : prgc)); + _nc = colorMultiply(_nc, _wg2clr.eval((p0.weight - _wg2clrR[0]) / _wg2clrRng)); if(_cap) { if(j == 1) { diff --git a/scripts/node_path_plot/node_path_plot.gml b/scripts/node_path_plot/node_path_plot.gml index ac7a99737..d5cad6a0f 100644 --- a/scripts/node_path_plot/node_path_plot.gml +++ b/scripts/node_path_plot/node_path_plot.gml @@ -19,20 +19,44 @@ function Node_Path_Plot(_x, _y, _group = noone) : Node(_x, _y, _group) construct newInput(6, nodeValue_Slider_Range("Range", self, [ 0, 1 ], { range: [ -1, 1, 0.01 ] })); - newInput(7, nodeValue_Vec2("Input scale", self, [ 1, 1 ])); - - newInput(8, nodeValue_Vec2("Input shift", self, [ 0, 0 ])); - + newInput(7, nodeValue_Vec2("Input Scale", self, [ 1, 1 ])); + + newInput(8, nodeValue_Vec2("Input Shift", self, [ 0, 0 ])); + + newInput(9, nodeValue_Bool("Use Weight", self, false)); + + newInput(10, nodeValue_Text("w(x)", self, "")); + newOutput(0, nodeValue_Output("Path", self, VALUE_TYPE.pathnode, self)); input_display_list = [ - [ "Variable", false ], 5, 7, 8, 0, - [ "Equation", false ], 1, 2, 3, 4, 6, + [ "Variable", false], 5, 7, 8, 0, + [ "Equation", false], 1, 2, 3, 4, 6, + [ "Weight", false, 9], 10, ] boundary = new BoundingBox( 0, 0, 1, 1 ); cached_pos = ds_map_create(); + curr_sca = 0; + curr_coor = 0; + curr_eqa = 0; + curr_eq0 = 0; + curr_eq1 = 0; + curr_orig = 0; + curr_ran = 0; + curr_iran = 0; + curr_shf = 0; + + curr_usew = 0; + curr_wgfn = 0; + + fn0 = 0; + fn1 = 0; + + _a = new __vec2P(); + _param = { x:0, y:0, t:0, r:0, O:0 }; + static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) { inputs[5].drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny); } @@ -46,59 +70,99 @@ function Node_Path_Plot(_x, _y, _group = noone) : Node(_x, _y, _group) construct static getPointRatio = function(_rat, ind = 0, out = undefined) { if(out == undefined) out = new __vec2P(); else { out.x = 0; out.y = 0; } - var _sca = getInputData(0); - var _coor = getInputData(1); - var _eqa = getInputData(2); - var _eq0 = getInputData(3); - var _eq1 = getInputData(4); - var _orig = getInputData(5); - var _ran = getInputData(6); - var _iran = getInputData(7); - var _shf = getInputData(8); + _rat = curr_ran[0] + (_rat * (curr_ran[1] - curr_ran[0])); - _rat = _ran[0] + (_rat * (_ran[1] - _ran[0])); - - switch(_coor) { + switch(curr_coor) { case 0 : - switch(_eqa) { + switch(curr_eqa) { case 0 : - out.x = _rat * _iran[0] + _shf[0]; - out.y = evaluateFunction(_eq0, { x: _rat * _iran[0] + _shf[0] }); + _param.x = _rat * curr_iran[0] + curr_shf[0]; + + out.x = _rat * curr_iran[0] + curr_shf[0]; + out.y = fn0.eval(_param); + + if(curr_usew) { + _param.x = _rat; + out.weight = fnw.eval(_param); + } break; + case 1 : - out.x = evaluateFunction(_eq0, { y: _rat * _iran[1] + _shf[1] }); - out.y = _rat * _iran[1] + _shf[1]; + _param.y = _rat * curr_iran[1] + curr_shf[1]; + + out.x = fn0.eval(_param); + out.y = _rat * curr_iran[1] + curr_shf[1]; + + if(curr_usew) { + _param.y = _rat; + out.weight = fnw.eval(_param); + } break; + case 2 : - out.x = evaluateFunction(_eq0, { t: _rat * _iran[0] + _shf[0] }); - out.y = evaluateFunction(_eq1, { t: _rat * _iran[1] + _shf[1] }); + _param.t = _rat * curr_iran[0] + curr_shf[0]; + out.x = fn0.eval(_param); + + _param.t = _rat * curr_iran[1] + curr_shf[1]; + out.y = fn1.eval(_param); + + if(curr_usew) { + _param.t = _rat; + out.weight = fnw.eval(_param); + } break; } break; + case 1 : - var _a = new __vec2P(); - switch(_eqa) { + var _ax = 0, _ay = 0; + + switch(curr_eqa) { case 0 : - _a.x = _rat * _iran[0] + _shf[0]; - _a.y = evaluateFunction(_eq0, { r: _rat * _iran[0] + _shf[0] }); + _param.r = _rat * curr_iran[0] + curr_shf[0]; + + _ax = _rat * curr_iran[0] + curr_shf[0]; + _ay = fn0.eval(_param); + + if(curr_usew) { + _param.r = _rat; + out.weight = fnw.eval(_param); + } break; + case 1 : - _a.x = evaluateFunction(_eq0, { O: _rat * _iran[1] + _shf[1] }); - _a.y = _rat * _iran[1] + _shf[1]; + _param.O = _rat * curr_iran[1] + curr_shf[1]; + + _ax = fn0.eval(_param); + _ay = _rat * curr_iran[1] + curr_shf[1]; + + if(curr_usew) { + _param.O = _rat; + out.weight = fnw.eval(_param); + } break; + case 2 : - _a.x = evaluateFunction(_eq0, { t: _rat * _iran[0] + _shf[0] }); - _a.y = evaluateFunction(_eq1, { t: _rat * _iran[1] + _shf[1] }); + _param.t = _rat * curr_iran[0] + curr_shf[0]; + _ax = fn0.eval(_param); + + _param.t = _rat * curr_iran[1] + curr_shf[1]; + _ay = fn1.eval(_param); + + if(curr_usew) { + _param.t = _rat; + out.weight = fnw.eval(_param); + } break; } - out.x = cos(_a.y) * _a.x; - out.y = -sin(_a.y) * _a.x; + out.x = cos(_ay) * _ax; + out.y = -sin(_ay) * _ax; break; } - out.x = out.x * _sca[0] + _orig[0]; - out.y = -out.y * _sca[1] + _orig[1]; + out.x = out.x * curr_sca[0] + curr_orig[0]; + out.y = -out.y * curr_sca[1] + curr_orig[1]; return out; } @@ -110,45 +174,51 @@ function Node_Path_Plot(_x, _y, _group = noone) : Node(_x, _y, _group) construct var _eqa = getInputData(2); inputs[2].editWidget.data_list = _coor? eq_type_pol : eq_type_car; + inputs[4].setVisible(_eqa == 2); switch(_coor) { case 0 : switch(_eqa) { case 0 : - inputs[3].name = "f(x) = "; - inputs[4].setVisible(false); - inputs[6].name = "x range"; + inputs[ 3].name = "f(x) = "; + inputs[ 6].name = "x range"; + inputs[10].name = "w(x) = "; break; + case 1 : - inputs[3].name = "f(y) = "; - inputs[4].setVisible(false); - inputs[6].name = "y range"; + inputs[ 3].name = "f(y) = "; + inputs[ 6].name = "y range"; + inputs[10].name = "w(y) = "; break; + case 2 : - inputs[3].name = "x(t) = "; - inputs[4].name = "y(t) = "; - inputs[4].setVisible(true); - inputs[6].name = "t range"; + inputs[ 3].name = "x(t) = "; + inputs[ 4].name = "y(t) = "; + inputs[ 6].name = "t range"; + inputs[10].name = "w(t) = "; break; } break; + case 1 : switch(_eqa) { case 0 : - inputs[3].name = "f(r) = "; - inputs[4].setVisible(false); - inputs[6].name = "r range"; + inputs[ 3].name = "f(r) = "; + inputs[ 6].name = "r range"; + inputs[10].name = "w(r) = "; break; + case 1 : - inputs[3].name = "f(O) = "; - inputs[4].setVisible(false); - inputs[6].name = "O range"; + inputs[ 3].name = "f(O) = "; + inputs[ 6].name = "O range"; + inputs[10].name = "w(O) = "; break; + case 2 : - inputs[3].name = "r(t) = "; - inputs[4].name = "O(t) = "; - inputs[4].setVisible(true); - inputs[6].name = "t range"; + inputs[ 3].name = "r(t) = "; + inputs[ 4].name = "O(t) = "; + inputs[ 6].name = "t range"; + inputs[10].name = "w(t) = "; break; } break; @@ -173,6 +243,23 @@ function Node_Path_Plot(_x, _y, _group = noone) : Node(_x, _y, _group) construct } static update = function() { + curr_sca = getInputData(0); + curr_coor = getInputData(1); + curr_eqa = getInputData(2); + curr_eq0 = getInputData(3); + curr_eq1 = getInputData(4); + curr_orig = getInputData(5); + curr_ran = getInputData(6); + curr_iran = getInputData(7); + curr_shf = getInputData(8); + + curr_usew = getInputData( 9); + curr_wgfn = getInputData(10); + + fn0 = evaluateFunctionList(curr_eq0); + fn1 = evaluateFunctionList(curr_eq1); + fnw = evaluateFunctionList(curr_wgfn); + updateBoundary(); outputs[0].setValue(self); } diff --git a/scripts/pcx_ast/pcx_ast.gml b/scripts/pcx_ast/pcx_ast.gml index 56c7d5eaf..47d4f4c40 100644 --- a/scripts/pcx_ast/pcx_ast.gml +++ b/scripts/pcx_ast/pcx_ast.gml @@ -517,9 +517,7 @@ return v1; } - static toString = function() { - return $"[PCX funcTree] \{ symbol: {symbol}, l: {l}, r: {r}\}"; - } + static toString = function() { return $"[PCX funcTree] \{ symbol: {symbol}, l: {l}, r: {r}\}"; } } function evaluateFunction(fx, params = {}) {