mirror of
https://github.com/Ttanasart-pt/Pixel-Composer.git
synced 2024-12-25 14:36:13 +01:00
- [Path Builder] Now support path array. - [Path Builder] Fix error when inputing invalid point arrays.
This commit is contained in:
parent
aa268c6771
commit
a69b16d2c4
2 changed files with 123 additions and 115 deletions
|
@ -10,14 +10,20 @@ function Node_Array_Add(_x, _y, _group = noone) : Node(_x, _y, _group) construct
|
||||||
|
|
||||||
outputs[| 0] = nodeValue("Output", self, JUNCTION_CONNECT.output, VALUE_TYPE.integer, 0);
|
outputs[| 0] = nodeValue("Output", self, JUNCTION_CONNECT.output, VALUE_TYPE.integer, 0);
|
||||||
|
|
||||||
|
input_display_list = [ 1, 0 ];
|
||||||
|
|
||||||
static createNewInput = function() {
|
static createNewInput = function() {
|
||||||
var index = ds_list_size(inputs);
|
var index = ds_list_size(inputs);
|
||||||
|
|
||||||
inputs[| index] = nodeValue("Value", self, JUNCTION_CONNECT.input, VALUE_TYPE.any, -1 )
|
inputs[| index] = nodeValue("Value", self, JUNCTION_CONNECT.input, VALUE_TYPE.any, -1 )
|
||||||
.setVisible(true, true);
|
.setVisible(true, true);
|
||||||
|
|
||||||
|
array_push(input_display_list, index);
|
||||||
|
|
||||||
return inputs[| index];
|
return inputs[| index];
|
||||||
} setDynamicInput(1);
|
}
|
||||||
|
|
||||||
|
setDynamicInput(1);
|
||||||
|
|
||||||
static update = function(frame = CURRENT_FRAME) {
|
static update = function(frame = CURRENT_FRAME) {
|
||||||
var _arr = getInputData(0);
|
var _arr = getInputData(0);
|
||||||
|
@ -40,10 +46,8 @@ function Node_Array_Add(_x, _y, _group = noone) : Node(_x, _y, _group) construct
|
||||||
var _val = getInputData(i);
|
var _val = getInputData(i);
|
||||||
inputs[| i].setType(_type);
|
inputs[| i].setType(_type);
|
||||||
|
|
||||||
if(is_array(_val) && spd)
|
if(is_array(_val) && spd) array_append(_out, _val);
|
||||||
array_append(_out, _val);
|
else array_push(_out, _val);
|
||||||
else
|
|
||||||
array_push(_out, _val);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
outputs[| 0].setValue(_out);
|
outputs[| 0].setValue(_out);
|
||||||
|
|
|
@ -4,6 +4,7 @@ function Node_Path_Builder(_x, _y, _group = noone) : Node(_x, _y, _group) constr
|
||||||
|
|
||||||
#region ---- path ----
|
#region ---- path ----
|
||||||
path_loop = false;
|
path_loop = false;
|
||||||
|
path_amount = 0;
|
||||||
anchors = [];
|
anchors = [];
|
||||||
segments = [];
|
segments = [];
|
||||||
lengths = [];
|
lengths = [];
|
||||||
|
@ -26,14 +27,14 @@ function Node_Path_Builder(_x, _y, _group = noone) : Node(_x, _y, _group) constr
|
||||||
|
|
||||||
cached_pos = ds_map_create();
|
cached_pos = ds_map_create();
|
||||||
|
|
||||||
static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) { #region
|
static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
|
||||||
|
if(path_amount == 0) return;
|
||||||
|
|
||||||
draw_set_color(COLORS._main_accent);
|
draw_set_color(COLORS._main_accent);
|
||||||
|
|
||||||
if(!array_empty(anchors)) {
|
for(var p = 0; p < path_amount; p++)
|
||||||
draw_set_color(COLORS._main_accent);
|
for( var i = 0, n = array_length(segments[p]); i < n; i++ ) {
|
||||||
|
var _seg = segments[p][i];
|
||||||
for( var i = 0, n = array_length(segments); i < n; i++ ) { #region draw path
|
|
||||||
var _seg = segments[i];
|
|
||||||
var _ox = 0, _oy = 0, _nx = 0, _ny = 0, p = 0;
|
var _ox = 0, _oy = 0, _nx = 0, _ny = 0, p = 0;
|
||||||
|
|
||||||
for( var j = 0, m = array_length(_seg); j < m; j += 2 ) {
|
for( var j = 0, m = array_length(_seg); j < m; j += 2 ) {
|
||||||
|
@ -45,40 +46,29 @@ function Node_Path_Builder(_x, _y, _group = noone) : Node(_x, _y, _group) constr
|
||||||
_ox = _nx;
|
_ox = _nx;
|
||||||
_oy = _ny;
|
_oy = _ny;
|
||||||
}
|
}
|
||||||
} #endregion
|
|
||||||
|
|
||||||
#region draw anchor
|
|
||||||
for(var i = 0; i < array_length(anchors); i++) {
|
|
||||||
var _a = anchors[i];
|
|
||||||
var xx = _x + _a[0] * _s;
|
|
||||||
var yy = _y + _a[1] * _s;
|
|
||||||
|
|
||||||
draw_sprite_colored(THEME.anchor_selector, 0, xx, yy);
|
|
||||||
}
|
}
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(inputs[| 0].value_from != noone)
|
static updateLength = function() {
|
||||||
inputs[| 0].drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
|
boundary = array_create(path_amount);
|
||||||
} #endregion
|
segments = array_create(path_amount);
|
||||||
|
lengths = array_create(path_amount);
|
||||||
|
lengthAccs = array_create(path_amount);
|
||||||
|
lengthTotal = array_create(path_amount);
|
||||||
|
|
||||||
static updateLength = function() { #region
|
|
||||||
boundary = new BoundingBox();
|
|
||||||
segments = [];
|
|
||||||
lengths = [];
|
|
||||||
lengthAccs = [];
|
|
||||||
lengthTotal = 0;
|
|
||||||
|
|
||||||
var _index = 0;
|
|
||||||
var sample = PREFERENCES.path_resolution;
|
var sample = PREFERENCES.path_resolution;
|
||||||
var ansize = array_length(anchors);
|
|
||||||
if(ansize < 2) return;
|
for(var p = 0; p < path_amount; p++) {
|
||||||
|
var _anchor = anchors[p];
|
||||||
|
var ansize = array_length(_anchor);
|
||||||
|
if(ansize < 2) continue;
|
||||||
|
|
||||||
var con = path_loop? ansize : ansize - 1;
|
var con = path_loop? ansize : ansize - 1;
|
||||||
|
var _bb = new BoundingBox();
|
||||||
|
|
||||||
for(var i = 0; i < con; i++) {
|
for(var i = 0; i < con; i++) {
|
||||||
var _a0 = anchors[(i + 0) % ansize];
|
var _a0 = _anchor[(i + 0) % ansize];
|
||||||
var _a1 = anchors[(i + 1) % ansize];
|
var _a1 = _anchor[(i + 1) % ansize];
|
||||||
|
|
||||||
var l = 0, _ox = 0, _oy = 0, _nx = 0, _ny = 0, p = 0;
|
var l = 0, _ox = 0, _oy = 0, _nx = 0, _ny = 0, p = 0;
|
||||||
var sg = array_create((sample + 1) * 2);
|
var sg = array_create((sample + 1) * 2);
|
||||||
|
@ -96,32 +86,33 @@ function Node_Path_Builder(_x, _y, _group = noone) : Node(_x, _y, _group) constr
|
||||||
sg[j * 2 + 0] = _nx;
|
sg[j * 2 + 0] = _nx;
|
||||||
sg[j * 2 + 1] = _ny;
|
sg[j * 2 + 1] = _ny;
|
||||||
|
|
||||||
boundary.addPoint(_nx, _ny);
|
_bb.addPoint(_nx, _ny);
|
||||||
if(j) l += point_distance(_nx, _ny, _ox, _oy);
|
if(j) l += point_distance(_nx, _ny, _ox, _oy);
|
||||||
|
|
||||||
_ox = _nx;
|
_ox = _nx;
|
||||||
_oy = _ny;
|
_oy = _ny;
|
||||||
}
|
}
|
||||||
|
|
||||||
segments[i] = sg;
|
boundary[p] = _bb;
|
||||||
lengths[i] = l;
|
segments[p][i] = sg;
|
||||||
lengthTotal += l;
|
lengths[p][i] = l;
|
||||||
lengthAccs[i] = lengthTotal;
|
lengthTotal[p] += l;
|
||||||
|
lengthAccs[p][i] = lengthTotal;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} #endregion
|
|
||||||
|
|
||||||
static getLineCount = function() { return 1; }
|
static getLineCount = function() { return path_amount; }
|
||||||
static getSegmentCount = function() { return array_length(lengths); }
|
static getSegmentCount = function(ind = 0) { return array_length(lengths[ind]); }
|
||||||
static getBoundary = function() { return boundary; }
|
static getBoundary = function(ind = 0) { return boundary[ind]; }
|
||||||
|
|
||||||
static getLength = function() { return lengthTotal; }
|
static getLength = function(ind = 0) { return lengthTotal[ind]; }
|
||||||
static getAccuLength = function() { return lengthAccs; }
|
static getAccuLength = function(ind = 0) { return lengthAccs[ind]; }
|
||||||
|
|
||||||
static getPointDistance = function(_dist, _ind = 0, out = undefined) { #region
|
static getPointDistance = function(_dist, ind = 0, out = undefined) {
|
||||||
if(out == undefined) out = new __vec2(); else { out.x = 0; out.y = 0; }
|
if(out == undefined) out = new __vec2(); else { out.x = 0; out.y = 0; }
|
||||||
if(array_empty(lengths)) return out;
|
|
||||||
|
|
||||||
var _cKey = _dist;
|
var _cKey = $"{ind}, {_dist}";
|
||||||
if(ds_map_exists(cached_pos, _cKey)) {
|
if(ds_map_exists(cached_pos, _cKey)) {
|
||||||
var _p = cached_pos[? _cKey];
|
var _p = cached_pos[? _cKey];
|
||||||
out.x = _p.x;
|
out.x = _p.x;
|
||||||
|
@ -129,24 +120,25 @@ function Node_Path_Builder(_x, _y, _group = noone) : Node(_x, _y, _group) constr
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
var loop = getInputData(1);
|
if(path_loop) _dist = safe_mod(_dist, lengthTotal[ind], MOD_NEG.wrap);
|
||||||
if(loop) _dist = safe_mod(_dist, lengthTotal, MOD_NEG.wrap);
|
|
||||||
|
|
||||||
var ansize = ds_list_size(inputs) - input_fix_len;
|
var _anchor = anchors[ind];
|
||||||
|
var ansize = array_length(_anchor);
|
||||||
if(ansize == 0) return out;
|
if(ansize == 0) return out;
|
||||||
|
|
||||||
var _a0, _a1;
|
var _a0, _a1;
|
||||||
|
var _len = lengths[ind];
|
||||||
|
|
||||||
for(var i = 0; i < ansize; i++) {
|
for(var i = 0; i < ansize; i++) {
|
||||||
_a0 = anchors[(i + 0) % ansize];
|
_a0 = _anchor[(i + 0) % ansize];
|
||||||
_a1 = anchors[(i + 1) % ansize];
|
_a1 = _anchor[(i + 1) % ansize];
|
||||||
|
|
||||||
if(_dist > lengths[i]) {
|
if(_dist > _len[i]) {
|
||||||
_dist -= lengths[i];
|
_dist -= _len[i];
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var _t = _dist / lengths[i];
|
var _t = _dist / _len[i];
|
||||||
|
|
||||||
if(_a0[4] == 0 && _a0[5] == 0 && _a1[2] == 0 && _a1[3] == 0) {
|
if(_a0[4] == 0 && _a0[5] == 0 && _a1[2] == 0 && _a1[3] == 0) {
|
||||||
out.x = lerp(_a0[0], _a1[0], _t);
|
out.x = lerp(_a0[0], _a1[0], _t);
|
||||||
|
@ -161,35 +153,47 @@ function Node_Path_Builder(_x, _y, _group = noone) : Node(_x, _y, _group) constr
|
||||||
}
|
}
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
} #endregion
|
}
|
||||||
|
|
||||||
static getPointRatio = function(_rat, _ind = 0, out = undefined) { #region
|
static getPointRatio = function(_rat, ind = 0, out = undefined) {
|
||||||
var pix = (path_loop? frac(_rat) : clamp(_rat, 0, 0.99)) * lengthTotal;
|
var pix = (path_loop? frac(_rat) : clamp(_rat, 0, 0.99)) * lengthTotal[ind];
|
||||||
return getPointDistance(pix, _ind, out);
|
return getPointDistance(pix, ind, out);
|
||||||
} #endregion
|
}
|
||||||
|
|
||||||
static update = function() { #region
|
static update = function() {
|
||||||
ds_map_clear(cached_pos);
|
ds_map_clear(cached_pos);
|
||||||
|
|
||||||
var _anc = getInputData(0);
|
var _anc = getInputData(0);
|
||||||
path_loop = getInputData(1);
|
path_loop = getInputData(1);
|
||||||
|
path_amount = 0;
|
||||||
|
|
||||||
anchors = array_create(array_length(_anc));
|
if(!is_array(_anc)) return;
|
||||||
|
|
||||||
for (var i = 0, n = array_length(_anc); i < n; i++) {
|
var _d = array_get_depth(_anc);
|
||||||
var _a = _anc[i];
|
if(_d < 2 || _d > 3) return;
|
||||||
|
else if(_d == 2) _anc = [ _anc ];
|
||||||
|
|
||||||
for(var j = 0; j < 7; j++)
|
path_amount = array_length(_anc);
|
||||||
anchors[i][j] = array_safe_get(_a, j, 0);
|
anchors = array_create(path_amount);
|
||||||
|
|
||||||
|
for (var i = 0, n = path_amount; i < n; i++) {
|
||||||
|
var _anchors = _anc[i];
|
||||||
|
|
||||||
|
for (var j = 0, m = array_length(_anchors); j < m; j++) {
|
||||||
|
var _a = _anchors[j];
|
||||||
|
|
||||||
|
for (var k = 0; k < 7; k++)
|
||||||
|
anchors[i][j][k] = array_safe_get(_a, k, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateLength();
|
updateLength();
|
||||||
|
|
||||||
outputs[| 0].setValue(self);
|
outputs[| 0].setValue(self);
|
||||||
} #endregion
|
}
|
||||||
|
|
||||||
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) { #region
|
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
|
||||||
var bbox = drawGetBbox(xx, yy, _s);
|
var bbox = drawGetBbox(xx, yy, _s);
|
||||||
draw_sprite_fit(s_node_path_builder, 0, bbox.xc, bbox.yc, bbox.w, bbox.h);
|
draw_sprite_fit(s_node_path_builder, 0, bbox.xc, bbox.yc, bbox.w, bbox.h);
|
||||||
} #endregion
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue