2023-02-28 09:43:01 +01:00
|
|
|
function Node_Path_Blend(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
|
2023-02-14 02:48:33 +01:00
|
|
|
name = "Blend Path";
|
|
|
|
previewable = false;
|
|
|
|
|
|
|
|
w = 96;
|
2023-08-02 19:11:57 +02:00
|
|
|
length = 0;
|
2023-02-14 02:48:33 +01:00
|
|
|
|
|
|
|
inputs[| 0] = nodeValue("Path 1", self, JUNCTION_CONNECT.input, VALUE_TYPE.pathnode, noone)
|
|
|
|
.setVisible(true, true)
|
|
|
|
.rejectArray();
|
|
|
|
|
|
|
|
inputs[| 1] = nodeValue("Path 2", self, JUNCTION_CONNECT.input, VALUE_TYPE.pathnode, noone)
|
|
|
|
.setVisible(true, true)
|
|
|
|
.rejectArray();
|
|
|
|
|
|
|
|
inputs[| 2] = nodeValue("Ratio", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0)
|
2023-10-02 08:57:44 +02:00
|
|
|
.setDisplay(VALUE_DISPLAY.slider)
|
2023-02-14 02:48:33 +01:00
|
|
|
.rejectArray();
|
|
|
|
|
|
|
|
outputs[| 0] = nodeValue("Path", self, JUNCTION_CONNECT.output, VALUE_TYPE.pathnode, self);
|
|
|
|
|
2023-08-02 19:11:57 +02:00
|
|
|
static getLineCount = function() {
|
2023-10-02 08:57:44 +02:00
|
|
|
var _path = getInputData(0);
|
2023-08-02 19:11:57 +02:00
|
|
|
return struct_has(_path, "getLineCount")? _path.getLineCount() : 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static getSegmentCount = function(ind = 0) {
|
2023-10-02 08:57:44 +02:00
|
|
|
var _path1 = getInputData(0);
|
|
|
|
var _path2 = getInputData(1);
|
|
|
|
var _lerp = getInputData(2);
|
2023-02-28 09:43:01 +01:00
|
|
|
|
|
|
|
var p1 = _path1 != noone && struct_has(_path1, "getSegmentCount");
|
|
|
|
var p2 = _path2 != noone && struct_has(_path2, "getSegmentCount");
|
|
|
|
|
|
|
|
if(!p1 && !p2) return 0;
|
2023-08-02 19:11:57 +02:00
|
|
|
if( p1 && !p2) return _path1.getSegmentCount(ind);
|
|
|
|
if(!p1 && p2) return _path2.getSegmentCount(ind);
|
2023-02-28 09:43:01 +01:00
|
|
|
|
2023-08-02 19:11:57 +02:00
|
|
|
return max(_path1.getSegmentCount(ind), _path2.getSegmentCount(ind));
|
2023-02-28 09:43:01 +01:00
|
|
|
}
|
|
|
|
|
2023-08-02 19:11:57 +02:00
|
|
|
static getLength = function(ind = 0) {
|
2023-10-02 08:57:44 +02:00
|
|
|
var _path1 = getInputData(0);
|
|
|
|
var _path2 = getInputData(1);
|
|
|
|
var _lerp = getInputData(2);
|
2023-02-14 02:48:33 +01:00
|
|
|
|
2023-08-02 19:11:57 +02:00
|
|
|
var p1 = _path1 != noone && struct_has(_path1, "getLength");
|
|
|
|
var p2 = _path2 != noone && struct_has(_path2, "getLength");
|
2023-02-14 02:48:33 +01:00
|
|
|
|
2023-08-02 19:11:57 +02:00
|
|
|
if(!p1 && !p2) return 0;
|
|
|
|
if( p1 && !p2) return _path1.getLength(ind);
|
|
|
|
if(!p1 && p2) return _path2.getLength(ind);
|
2023-02-14 02:48:33 +01:00
|
|
|
|
2023-08-02 19:11:57 +02:00
|
|
|
var _p1 = _path1.getLength(ind);
|
|
|
|
var _p2 = _path2.getLength(ind);
|
2023-02-14 02:48:33 +01:00
|
|
|
|
2023-08-02 19:11:57 +02:00
|
|
|
return lerp(_p1, _p2, _lerp);
|
2023-03-19 09:17:39 +01:00
|
|
|
}
|
|
|
|
|
2023-08-02 19:11:57 +02:00
|
|
|
static getAccuLength = function(ind = 0) {
|
2023-10-02 08:57:44 +02:00
|
|
|
var _path1 = getInputData(0);
|
|
|
|
var _path2 = getInputData(1);
|
|
|
|
var _lerp = getInputData(2);
|
2023-03-19 09:17:39 +01:00
|
|
|
|
2023-08-02 19:11:57 +02:00
|
|
|
var p1 = _path1 != noone && struct_has(_path1, "getAccuLength");
|
|
|
|
var p2 = _path2 != noone && struct_has(_path2, "getAccuLength");
|
2023-03-19 09:17:39 +01:00
|
|
|
|
|
|
|
if(!p1 && !p2) return 0;
|
2023-08-02 19:11:57 +02:00
|
|
|
if( p1 && !p2) return _path1.getAccuLength(ind);
|
|
|
|
if(!p1 && p2) return _path2.getAccuLength(ind);
|
2023-03-19 09:17:39 +01:00
|
|
|
|
2023-08-02 19:11:57 +02:00
|
|
|
var _p1 = _path1.getAccuLength(ind);
|
|
|
|
var _p2 = _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);
|
|
|
|
|
|
|
|
res[i] = lerp(_l1, _l2, _lerp);
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static getPointRatio = function(_rat, ind = 0) {
|
2023-10-02 08:57:44 +02:00
|
|
|
var _path1 = getInputData(0);
|
|
|
|
var _path2 = getInputData(1);
|
|
|
|
var _lerp = getInputData(2);
|
2023-08-02 19:11:57 +02:00
|
|
|
|
|
|
|
var p1 = _path1 != noone && struct_has(_path1, "getPointRatio");
|
|
|
|
var p2 = _path2 != noone && struct_has(_path2, "getPointRatio");
|
|
|
|
|
2023-08-31 16:58:13 +02:00
|
|
|
if(!p1 && !p2) return new __vec2();
|
2023-08-02 19:11:57 +02:00
|
|
|
if( p1 && !p2) return _path1.getPointRatio(_rat, ind);
|
|
|
|
if(!p1 && p2) return _path2.getPointRatio(_rat, ind);
|
|
|
|
|
|
|
|
var _p1 = _path1.getPointRatio(_rat, ind);
|
|
|
|
var _p2 = _path2.getPointRatio(_rat, ind);
|
2023-08-31 16:58:13 +02:00
|
|
|
var _r = new __vec2();
|
2023-08-02 19:11:57 +02:00
|
|
|
|
|
|
|
_r.x = lerp(_p1.x, _p2.x, _lerp);
|
|
|
|
_r.y = lerp(_p1.y, _p2.y, _lerp);
|
|
|
|
|
|
|
|
return _r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static getPointDistance = function(_dist, ind = 0) {
|
|
|
|
return getPointRatio(_dist / getLength(ind), ind);
|
2023-02-14 02:48:33 +01:00
|
|
|
}
|
|
|
|
|
2023-08-02 19:11:57 +02:00
|
|
|
static getBoundary = function(ind = 0) {
|
2023-10-02 08:57:44 +02:00
|
|
|
var _path1 = getInputData(0);
|
|
|
|
var _path2 = getInputData(1);
|
|
|
|
var _lerp = getInputData(2);
|
2023-02-14 02:48:33 +01:00
|
|
|
|
|
|
|
var p1 = _path1 != noone && struct_has(_path1, "getPointRatio");
|
|
|
|
var p2 = _path2 != noone && struct_has(_path2, "getPointRatio");
|
|
|
|
|
2023-03-19 09:17:39 +01:00
|
|
|
if(!p1 && !p2) return new BoundingBox();
|
2023-08-02 19:11:57 +02:00
|
|
|
if( p1 && !p2) return _path1.getBoundary(ind);
|
|
|
|
if(!p1 && p2) return _path2.getBoundary(ind);
|
2023-02-14 02:48:33 +01:00
|
|
|
|
2023-08-02 19:11:57 +02:00
|
|
|
var _p1 = _path1.getBoundary(ind);
|
|
|
|
var _p2 = _path2.getBoundary(ind);
|
2023-02-14 02:48:33 +01:00
|
|
|
|
2023-03-19 09:17:39 +01:00
|
|
|
return _p1.lerpTo(_p2, _lerp);
|
2023-02-14 02:48:33 +01:00
|
|
|
}
|
|
|
|
|
2023-09-26 14:35:25 +02:00
|
|
|
static update = function() {
|
2023-02-14 02:48:33 +01:00
|
|
|
outputs[| 0].setValue(self);
|
|
|
|
}
|
|
|
|
|
2023-03-05 07:16:44 +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);
|
|
|
|
}
|
|
|
|
}
|