Pixel-Composer/scripts/node_path_trim/node_path_trim.gml

68 lines
2.1 KiB
Text
Raw Normal View History

2023-02-28 15:43:01 +07:00
function Node_Path_Trim(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
2023-02-14 08:48:33 +07:00
name = "Trim Path";
previewable = false;
w = 96;
inputs[| 0] = nodeValue("Path", self, JUNCTION_CONNECT.input, VALUE_TYPE.pathnode, noone)
.setVisible(true, true);
inputs[| 1] = nodeValue("Range", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 0, 1 ])
.setDisplay(VALUE_DISPLAY.slider_range);
2023-02-14 08:48:33 +07:00
outputs[| 0] = nodeValue("Path", self, JUNCTION_CONNECT.output, VALUE_TYPE.pathnode, self);
2023-03-07 20:29:47 +07:00
static getLineCount = function() {
var _path = getInputData(0);
2023-03-07 20:29:47 +07:00
return struct_has(_path, "getLineCount")? _path.getLineCount() : 1;
}
2023-08-02 19:11:57 +02:00
static getSegmentCount = function(ind = 0) {
var _path = getInputData(0);
2023-08-02 19:11:57 +02:00
return struct_has(_path, "getSegmentCount")? _path.getSegmentCount(ind) : 0;
2023-02-28 15:43:01 +07:00
}
2023-08-02 19:11:57 +02:00
static getLength = function(ind = 0) {
var _path = getInputData(0);
2023-08-02 19:11:57 +02:00
return struct_has(_path, "getLength")? _path.getLength(ind) : 0;
2023-03-19 15:17:39 +07:00
}
2023-08-02 19:11:57 +02:00
static getAccuLength = function(ind = 0) {
var _path = getInputData(0);
2023-08-02 19:11:57 +02:00
return struct_has(_path, "getAccuLength")? _path.getAccuLength(ind) : [];
2023-03-19 15:17:39 +07:00
}
2023-10-29 12:29:10 +07:00
static getPointRatio = function(_rat, ind = 0, out = undefined) {
if(out == undefined) out = new __vec2(); else { out.x = 0; out.y = 0; }
var _path = getInputData(0);
var _rng = getInputData(1);
2023-02-14 08:48:33 +07:00
2023-03-07 20:29:47 +07:00
if(is_array(_path)) {
_path = array_safe_get(_path, ind);
ind = 0;
}
2023-02-14 08:48:33 +07:00
if(!is_struct(_path) || !struct_has(_path, "getPointRatio"))
2023-10-29 12:29:10 +07:00
return out;
2023-02-14 08:48:33 +07:00
_rat = _rng[0] + _rat * (_rng[1] - _rng[0]);
2023-10-29 12:29:10 +07:00
return _path.getPointRatio(_rat, ind, out);
2023-03-19 15:17:39 +07:00
}
2023-10-29 12:29:10 +07:00
static getPointDistance = function(_dist, ind = 0, out = undefined) { return getPointRatio(_dist / getLength(), ind, out); }
2023-02-14 08:48:33 +07:00
2023-08-02 19:11:57 +02:00
static getBoundary = function(ind = 0) {
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 );
}
2023-09-26 19:35:25 +07:00
static update = function() {
2023-02-14 08:48:33 +07:00
outputs[| 0].setValue(self);
}
2023-03-05 13:16:44 +07:00
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
2023-02-14 08:48:33 +07:00
var bbox = drawGetBbox(xx, yy, _s);
2023-02-14 17:40:24 +07:00
draw_sprite_fit(s_node_path_trim, 0, bbox.xc, bbox.yc, bbox.w, bbox.h);
2023-02-14 08:48:33 +07:00
}
}