2023-02-28 09:43:01 +01:00
|
|
|
function Node_Path_Blend(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
|
2024-01-22 14:23:35 +01:00
|
|
|
name = "Blend Path";
|
2025-01-01 02:12:36 +01:00
|
|
|
setDimension(96, 48);
|
2023-08-02 19:11:57 +02:00
|
|
|
length = 0;
|
2023-02-14 02:48:33 +01:00
|
|
|
|
2024-08-18 09:13:41 +02:00
|
|
|
newInput(0, nodeValue_PathNode("Path 1", self, noone))
|
2023-02-14 02:48:33 +01:00
|
|
|
.setVisible(true, true)
|
|
|
|
.rejectArray();
|
|
|
|
|
2024-08-18 09:13:41 +02:00
|
|
|
newInput(1, nodeValue_PathNode("Path 2", self, noone))
|
2023-02-14 02:48:33 +01:00
|
|
|
.setVisible(true, true)
|
|
|
|
.rejectArray();
|
|
|
|
|
2024-08-18 09:13:41 +02:00
|
|
|
newInput(2, nodeValue_Float("Ratio", self, 0))
|
2023-10-02 08:57:44 +02:00
|
|
|
.setDisplay(VALUE_DISPLAY.slider)
|
2023-02-14 02:48:33 +01:00
|
|
|
.rejectArray();
|
|
|
|
|
2024-09-04 03:57:11 +02:00
|
|
|
newOutput(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();
|
|
|
|
|
2025-01-16 04:39:54 +01:00
|
|
|
curr_path1 = noone;
|
|
|
|
curr_path2 = noone;
|
|
|
|
curr_lerp = noone;
|
|
|
|
|
|
|
|
is_path1 = false;
|
|
|
|
is_path2 = false;
|
|
|
|
|
2025-01-15 07:55:00 +01:00
|
|
|
static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
|
2024-01-22 14:23:35 +01:00
|
|
|
|
2025-01-16 04:39:54 +01:00
|
|
|
if(is_path1 && struct_has(curr_path1, "drawOverlay")) curr_path1.drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
|
|
|
|
if(is_path2 && struct_has(curr_path2, "drawOverlay")) curr_path2.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;
|
2025-01-15 07:55:00 +01:00
|
|
|
var _p = new __vec2P();
|
2024-01-22 14:23:35 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2025-01-15 07:55:00 +01:00
|
|
|
}
|
2024-01-22 14:23:35 +01:00
|
|
|
|
2025-01-16 04:39:54 +01:00
|
|
|
static getLineCount = function() { return is_path1? curr_path1.getLineCount() : 1; }
|
2023-08-02 19:11:57 +02:00
|
|
|
|
2025-01-15 07:55:00 +01:00
|
|
|
static getSegmentCount = function(ind = 0) {
|
2023-02-28 09:43:01 +01:00
|
|
|
|
2025-01-16 04:39:54 +01:00
|
|
|
if(!is_path1 && !is_path2) return 0;
|
|
|
|
if( is_path1 && !is_path2) return curr_path1.getSegmentCount(ind);
|
|
|
|
if(!is_path1 && is_path2) return curr_path2.getSegmentCount(ind);
|
2023-02-28 09:43:01 +01:00
|
|
|
|
2025-01-16 04:39:54 +01:00
|
|
|
return max(curr_path1.getSegmentCount(ind), curr_path2.getSegmentCount(ind));
|
2025-01-15 07:55:00 +01:00
|
|
|
}
|
2023-02-28 09:43:01 +01:00
|
|
|
|
2025-01-15 07:55:00 +01:00
|
|
|
static getLength = function(ind = 0) {
|
2023-02-14 02:48:33 +01:00
|
|
|
|
2025-01-16 04:39:54 +01:00
|
|
|
if(!is_path1 && !is_path2) return 0;
|
|
|
|
if( is_path1 && !is_path2) return curr_path1.getLength(ind);
|
|
|
|
if(!is_path1 && is_path2) return curr_path2.getLength(ind);
|
2023-02-14 02:48:33 +01:00
|
|
|
|
2025-01-16 04:39:54 +01:00
|
|
|
var _p1 = curr_path1.getLength(ind);
|
|
|
|
var _p2 = curr_path2.getLength(ind);
|
2023-02-14 02:48:33 +01:00
|
|
|
|
2025-01-16 04:39:54 +01:00
|
|
|
return lerp(_p1, _p2, curr_lerp);
|
2025-01-15 07:55:00 +01:00
|
|
|
}
|
2023-03-19 09:17:39 +01:00
|
|
|
|
2025-01-15 07:55:00 +01:00
|
|
|
static getAccuLength = function(ind = 0) {
|
2023-03-19 09:17:39 +01:00
|
|
|
|
2025-01-16 04:39:54 +01:00
|
|
|
if(!is_path1 && !is_path2) return 0;
|
|
|
|
if( is_path1 && !is_path2) return curr_path1.getAccuLength(ind);
|
|
|
|
if(!is_path1 && is_path2) return curr_path2.getAccuLength(ind);
|
2023-03-19 09:17:39 +01:00
|
|
|
|
2025-01-16 04:39:54 +01:00
|
|
|
var _p1 = curr_path1.getAccuLength(ind);
|
|
|
|
var _p2 = curr_path2.getAccuLength(ind);
|
2023-03-19 09:17:39 +01:00
|
|
|
|
2023-08-02 19:11:57 +02:00
|
|
|
var len = max(array_length(_p1), array_length(_p2));
|
|
|
|
var res = [];
|
|
|
|
|
|
|
|
for( var i = 0; i < len; i++ ) {
|
|
|
|
var _l1 = array_get_decimal(_p1, i);
|
|
|
|
var _l2 = array_get_decimal(_p2, i);
|
|
|
|
|
2025-01-16 04:39:54 +01:00
|
|
|
res[i] = lerp(_l1, _l2, curr_lerp);
|
2023-08-02 19:11:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
2025-01-15 07:55:00 +01:00
|
|
|
}
|
2023-08-02 19:11:57 +02:00
|
|
|
|
2025-01-15 07:55:00 +01:00
|
|
|
static getPointRatio = function(_rat, ind = 0, out = undefined) {
|
|
|
|
if(out == undefined) out = new __vec2P(); else { out.x = 0; out.y = 0; }
|
2023-10-29 06:29:10 +01:00
|
|
|
|
2024-12-28 07:29:49 +01:00
|
|
|
var _cKey = $"{string_format(_rat, 0, 6)},{ind}";
|
2024-01-23 07:51:28 +01:00
|
|
|
if(ds_map_exists(cached_pos, _cKey)) {
|
|
|
|
var _p = cached_pos[? _cKey];
|
|
|
|
out.x = _p.x;
|
|
|
|
out.y = _p.y;
|
2025-01-15 07:55:00 +01:00
|
|
|
out.weight = _p.weight;
|
2024-01-23 07:51:28 +01:00
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2025-01-16 04:39:54 +01:00
|
|
|
if(!is_path1 && !is_path2) return out;
|
|
|
|
if( is_path1 && !is_path2) return curr_path1.getPointRatio(_rat, ind, out);
|
|
|
|
if(!is_path1 && is_path2) return curr_path2.getPointRatio(_rat, ind, out);
|
2023-08-02 19:11:57 +02:00
|
|
|
|
2025-01-16 04:39:54 +01:00
|
|
|
var _p1 = curr_path1.getPointRatio(_rat, ind);
|
|
|
|
var _p2 = curr_path2.getPointRatio(_rat, ind);
|
2023-08-02 19:11:57 +02:00
|
|
|
|
2025-01-16 04:39:54 +01:00
|
|
|
out.x = lerp(_p1.x, _p2.x, curr_lerp);
|
|
|
|
out.y = lerp(_p1.y, _p2.y, curr_lerp);
|
|
|
|
out.weight = lerp(_p1.weight, _p2.weight, curr_lerp);
|
2023-08-02 19:11:57 +02:00
|
|
|
|
2025-01-15 07:55:00 +01:00
|
|
|
cached_pos[? _cKey] = new __vec2P(out.x, out.y, out.weight);
|
2024-01-23 07:51:28 +01:00
|
|
|
|
2023-10-29 06:29:10 +01:00
|
|
|
return out;
|
2025-01-15 07:55:00 +01:00
|
|
|
}
|
2023-08-02 19:11:57 +02:00
|
|
|
|
2023-10-29 06:29:10 +01:00
|
|
|
static getPointDistance = function(_dist, ind = 0, out = undefined) { return getPointRatio(_dist / getLength(ind), ind, out); }
|
2023-02-14 02:48:33 +01:00
|
|
|
|
2025-01-15 07:55:00 +01:00
|
|
|
static getBoundary = function(ind = 0) {
|
2023-02-14 02:48:33 +01:00
|
|
|
|
2025-01-16 04:39:54 +01:00
|
|
|
if(!is_path1 && !is_path2) return new BoundingBox();
|
|
|
|
if( is_path1 && !is_path2) return curr_path1.getBoundary(ind);
|
|
|
|
if(!is_path1 && is_path2) return curr_path2.getBoundary(ind);
|
2023-02-14 02:48:33 +01:00
|
|
|
|
2025-01-16 04:39:54 +01:00
|
|
|
var _p1 = curr_path1.getBoundary(ind);
|
|
|
|
var _p2 = curr_path2.getBoundary(ind);
|
2023-02-14 02:48:33 +01:00
|
|
|
|
2025-01-16 04:39:54 +01:00
|
|
|
return _p1.lerpTo(_p2, curr_lerp);
|
2025-01-15 07:55:00 +01:00
|
|
|
}
|
2023-02-14 02:48:33 +01:00
|
|
|
|
2025-01-15 07:55:00 +01:00
|
|
|
static update = function() {
|
2025-01-16 04:39:54 +01:00
|
|
|
curr_path1 = getInputData(0);
|
|
|
|
curr_path2 = getInputData(1);
|
|
|
|
curr_lerp = getInputData(2);
|
|
|
|
|
|
|
|
is_path1 = curr_path1 != noone && struct_has(curr_path1, "getPointRatio");
|
|
|
|
is_path2 = curr_path2 != noone && struct_has(curr_path2, "getPointRatio");
|
|
|
|
|
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);
|
2025-01-15 07:55:00 +01:00
|
|
|
}
|
2023-02-14 02:48:33 +01:00
|
|
|
|
2025-01-15 07:55:00 +01:00
|
|
|
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
|
2023-02-14 02:48:33 +01:00
|
|
|
var bbox = drawGetBbox(xx, yy, _s);
|
|
|
|
draw_sprite_fit(s_node_path_blend, 0, bbox.xc, bbox.yc, bbox.w, bbox.h);
|
2025-01-15 07:55:00 +01:00
|
|
|
}
|
2023-02-14 02:48:33 +01:00
|
|
|
}
|