2024-01-23 07:51:28 +01:00
|
|
|
function Node_Path_Bake(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
|
|
|
|
name = "Bake Path";
|
2024-07-16 04:29:46 +02:00
|
|
|
setDimension(96, 48);
|
2024-01-23 07:51:28 +01:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
inputs[0] = nodeValue_PathNode("Path", self, noone)
|
2024-01-23 07:51:28 +01:00
|
|
|
.setVisible(true, true);
|
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(1, nodeValue_Float("Segment length", self, 1));
|
2024-01-23 07:51:28 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(2, nodeValue_Bool("Spread single path", self, true));
|
2024-07-16 04:29:46 +02:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
outputs[0] = nodeValue_Output("Segments", self, VALUE_TYPE.float, [[]])
|
2024-01-23 07:51:28 +01:00
|
|
|
.setDisplay(VALUE_DISPLAY.vector)
|
2024-07-16 05:08:51 +02:00
|
|
|
.setArrayDepth(2);
|
2024-01-23 07:51:28 +01:00
|
|
|
|
2024-06-21 03:52:35 +02:00
|
|
|
path_amount = 1;
|
|
|
|
|
2024-07-10 09:17:14 +02:00
|
|
|
static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
|
2024-01-23 07:51:28 +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-23 07:51:28 +01:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
var _segs = outputs[0].getValue();
|
2024-01-23 07:51:28 +01:00
|
|
|
var ox, oy, nx, ny;
|
|
|
|
|
2024-07-16 04:29:46 +02:00
|
|
|
if(array_invalid(_segs) || array_invalid(_segs[0])) return;
|
|
|
|
if(!is_array(_segs[0][0])) _segs = [ _segs ];
|
|
|
|
|
2024-01-23 07:51:28 +01:00
|
|
|
draw_set_color(COLORS._main_icon);
|
2024-06-21 03:52:35 +02:00
|
|
|
|
2024-01-23 07:51:28 +01:00
|
|
|
for( var i = 0, n = array_length(_segs); i < n; i++ ) {
|
|
|
|
var _seg = _segs[i];
|
|
|
|
|
|
|
|
for( var j = 0, m = array_length(_seg); j < m; j++ ) {
|
|
|
|
nx = _x + _seg[j][0] * _s;
|
|
|
|
ny = _y + _seg[j][1] * _s;
|
|
|
|
|
|
|
|
if(j) draw_line_width(ox, oy, nx, ny, 3);
|
|
|
|
|
|
|
|
ox = nx;
|
|
|
|
oy = ny;
|
|
|
|
}
|
|
|
|
}
|
2024-07-10 09:17:14 +02:00
|
|
|
}
|
2024-01-23 07:51:28 +01:00
|
|
|
|
2024-07-10 09:17:14 +02:00
|
|
|
static update = function() {
|
2024-01-23 07:51:28 +01:00
|
|
|
var _path = getInputData(0);
|
|
|
|
var _dist = getInputData(1);
|
2024-07-16 04:29:46 +02:00
|
|
|
var _sped = getInputData(2);
|
2024-01-23 07:51:28 +01:00
|
|
|
|
|
|
|
if(_path == noone) return;
|
|
|
|
if(_dist <= 0) return;
|
|
|
|
|
2024-07-16 05:08:51 +02:00
|
|
|
var _loop = struct_try_get(_path, "path_loop", false);
|
2024-06-21 03:52:35 +02:00
|
|
|
var _amo = _path.getLineCount();
|
|
|
|
path_amount = _amo;
|
|
|
|
var _segs = array_create(_amo);
|
2024-01-23 07:51:28 +01:00
|
|
|
|
|
|
|
var _p = new __vec2();
|
|
|
|
|
|
|
|
for( var i = 0; i < _amo; i++ ) {
|
|
|
|
var _len = _path.getLength(i);
|
|
|
|
var _seg = [];
|
2024-07-16 04:29:46 +02:00
|
|
|
_segs[i] = _seg;
|
|
|
|
|
|
|
|
if(_len == 0) continue;
|
2024-01-23 07:51:28 +01:00
|
|
|
|
|
|
|
for( var j = 0; j <= _len; j += _dist ) {
|
|
|
|
_p = _path.getPointDistance(j, i, _p);
|
2024-07-16 04:29:46 +02:00
|
|
|
array_push(_seg, [ _p.x, _p.y, j / _len ]);
|
2024-01-23 07:51:28 +01:00
|
|
|
}
|
2024-07-16 05:08:51 +02:00
|
|
|
|
|
|
|
if(_loop) array_push(_seg, [ _seg[0][0], _seg[0][1], 1 ]);
|
2024-01-23 07:51:28 +01:00
|
|
|
}
|
|
|
|
|
2024-07-16 04:29:46 +02:00
|
|
|
if(_sped && _amo == 1) _segs = _segs[0];
|
2024-08-08 06:57:51 +02:00
|
|
|
outputs[0].setValue(_segs);
|
2024-07-10 09:17:14 +02:00
|
|
|
}
|
2024-01-23 07:51:28 +01:00
|
|
|
|
2024-07-10 09:17:14 +02:00
|
|
|
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
|
2024-01-23 07:51:28 +01:00
|
|
|
var bbox = drawGetBbox(xx, yy, _s);
|
2024-07-16 05:08:51 +02:00
|
|
|
draw_sprite_bbox_uniform(THEME.node_draw_path, 0, bbox);
|
2024-07-10 09:17:14 +02:00
|
|
|
}
|
2024-01-23 07:51:28 +01:00
|
|
|
}
|