plot function cache

This commit is contained in:
Tanasart 2025-01-16 13:27:35 +07:00
parent b9bcf3360f
commit d9b81b0706
5 changed files with 171 additions and 81 deletions

Binary file not shown.

View file

@ -40,18 +40,6 @@ function Node_Armature_Path(_x, _y, _group = noone) : Node(_x, _y, _group) const
static getLength = function() { return current_length; } static getLength = function() { return current_length; }
static getAccuLength = function() { return [ 0, 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 getPointDistance = function(_dist, _ind = 0, out = undefined) { return getPointRatio(_dist / current_length, _ind, out); }
static getPointRatio = function(_rat, _ind = 0, out = undefined) { static getPointRatio = function(_rat, _ind = 0, out = undefined) {

View file

@ -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(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 = [ input_display_list = [
["Output", true], 0, 1, 30, 31, ["Output", true], 0, 1, 30, 31, 16,
["Line data", false], 27, 6, 7, 28, 32, 33, 35, 19, 2, 20, ["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, ["Width", false], 17, 3, 11, 12, 36,
["Line settings", false], 8, 25, 9, 26, 13, 14,
["Wiggle", false], 4, 5, ["Wiggle", false], 4, 5,
["Render", false], 10, 24, 15, 16, 34, ["Color", false], 10, 24, 15, 37, 38,
["Texture", false], 18, 21, 22, 23, 29, ["Texture", false], 18, 21, 22, 23, 29,
["Render", false], 34,
]; ];
newOutput(0, nodeValue_Output("Surface out", self, VALUE_TYPE.surface, noone)); 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 _aa = power(2, _data[34]);
var _loop = _data[35]; var _loop = _data[35];
var _wg2wid = _data[36];
var _wg2clr = _data[37];
var _wg2clrR = _data[38];
if(_dtype == 1 && _pat == noone) if(_dtype == 1 && _pat == noone)
_dtype = 0; _dtype = 0;
@ -429,7 +441,7 @@ function Node_Line(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) cons
y: _ny, y: _ny,
prog: (_prog_total - _pathStr) / (_pathEnd - _pathStr), prog: (_prog_total - _pathStr) / (_pathEnd - _pathStr),
progCrop: _prog_curr / _pathLength, progCrop: _prog_curr / _pathLength,
weight: wght weight: wght,
} }
minx = min(minx, _nx); 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 _padx = _pbbox * (_ppadd[2] - minx);
var _pady = _pbbox * (_ppadd[1] - miny); 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()); temp_surface[0] = surface_verify(temp_surface[0], _surfDim[0] * _aa, _surfDim[1] * _aa, attrDepth());
var _cPassAA = temp_surface[0]; 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)) if(!ds_map_exists(widthMap, widProg))
widthMap[? widProg] = eval_curve_x(_widc, widProg, 0.1); widthMap[? widProg] = eval_curve_x(_widc, widProg, 0.1);
_nw *= widthMap[? widProg]; _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(_cap) {
if(j == 1) { if(j == 1) {

View file

@ -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(6, nodeValue_Slider_Range("Range", self, [ 0, 1 ], { range: [ -1, 1, 0.01 ] }));
newInput(7, nodeValue_Vec2("Input scale", self, [ 1, 1 ])); newInput(7, nodeValue_Vec2("Input Scale", self, [ 1, 1 ]));
newInput(8, nodeValue_Vec2("Input shift", self, [ 0, 0 ])); 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)); newOutput(0, nodeValue_Output("Path", self, VALUE_TYPE.pathnode, self));
input_display_list = [ input_display_list = [
[ "Variable", false], 5, 7, 8, 0, [ "Variable", false], 5, 7, 8, 0,
[ "Equation", false], 1, 2, 3, 4, 6, [ "Equation", false], 1, 2, 3, 4, 6,
[ "Weight", false, 9], 10,
] ]
boundary = new BoundingBox( 0, 0, 1, 1 ); boundary = new BoundingBox( 0, 0, 1, 1 );
cached_pos = ds_map_create(); 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) { static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
inputs[5].drawOverlay(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) { static getPointRatio = function(_rat, ind = 0, out = undefined) {
if(out == undefined) out = new __vec2P(); else { out.x = 0; out.y = 0; } if(out == undefined) out = new __vec2P(); else { out.x = 0; out.y = 0; }
var _sca = getInputData(0); _rat = curr_ran[0] + (_rat * (curr_ran[1] - curr_ran[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 = _ran[0] + (_rat * (_ran[1] - _ran[0])); switch(curr_coor) {
case 0 :
switch(curr_eqa) {
case 0 :
_param.x = _rat * curr_iran[0] + curr_shf[0];
switch(_coor) { out.x = _rat * curr_iran[0] + curr_shf[0];
case 0 : out.y = fn0.eval(_param);
switch(_eqa) {
case 0 : if(curr_usew) {
out.x = _rat * _iran[0] + _shf[0]; _param.x = _rat;
out.y = evaluateFunction(_eq0, { x: _rat * _iran[0] + _shf[0] }); out.weight = fnw.eval(_param);
}
break; break;
case 1 : case 1 :
out.x = evaluateFunction(_eq0, { y: _rat * _iran[1] + _shf[1] }); _param.y = _rat * curr_iran[1] + curr_shf[1];
out.y = _rat * _iran[1] + _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; break;
case 2 : case 2 :
out.x = evaluateFunction(_eq0, { t: _rat * _iran[0] + _shf[0] }); _param.t = _rat * curr_iran[0] + curr_shf[0];
out.y = evaluateFunction(_eq1, { t: _rat * _iran[1] + _shf[1] }); 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;
} }
break; break;
case 1 : case 1 :
var _a = new __vec2P(); var _ax = 0, _ay = 0;
switch(_eqa) {
switch(curr_eqa) {
case 0 : case 0 :
_a.x = _rat * _iran[0] + _shf[0]; _param.r = _rat * curr_iran[0] + curr_shf[0];
_a.y = evaluateFunction(_eq0, { r: _rat * _iran[0] + _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; break;
case 1 : case 1 :
_a.x = evaluateFunction(_eq0, { O: _rat * _iran[1] + _shf[1] }); _param.O = _rat * curr_iran[1] + curr_shf[1];
_a.y = _rat * _iran[1] + _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; break;
case 2 : case 2 :
_a.x = evaluateFunction(_eq0, { t: _rat * _iran[0] + _shf[0] }); _param.t = _rat * curr_iran[0] + curr_shf[0];
_a.y = evaluateFunction(_eq1, { t: _rat * _iran[1] + _shf[1] }); _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; break;
} }
out.x = cos(_a.y) * _a.x; out.x = cos(_ay) * _ax;
out.y = -sin(_a.y) * _a.x; out.y = -sin(_ay) * _ax;
break; break;
} }
out.x = out.x * _sca[0] + _orig[0]; out.x = out.x * curr_sca[0] + curr_orig[0];
out.y = -out.y * _sca[1] + _orig[1]; out.y = -out.y * curr_sca[1] + curr_orig[1];
return out; return out;
} }
@ -110,45 +174,51 @@ function Node_Path_Plot(_x, _y, _group = noone) : Node(_x, _y, _group) construct
var _eqa = getInputData(2); var _eqa = getInputData(2);
inputs[2].editWidget.data_list = _coor? eq_type_pol : eq_type_car; inputs[2].editWidget.data_list = _coor? eq_type_pol : eq_type_car;
inputs[4].setVisible(_eqa == 2);
switch(_coor) { switch(_coor) {
case 0 : case 0 :
switch(_eqa) { switch(_eqa) {
case 0 : case 0 :
inputs[ 3].name = "f(x) = "; inputs[ 3].name = "f(x) = ";
inputs[4].setVisible(false);
inputs[ 6].name = "x range"; inputs[ 6].name = "x range";
inputs[10].name = "w(x) = ";
break; break;
case 1 : case 1 :
inputs[ 3].name = "f(y) = "; inputs[ 3].name = "f(y) = ";
inputs[4].setVisible(false);
inputs[ 6].name = "y range"; inputs[ 6].name = "y range";
inputs[10].name = "w(y) = ";
break; break;
case 2 : case 2 :
inputs[ 3].name = "x(t) = "; inputs[ 3].name = "x(t) = ";
inputs[ 4].name = "y(t) = "; inputs[ 4].name = "y(t) = ";
inputs[4].setVisible(true);
inputs[ 6].name = "t range"; inputs[ 6].name = "t range";
inputs[10].name = "w(t) = ";
break; break;
} }
break; break;
case 1 : case 1 :
switch(_eqa) { switch(_eqa) {
case 0 : case 0 :
inputs[ 3].name = "f(r) = "; inputs[ 3].name = "f(r) = ";
inputs[4].setVisible(false);
inputs[ 6].name = "r range"; inputs[ 6].name = "r range";
inputs[10].name = "w(r) = ";
break; break;
case 1 : case 1 :
inputs[ 3].name = "f(O) = "; inputs[ 3].name = "f(O) = ";
inputs[4].setVisible(false);
inputs[ 6].name = "O range"; inputs[ 6].name = "O range";
inputs[10].name = "w(O) = ";
break; break;
case 2 : case 2 :
inputs[ 3].name = "r(t) = "; inputs[ 3].name = "r(t) = ";
inputs[ 4].name = "O(t) = "; inputs[ 4].name = "O(t) = ";
inputs[4].setVisible(true);
inputs[ 6].name = "t range"; inputs[ 6].name = "t range";
inputs[10].name = "w(t) = ";
break; break;
} }
break; break;
@ -173,6 +243,23 @@ function Node_Path_Plot(_x, _y, _group = noone) : Node(_x, _y, _group) construct
} }
static update = function() { 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(); updateBoundary();
outputs[0].setValue(self); outputs[0].setValue(self);
} }

View file

@ -517,9 +517,7 @@
return v1; return v1;
} }
static toString = function() { static toString = function() { return $"[PCX funcTree] \{ symbol: {symbol}, l: {l}, r: {r}\}"; }
return $"[PCX funcTree] \{ symbol: {symbol}, l: {l}, r: {r}\}";
}
} }
function evaluateFunction(fx, params = {}) { function evaluateFunction(fx, params = {}) {