mirror of
https://github.com/Ttanasart-pt/Pixel-Composer.git
synced 2024-12-24 14:06:23 +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);
|
||||
|
||||
input_display_list = [ 1, 0 ];
|
||||
|
||||
static createNewInput = function() {
|
||||
var index = ds_list_size(inputs);
|
||||
|
||||
inputs[| index] = nodeValue("Value", self, JUNCTION_CONNECT.input, VALUE_TYPE.any, -1 )
|
||||
.setVisible(true, true);
|
||||
|
||||
array_push(input_display_list, index);
|
||||
|
||||
return inputs[| index];
|
||||
} setDynamicInput(1);
|
||||
}
|
||||
|
||||
setDynamicInput(1);
|
||||
|
||||
static update = function(frame = CURRENT_FRAME) {
|
||||
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);
|
||||
inputs[| i].setType(_type);
|
||||
|
||||
if(is_array(_val) && spd)
|
||||
array_append(_out, _val);
|
||||
else
|
||||
array_push(_out, _val);
|
||||
if(is_array(_val) && spd) array_append(_out, _val);
|
||||
else array_push(_out, _val);
|
||||
}
|
||||
|
||||
outputs[| 0].setValue(_out);
|
||||
|
|
|
@ -4,6 +4,7 @@ function Node_Path_Builder(_x, _y, _group = noone) : Node(_x, _y, _group) constr
|
|||
|
||||
#region ---- path ----
|
||||
path_loop = false;
|
||||
path_amount = 0;
|
||||
anchors = [];
|
||||
segments = [];
|
||||
lengths = [];
|
||||
|
@ -26,102 +27,92 @@ function Node_Path_Builder(_x, _y, _group = noone) : Node(_x, _y, _group) constr
|
|||
|
||||
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);
|
||||
|
||||
if(!array_empty(anchors)) {
|
||||
draw_set_color(COLORS._main_accent);
|
||||
|
||||
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;
|
||||
|
||||
for( var j = 0, m = array_length(_seg); j < m; j += 2 ) {
|
||||
_nx = _x + _seg[j + 0] * _s;
|
||||
_ny = _y + _seg[j + 1] * _s;
|
||||
|
||||
if(j) draw_line_width(_ox, _oy, _nx, _ny, 1);
|
||||
|
||||
_ox = _nx;
|
||||
_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)
|
||||
inputs[| 0].drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
|
||||
} #endregion
|
||||
|
||||
static updateLength = function() { #region
|
||||
boundary = new BoundingBox();
|
||||
segments = [];
|
||||
lengths = [];
|
||||
lengthAccs = [];
|
||||
lengthTotal = 0;
|
||||
|
||||
var _index = 0;
|
||||
var sample = PREFERENCES.path_resolution;
|
||||
var ansize = array_length(anchors);
|
||||
if(ansize < 2) return;
|
||||
|
||||
var con = path_loop? ansize : ansize - 1;
|
||||
|
||||
for(var i = 0; i < con; i++) {
|
||||
var _a0 = anchors[(i + 0) % ansize];
|
||||
var _a1 = anchors[(i + 1) % ansize];
|
||||
|
||||
var l = 0, _ox = 0, _oy = 0, _nx = 0, _ny = 0, p = 0;
|
||||
var sg = array_create((sample + 1) * 2);
|
||||
|
||||
for(var j = 0; j <= sample; j++) {
|
||||
for(var p = 0; p < path_amount; p++)
|
||||
for( var i = 0, n = array_length(segments[p]); i < n; i++ ) {
|
||||
var _seg = segments[p][i];
|
||||
var _ox = 0, _oy = 0, _nx = 0, _ny = 0, p = 0;
|
||||
|
||||
if(_a0[4] == 0 && _a0[5] == 0 && _a1[2] == 0 && _a1[3] == 0) {
|
||||
_nx = lerp(_a0[0], _a1[0], j / sample);
|
||||
_ny = lerp(_a0[1], _a1[1], j / sample);
|
||||
} else {
|
||||
_nx = eval_bezier_x(j / sample, _a0[0], _a0[1], _a1[0], _a1[1], _a0[0] + _a0[4], _a0[1] + _a0[5], _a1[0] + _a1[2], _a1[1] + _a1[3]);
|
||||
_ny = eval_bezier_y(j / sample, _a0[0], _a0[1], _a1[0], _a1[1], _a0[0] + _a0[4], _a0[1] + _a0[5], _a1[0] + _a1[2], _a1[1] + _a1[3]);
|
||||
}
|
||||
|
||||
sg[j * 2 + 0] = _nx;
|
||||
sg[j * 2 + 1] = _ny;
|
||||
|
||||
boundary.addPoint(_nx, _ny);
|
||||
if(j) l += point_distance(_nx, _ny, _ox, _oy);
|
||||
for( var j = 0, m = array_length(_seg); j < m; j += 2 ) {
|
||||
_nx = _x + _seg[j + 0] * _s;
|
||||
_ny = _y + _seg[j + 1] * _s;
|
||||
|
||||
if(j) draw_line_width(_ox, _oy, _nx, _ny, 1);
|
||||
|
||||
_ox = _nx;
|
||||
_oy = _ny;
|
||||
}
|
||||
|
||||
segments[i] = sg;
|
||||
lengths[i] = l;
|
||||
lengthTotal += l;
|
||||
lengthAccs[i] = lengthTotal;
|
||||
}
|
||||
} #endregion
|
||||
}
|
||||
|
||||
static getLineCount = function() { return 1; }
|
||||
static getSegmentCount = function() { return array_length(lengths); }
|
||||
static getBoundary = function() { return boundary; }
|
||||
|
||||
static getLength = function() { return lengthTotal; }
|
||||
static getAccuLength = function() { return lengthAccs; }
|
||||
|
||||
static getPointDistance = function(_dist, _ind = 0, out = undefined) { #region
|
||||
if(out == undefined) out = new __vec2(); else { out.x = 0; out.y = 0; }
|
||||
if(array_empty(lengths)) return out;
|
||||
static updateLength = function() {
|
||||
boundary = array_create(path_amount);
|
||||
segments = array_create(path_amount);
|
||||
lengths = array_create(path_amount);
|
||||
lengthAccs = array_create(path_amount);
|
||||
lengthTotal = array_create(path_amount);
|
||||
|
||||
var _cKey = _dist;
|
||||
var sample = PREFERENCES.path_resolution;
|
||||
|
||||
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 _bb = new BoundingBox();
|
||||
|
||||
for(var i = 0; i < con; i++) {
|
||||
var _a0 = _anchor[(i + 0) % ansize];
|
||||
var _a1 = _anchor[(i + 1) % ansize];
|
||||
|
||||
var l = 0, _ox = 0, _oy = 0, _nx = 0, _ny = 0, p = 0;
|
||||
var sg = array_create((sample + 1) * 2);
|
||||
|
||||
for(var j = 0; j <= sample; j++) {
|
||||
|
||||
if(_a0[4] == 0 && _a0[5] == 0 && _a1[2] == 0 && _a1[3] == 0) {
|
||||
_nx = lerp(_a0[0], _a1[0], j / sample);
|
||||
_ny = lerp(_a0[1], _a1[1], j / sample);
|
||||
} else {
|
||||
_nx = eval_bezier_x(j / sample, _a0[0], _a0[1], _a1[0], _a1[1], _a0[0] + _a0[4], _a0[1] + _a0[5], _a1[0] + _a1[2], _a1[1] + _a1[3]);
|
||||
_ny = eval_bezier_y(j / sample, _a0[0], _a0[1], _a1[0], _a1[1], _a0[0] + _a0[4], _a0[1] + _a0[5], _a1[0] + _a1[2], _a1[1] + _a1[3]);
|
||||
}
|
||||
|
||||
sg[j * 2 + 0] = _nx;
|
||||
sg[j * 2 + 1] = _ny;
|
||||
|
||||
_bb.addPoint(_nx, _ny);
|
||||
if(j) l += point_distance(_nx, _ny, _ox, _oy);
|
||||
|
||||
_ox = _nx;
|
||||
_oy = _ny;
|
||||
}
|
||||
|
||||
boundary[p] = _bb;
|
||||
segments[p][i] = sg;
|
||||
lengths[p][i] = l;
|
||||
lengthTotal[p] += l;
|
||||
lengthAccs[p][i] = lengthTotal;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static getLineCount = function() { return path_amount; }
|
||||
static getSegmentCount = function(ind = 0) { return array_length(lengths[ind]); }
|
||||
static getBoundary = function(ind = 0) { return boundary[ind]; }
|
||||
|
||||
static getLength = function(ind = 0) { return lengthTotal[ind]; }
|
||||
static getAccuLength = function(ind = 0) { return lengthAccs[ind]; }
|
||||
|
||||
static getPointDistance = function(_dist, ind = 0, out = undefined) {
|
||||
if(out == undefined) out = new __vec2(); else { out.x = 0; out.y = 0; }
|
||||
|
||||
var _cKey = $"{ind}, {_dist}";
|
||||
if(ds_map_exists(cached_pos, _cKey)) {
|
||||
var _p = cached_pos[? _cKey];
|
||||
out.x = _p.x;
|
||||
|
@ -129,24 +120,25 @@ function Node_Path_Builder(_x, _y, _group = noone) : Node(_x, _y, _group) constr
|
|||
return out;
|
||||
}
|
||||
|
||||
var loop = getInputData(1);
|
||||
if(loop) _dist = safe_mod(_dist, lengthTotal, MOD_NEG.wrap);
|
||||
if(path_loop) _dist = safe_mod(_dist, lengthTotal[ind], 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;
|
||||
|
||||
var _a0, _a1;
|
||||
var _len = lengths[ind];
|
||||
|
||||
for(var i = 0; i < ansize; i++) {
|
||||
_a0 = anchors[(i + 0) % ansize];
|
||||
_a1 = anchors[(i + 1) % ansize];
|
||||
_a0 = _anchor[(i + 0) % ansize];
|
||||
_a1 = _anchor[(i + 1) % ansize];
|
||||
|
||||
if(_dist > lengths[i]) {
|
||||
_dist -= lengths[i];
|
||||
if(_dist > _len[i]) {
|
||||
_dist -= _len[i];
|
||||
continue;
|
||||
}
|
||||
|
||||
var _t = _dist / lengths[i];
|
||||
var _t = _dist / _len[i];
|
||||
|
||||
if(_a0[4] == 0 && _a0[5] == 0 && _a1[2] == 0 && _a1[3] == 0) {
|
||||
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;
|
||||
} #endregion
|
||||
}
|
||||
|
||||
static getPointRatio = function(_rat, _ind = 0, out = undefined) { #region
|
||||
var pix = (path_loop? frac(_rat) : clamp(_rat, 0, 0.99)) * lengthTotal;
|
||||
return getPointDistance(pix, _ind, out);
|
||||
} #endregion
|
||||
static getPointRatio = function(_rat, ind = 0, out = undefined) {
|
||||
var pix = (path_loop? frac(_rat) : clamp(_rat, 0, 0.99)) * lengthTotal[ind];
|
||||
return getPointDistance(pix, ind, out);
|
||||
}
|
||||
|
||||
static update = function() { #region
|
||||
static update = function() {
|
||||
ds_map_clear(cached_pos);
|
||||
|
||||
var _anc = getInputData(0);
|
||||
path_loop = getInputData(1);
|
||||
var _anc = getInputData(0);
|
||||
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 _a = _anc[i];
|
||||
var _d = array_get_depth(_anc);
|
||||
if(_d < 2 || _d > 3) return;
|
||||
else if(_d == 2) _anc = [ _anc ];
|
||||
|
||||
path_amount = array_length(_anc);
|
||||
anchors = array_create(path_amount);
|
||||
|
||||
for (var i = 0, n = path_amount; i < n; i++) {
|
||||
var _anchors = _anc[i];
|
||||
|
||||
for(var j = 0; j < 7; j++)
|
||||
anchors[i][j] = array_safe_get(_a, j, 0);
|
||||
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();
|
||||
|
||||
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);
|
||||
draw_sprite_fit(s_node_path_builder, 0, bbox.xc, bbox.yc, bbox.w, bbox.h);
|
||||
} #endregion
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue