Pixel-Composer/scripts/node_path_sample/node_path_sample.gml

79 lines
2.2 KiB
Plaintext
Raw Normal View History

2023-02-28 09:43:01 +01:00
function Node_Path_Sample(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
2024-01-22 14:23:35 +01:00
name = "Sample Path";
batch_output = false;
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_Float("Ratio", self, 0);
2023-02-14 02:48:33 +01:00
2024-08-08 06:57:51 +02:00
inputs[2] = nodeValue_Enum_Scroll("Type", self, 0, [ "Loop", "Ping pong" ]);
2023-04-16 11:53:46 +02:00
2024-08-08 06:57:51 +02:00
outputs[0] = nodeValue_Output("Position", self, VALUE_TYPE.float, [ 0, 0 ])
2023-02-14 02:48:33 +01:00
.setDisplay(VALUE_DISPLAY.vector);
2024-08-08 06:57:51 +02:00
outputs[1] = nodeValue_Output("Direction", self, VALUE_TYPE.float, 0);
2023-04-16 15:26:52 +02:00
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
2024-08-08 06:57:51 +02:00
var _pnt = outputs[0].getValue();
2024-01-22 14:23:35 +01:00
if(process_amount == 1) _pnt = [ _pnt ];
draw_set_color(COLORS._main_accent);
for( var i = 0, n = array_length(_pnt); i < n; i++ ) {
var _p = _pnt[i];
var _px = _x + _p[0] * _s;
var _py = _y + _p[1] * _s;
draw_circle(_px, _py, 4, false);
}
} #endregion
static processData = function(_output, _data, _output_index, _array_index = 0) { #region
2023-02-14 02:48:33 +01:00
var _path = _data[0];
var _rat = _data[1];
2023-04-16 11:53:46 +02:00
var _mod = _data[2];
2023-10-28 04:07:43 +02:00
if(_path == noone) return [ 0, 0 ];
if(!struct_has(_path, "getPointRatio")) return [ 0, 0 ];
if(!is_real(_rat)) return [ 0, 0 ];
2023-04-16 15:26:52 +02:00
var inv = false;
2023-04-16 11:53:46 +02:00
switch(_mod) {
2023-04-16 15:26:52 +02:00
case 0 :
_rat = frac(_rat);
break;
2023-04-16 11:53:46 +02:00
case 1 :
var fl = floor(_rat);
var fr = frac(_rat);
2023-04-16 15:26:52 +02:00
if(fl % 2 == 1 && fr != 0) {
2023-04-16 11:53:46 +02:00
fr = 1 - fr;
2023-04-16 15:26:52 +02:00
inv = true;
}
2023-04-16 11:53:46 +02:00
_rat = fr;
break;
}
2023-04-16 15:26:52 +02:00
if(_output_index == 0)
return _path.getPointRatio(_rat).toArray();
else if(_output_index == 1) {
var r0 = clamp(_rat - 0.0001, 0, 1);
var r1 = clamp(_rat + 0.0001, 0, 1);
var p0 = _path.getPointRatio(r0);
var p1 = _path.getPointRatio(r1);
var dir = inv? p1.directionTo(p0) : p0.directionTo(p1);
return dir;
}
2024-01-22 14:23:35 +01:00
} #endregion
2023-02-14 02:48:33 +01:00
2024-01-22 14:23:35 +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);
draw_sprite_fit(THEME.node_draw_path, 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
}