2023-02-28 09:43:01 +01:00
|
|
|
function Node_Path_Trim(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
|
2024-01-22 14:23:35 +01:00
|
|
|
name = "Trim Path";
|
2024-05-02 12:13:35 +02:00
|
|
|
setDimension(96, 48);;
|
2023-02-14 02:48:33 +01:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
inputs[0] = nodeValue_PathNode("Path", self, noone)
|
2023-02-14 02:48:33 +01:00
|
|
|
.setVisible(true, true);
|
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
inputs[1] = nodeValue_Slider_Range("Range", self, [ 0, 1 ]);
|
2023-02-14 02:48:33 +01:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
outputs[0] = nodeValue_Output("Path", self, VALUE_TYPE.pathnode, self);
|
2023-02-14 02:48:33 +01:00
|
|
|
|
2024-01-23 07:51:28 +01:00
|
|
|
cached_pos = ds_map_create();
|
|
|
|
|
2024-03-14 14:35:19 +01:00
|
|
|
static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) { #region
|
2024-01-22 14:23:35 +01:00
|
|
|
var _path = getInputData(0);
|
2024-03-26 11:48:41 +01:00
|
|
|
if(_path && struct_has(_path, "drawOverlay")) _path.drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
|
2024-01-22 14:23:35 +01:00
|
|
|
|
|
|
|
draw_set_color(COLORS._main_icon);
|
|
|
|
|
|
|
|
var _amo = getLineCount();
|
|
|
|
for( var i = 0; i < _amo; i++ ) {
|
|
|
|
var _len = getLength(_amo);
|
|
|
|
var _stp = 1 / clamp(_len * _s, 1, 64);
|
|
|
|
var ox, oy, nx, ny;
|
|
|
|
var _p = new __vec2();
|
|
|
|
|
|
|
|
for( var j = 0; j < 1; j += _stp ) {
|
|
|
|
_p = getPointRatio(j, i, _p);
|
|
|
|
nx = _x + _p.x * _s;
|
|
|
|
ny = _y + _p.y * _s;
|
|
|
|
|
|
|
|
if(j > 0) draw_line_width(ox, oy, nx, ny, 3);
|
|
|
|
|
|
|
|
ox = nx;
|
|
|
|
oy = ny;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} #endregion
|
|
|
|
|
|
|
|
static getLineCount = function() { #region
|
2023-10-02 08:57:44 +02:00
|
|
|
var _path = getInputData(0);
|
2023-03-07 14:29:47 +01:00
|
|
|
return struct_has(_path, "getLineCount")? _path.getLineCount() : 1;
|
2024-01-22 14:23:35 +01:00
|
|
|
} #endregion
|
2023-03-07 14:29:47 +01:00
|
|
|
|
2024-01-22 14:23:35 +01:00
|
|
|
static getSegmentCount = function(ind = 0) { #region
|
2023-10-02 08:57:44 +02:00
|
|
|
var _path = getInputData(0);
|
2023-08-02 19:11:57 +02:00
|
|
|
return struct_has(_path, "getSegmentCount")? _path.getSegmentCount(ind) : 0;
|
2024-01-22 14:23:35 +01:00
|
|
|
} #endregion
|
2023-02-28 09:43:01 +01:00
|
|
|
|
2024-01-22 14:23:35 +01:00
|
|
|
static getLength = function(ind = 0) { #region
|
2023-10-02 08:57:44 +02:00
|
|
|
var _path = getInputData(0);
|
2023-08-02 19:11:57 +02:00
|
|
|
return struct_has(_path, "getLength")? _path.getLength(ind) : 0;
|
2024-01-22 14:23:35 +01:00
|
|
|
} #endregion
|
2023-03-19 09:17:39 +01:00
|
|
|
|
2024-01-22 14:23:35 +01:00
|
|
|
static getAccuLength = function(ind = 0) { #region
|
2023-10-02 08:57:44 +02:00
|
|
|
var _path = getInputData(0);
|
2023-08-02 19:11:57 +02:00
|
|
|
return struct_has(_path, "getAccuLength")? _path.getAccuLength(ind) : [];
|
2024-01-22 14:23:35 +01:00
|
|
|
} #endregion
|
2023-03-19 09:17:39 +01:00
|
|
|
|
2024-01-22 14:23:35 +01:00
|
|
|
static getPointRatio = function(_rat, ind = 0, out = undefined) { #region
|
2023-10-29 06:29:10 +01:00
|
|
|
if(out == undefined) out = new __vec2(); else { out.x = 0; out.y = 0; }
|
|
|
|
|
2023-10-02 08:57:44 +02:00
|
|
|
var _path = getInputData(0);
|
|
|
|
var _rng = getInputData(1);
|
2023-02-14 02:48:33 +01:00
|
|
|
|
2023-03-07 14:29:47 +01:00
|
|
|
if(is_array(_path)) {
|
2024-03-31 05:36:11 +02:00
|
|
|
_path = array_safe_get_fast(_path, ind);
|
2023-03-07 14:29:47 +01:00
|
|
|
ind = 0;
|
|
|
|
}
|
|
|
|
|
2023-02-14 02:48:33 +01:00
|
|
|
if(!is_struct(_path) || !struct_has(_path, "getPointRatio"))
|
2023-10-29 06:29:10 +01:00
|
|
|
return out;
|
2023-02-14 02:48:33 +01:00
|
|
|
|
|
|
|
_rat = _rng[0] + _rat * (_rng[1] - _rng[0]);
|
2024-01-23 07:51:28 +01:00
|
|
|
|
2023-10-29 06:29:10 +01:00
|
|
|
return _path.getPointRatio(_rat, ind, out);
|
2024-01-22 14:23:35 +01:00
|
|
|
} #endregion
|
2023-03-19 09:17:39 +01:00
|
|
|
|
2023-10-29 06:29:10 +01:00
|
|
|
static getPointDistance = function(_dist, ind = 0, out = undefined) { return getPointRatio(_dist / getLength(), ind, out); }
|
2023-02-14 02:48:33 +01:00
|
|
|
|
2024-01-22 14:23:35 +01:00
|
|
|
static getBoundary = function(ind = 0) { #region
|
2023-10-02 08:57:44 +02:00
|
|
|
var _path = getInputData(0);
|
2023-08-02 19:11:57 +02:00
|
|
|
return struct_has(_path, "getBoundary")? _path.getBoundary(ind) : new BoundingBox( 0, 0, 1, 1 );
|
2024-01-22 14:23:35 +01:00
|
|
|
} #endregion
|
2023-08-02 19:11:57 +02:00
|
|
|
|
2024-01-22 14:23:35 +01:00
|
|
|
static update = function() { #region
|
2024-01-23 07:51:28 +01:00
|
|
|
ds_map_clear(cached_pos);
|
2024-08-08 06:57:51 +02:00
|
|
|
outputs[0].setValue(self);
|
2024-01-22 14:23:35 +01:00
|
|
|
} #endregion
|
2023-02-14 02:48:33 +01:00
|
|
|
|
2024-01-23 07:51:28 +01:00
|
|
|
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) { #region
|
2023-02-14 02:48:33 +01:00
|
|
|
var bbox = drawGetBbox(xx, yy, _s);
|
2023-02-14 11:40:24 +01:00
|
|
|
draw_sprite_fit(s_node_path_trim, 0, bbox.xc, bbox.yc, bbox.w, bbox.h);
|
2024-01-22 14:23:35 +01:00
|
|
|
} #endregion
|
2023-02-14 02:48:33 +01:00
|
|
|
}
|