Pixel-Composer/scripts/node_repeat/node_repeat.gml

321 lines
9.8 KiB
Text
Raw Normal View History

global.node_repeat_keys = [ "repeat polar", "repeat circular" ];
function Node_create_Repeat(_x, _y, _group = noone, _param = {}) {
var _node = new Node_Repeat(_x, _y, _group).skipDefault();
var query = struct_try_get(_param, "query", "");
switch(query) {
case "repeat polar" :
case "repeat circular" :
2024-08-08 06:57:51 +02:00
_node.inputs[3].setValue(2);
_node.inputs[9].unit.setMode(VALUE_UNIT.reference);
_node.inputs[9].setValueDirect([ 0.5, 0.5 ]);
break;
}
return _node;
}
2024-04-11 05:51:13 +02:00
function Node_Repeat(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
2023-01-17 08:11:55 +01:00
name = "Repeat";
2024-04-11 05:51:13 +02:00
dimension_index = 1;
2023-01-17 08:11:55 +01:00
2024-08-18 06:16:20 +02:00
newInput(0, nodeValue_Surface("Surface in", self));
2023-01-17 08:11:55 +01:00
2024-08-18 06:16:20 +02:00
newInput(1, nodeValue_Dimension(self));
2023-01-17 08:11:55 +01:00
2024-08-18 09:13:41 +02:00
newInput(2, nodeValue_Int("Amount", self, 2))
2024-04-11 05:51:13 +02:00
.rejectArray();
2023-01-17 08:11:55 +01:00
2024-08-20 10:15:53 +02:00
newInput(3, nodeValue_Enum_Scroll("Pattern", self, 0, [ new scrollItem("Linear", s_node_repeat_axis, 0),
new scrollItem("Grid", s_node_repeat_axis, 1),
new scrollItem("Circular", s_node_repeat_axis, 2), ]));
2023-01-17 08:11:55 +01:00
2024-08-18 09:13:41 +02:00
newInput(4, nodeValue_Vec2("Shift position", self, [ DEF_SURF_W / 2, 0 ]))
2023-01-17 08:11:55 +01:00
.setUnitRef(function() { return getDimension(); });
2024-08-18 06:16:20 +02:00
newInput(5, nodeValue_Rotation_Range("Repeat rotation", self, [0, 0]));
2023-01-17 08:11:55 +01:00
2024-08-18 06:16:20 +02:00
newInput(6, nodeValue_Float("Scale multiply", self, 1));
2023-01-17 08:11:55 +01:00
2024-08-18 06:16:20 +02:00
newInput(7, nodeValue_Rotation_Range("Angle range", self, [0, 360]));
2023-01-17 08:11:55 +01:00
2024-08-18 06:16:20 +02:00
newInput(8, nodeValue_Float("Radius", self, 1));
2023-01-17 08:11:55 +01:00
2024-08-18 09:13:41 +02:00
newInput(9, nodeValue_Vec2("Start position", self, [0, 0]))
.setUnitRef(function(index) { return getInputData(1); });
2023-01-17 08:11:55 +01:00
2024-08-20 10:15:53 +02:00
newInput(10, nodeValue("Scale over copy", self, CONNECT_TYPE.input, VALUE_TYPE.curve, CURVE_DEF_11 ));
2023-01-17 08:11:55 +01:00
2024-08-18 09:13:41 +02:00
newInput(11, nodeValue_PathNode("Path", self, noone, "Make each copy follow along path." ))
2023-01-17 08:11:55 +01:00
.setVisible(true, true);
2024-08-18 09:13:41 +02:00
newInput(12, nodeValue_Slider_Range("Path range", self, [0, 1]))
.setTooltip("Range of the path to follow.");
2023-01-17 08:11:55 +01:00
2024-08-18 06:16:20 +02:00
newInput(13, nodeValue_Float("Path shift", self, 0));
2023-01-17 08:11:55 +01:00
2024-08-18 09:13:41 +02:00
newInput(14, nodeValue_Gradient("Color over copy", self, new gradientObject(cola(c_white))))
2024-01-22 10:46:04 +01:00
.setMappable(30);
2023-01-17 08:11:55 +01:00
2024-08-20 10:15:53 +02:00
newInput(15, nodeValue("Alpha over copy", self, CONNECT_TYPE.input, VALUE_TYPE.curve, CURVE_DEF_11 ));
2023-01-17 08:11:55 +01:00
2024-08-18 09:13:41 +02:00
newInput(16, nodeValue_Enum_Button("Array select", self, 0, [ "Order", "Random", "Spread" ]))
2024-08-07 11:48:39 +02:00
.setTooltip("Whether to select image from an array in order, at random, or spread or each image to one output.");
2023-01-17 08:11:55 +01:00
2024-08-18 09:13:41 +02:00
newInput(17, nodeValue_Int("Seed", self, seed_random(6)))
2024-08-08 06:57:51 +02:00
.setDisplay(VALUE_DISPLAY._default, { side_button : button(function() { randomize(); inputs[17].setValue(seed_random(6)); }).setIcon(THEME.icon_random, 0, COLORS._main_icon) });
2023-01-17 08:11:55 +01:00
2024-08-18 06:16:20 +02:00
newInput(18, nodeValue_Int("Column", self, 4));
2023-01-17 08:11:55 +01:00
2024-08-18 09:13:41 +02:00
newInput(19, nodeValue_Vec2("Column shift", self, [0, DEF_SURF_H / 2]))
2023-01-17 08:11:55 +01:00
.setUnitRef(function() { return getDimension(); });
2024-08-18 09:13:41 +02:00
newInput(20, nodeValue_Float("Animator midpoint", self, 0.5))
.setDisplay(VALUE_DISPLAY.slider, { range: [-1, 2, 0.01] });
2023-01-17 08:11:55 +01:00
2024-08-18 09:13:41 +02:00
newInput(21, nodeValue_Float("Animator range", self, 0.1))
.setDisplay(VALUE_DISPLAY.slider);
2023-01-17 08:11:55 +01:00
2024-08-18 06:16:20 +02:00
newInput(22, nodeValue_Vec2("Animator position", self, [ 0, 0 ]));
2023-01-17 08:11:55 +01:00
2024-08-18 06:16:20 +02:00
newInput(23, nodeValue_Rotation("Animator rotation", self, 0));
2023-01-17 08:11:55 +01:00
2024-08-18 06:16:20 +02:00
newInput(24, nodeValue_Vec2("Animator scale", self, [ 0, 0 ]));
2023-01-17 08:11:55 +01:00
2024-08-20 10:15:53 +02:00
newInput(25, nodeValue("Animator falloff", self, CONNECT_TYPE.input, VALUE_TYPE.curve, CURVE_DEF_10));
2023-01-25 06:49:00 +01:00
2024-08-18 09:13:41 +02:00
newInput(26, nodeValue_Enum_Button("Stack", self, 0, [ "None", "X", "Y" ]))
2024-08-07 11:48:39 +02:00
.setTooltip("Place each copy next to each other, taking surface dimension into account.");
2023-01-17 08:11:55 +01:00
2024-08-18 06:16:20 +02:00
newInput(27, nodeValue_Color("Animator blend", self, cola(c_white)));
2023-01-25 06:49:00 +01:00
2024-08-18 09:13:41 +02:00
newInput(28, nodeValue_Float("Animator alpha", self, 1))
.setDisplay(VALUE_DISPLAY.slider);
2024-01-08 08:10:50 +01:00
2024-08-18 09:13:41 +02:00
newInput(29, nodeValue_Bool("Animator", self, false))
2024-01-08 08:10:50 +01:00
2024-01-22 10:46:04 +01:00
//////////////////////////////////////////////////////////////////////////////////////////////////
2024-08-18 06:16:20 +02:00
newInput(30, nodeValueMap("Gradient map", self));
2024-01-22 10:46:04 +01:00
2024-08-18 06:16:20 +02:00
newInput(31, nodeValueGradientRange("Gradient map range", self, inputs[14]));
2024-01-22 10:46:04 +01:00
//////////////////////////////////////////////////////////////////////////////////////////////////
2024-08-18 06:16:20 +02:00
newInput(32, nodeValue_Rotation("Start rotation", self, 0));
2024-08-18 06:16:20 +02:00
newInput(33, nodeValue_Rotation("Rotation", self, 0));
2024-08-18 06:16:20 +02:00
newInput(34, nodeValue_Enum_Scroll("Blend Mode", self, 0, [ "Normal", "Additive", "Maximum" ]));
2024-08-08 06:57:51 +02:00
outputs[0] = nodeValue_Output("Surface out", self, VALUE_TYPE.surface, noone);
2023-01-17 08:11:55 +01:00
input_display_list = [
["Surfaces", true], 0, 1, 16, 17,
["Pattern", false], 3, 9, 32, 2, 18, 7, 8,
2023-01-17 08:11:55 +01:00
["Path", true], 11, 12, 13,
2024-03-02 10:08:44 +01:00
["Position", false], 4, 26, 19,
["Rotation", false], 33, 5,
2024-03-02 10:08:44 +01:00
["Scale", false], 6, 10,
["Render", false], 34, 14, 30,
2024-01-08 08:10:50 +01:00
["Animator", true, 29], 20, 21, 25, 22, 23, 24, 27,
2023-01-17 08:11:55 +01:00
];
2023-03-19 09:17:39 +01:00
attribute_surface_depth();
attribute_interpolation();
2023-03-19 09:17:39 +01:00
static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
PROCESSOR_OVERLAY_CHECK
2024-07-02 12:18:32 +02:00
var _hov = false;
2024-08-08 06:57:51 +02:00
var hv = inputs[9].drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny); active &= !hv; _hov |= hv;
2023-01-17 08:11:55 +01:00
var _pat = current_data[3];
var _spos = current_data[9];
2023-01-17 08:11:55 +01:00
var px = _x + _spos[0] * _s;
var py = _y + _spos[1] * _s;
2023-02-14 05:32:32 +01:00
2024-08-08 06:57:51 +02:00
if(_pat == 0 || _pat == 1) { var hv = inputs[4].drawOverlay(hover, active, px, py, _s, _mx, _my, _snx, _sny); active &= !hv; _hov |= hv; }
else if(_pat == 2) { var hv = inputs[8].drawOverlay(hover, active, px, py, _s, _mx, _my, _snx, _sny); active &= !hv; _hov |= hv; }
2024-01-22 10:46:04 +01:00
2024-08-08 06:57:51 +02:00
var hv = inputs[31].drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny, current_data[1]); active &= !hv; _hov |= hv;
2024-07-02 12:18:32 +02:00
return _hov;
}
2023-01-17 08:11:55 +01:00
static preGetInputs = function() {
2024-04-11 05:51:13 +02:00
var _arr = getSingleValue(16);
var _pat = getSingleValue(3);
2024-08-08 06:57:51 +02:00
inputs[ 0].setArrayDepth(_arr != 2);
2024-04-11 05:51:13 +02:00
2024-08-08 06:57:51 +02:00
inputs[ 4].setVisible( _pat == 0 || _pat == 1);
inputs[ 7].setVisible( _pat == 2);
inputs[ 8].setVisible( _pat == 2);
inputs[18].setVisible( _pat == 1);
inputs[19].setVisible( _pat == 1);
inputs[26].setVisible( _pat == 0);
inputs[32].setVisible( _pat == 2);
2024-04-11 05:51:13 +02:00
2024-08-08 06:57:51 +02:00
inputs[14].mappableStep();
}
2024-01-22 10:46:04 +01:00
static processData = function(_outSurf, _data, _output_index, _array_index) {
2024-04-11 05:51:13 +02:00
var _iSrf = _data[ 0];
var _dim = _data[ 1];
var _amo = _data[ 2];
var _pat = _data[ 3];
2023-01-17 08:11:55 +01:00
2024-04-11 05:51:13 +02:00
var _spos = _data[ 9];
var _srot = _data[32];
2023-01-17 08:11:55 +01:00
2024-04-11 05:51:13 +02:00
var _rpos = _data[ 4];
var _rsta = _data[26];
var _rrot = _data[ 5];
var _rots = _data[33];
2024-04-11 05:51:13 +02:00
var _rsca = _data[ 6];
var _msca = _data[10];
2023-01-17 08:11:55 +01:00
2024-04-11 05:51:13 +02:00
var _aran = _data[ 7];
var _arad = _data[ 8];
2023-01-17 08:11:55 +01:00
2024-04-11 05:51:13 +02:00
var _path = _data[11];
var _prng = _data[12];
var _prsh = _data[13];
2023-01-17 08:11:55 +01:00
2024-04-11 05:51:13 +02:00
var _grad = _data[14];
var _grad_map = _data[30];
var _grad_range = _data[31];
2023-01-17 08:11:55 +01:00
2024-04-11 05:51:13 +02:00
var _arr = _data[16];
var _sed = _data[17];
2023-01-17 08:11:55 +01:00
2024-04-11 05:51:13 +02:00
var _col = _data[18];
var _cls = _data[19];
2023-01-17 08:11:55 +01:00
2024-04-11 05:51:13 +02:00
var _an_use = _data[29];
2024-01-08 08:10:50 +01:00
2024-04-11 05:51:13 +02:00
var _an_mid = _data[20];
var _an_ran = _data[21];
var _an_fal = _data[25];
var _an_pos = _data[22];
var _an_rot = _data[23];
var _an_sca = _data[24];
2023-01-17 08:11:55 +01:00
2024-04-11 05:51:13 +02:00
var _an_bld = _data[27];
2024-01-08 08:10:50 +01:00
var _an_alp = _color_get_alpha(_an_bld);
2023-01-25 06:49:00 +01:00
var _bld_md = _data[34];
2023-02-14 07:37:13 +01:00
var _surf, runx, runy, posx, posy, scax, scay, rot;
2023-01-17 08:11:55 +01:00
random_set_seed(_sed);
surface_set_shader(_outSurf);
if(_bld_md == 0) BLEND_ALPHA_MULP
else if(_bld_md == 1) BLEND_ADD
else if(_bld_md == 2) { BLEND_ALPHA_MULP gpu_set_blendequation(bm_eq_max); }
2023-01-17 08:11:55 +01:00
runx = 0;
runy = 0;
for( var i = 0; i < _amo; i++ ) {
posx = runx;
posy = runy;
if(_pat == 0) {
if(_path == noone || !variable_struct_exists(_path, "getPointRatio")) {
posx += _spos[0] + _rpos[0] * i;
posy += _spos[1] + _rpos[1] * i;
} else {
2023-01-25 06:49:00 +01:00
var rat = _prsh + _prng[0] + (_prng[1] - _prng[0]) * i / _amo;
if(_prng[1] - _prng[0] == 0) break;
2023-01-17 08:11:55 +01:00
rat = abs(frac(rat));
var _p = _path.getPointRatio(rat);
2023-03-19 09:17:39 +01:00
posx = _p.x;
posy = _p.y;
2023-01-17 08:11:55 +01:00
}
} else if(_pat == 1) {
var row = floor(i / _col);
2023-02-20 10:16:31 +01:00
var col = safe_mod(i, _col);
2023-01-17 08:11:55 +01:00
posx = _spos[0] + _rpos[0] * col + _cls[0] * row;
posy = _spos[1] + _rpos[1] * col + _cls[1] * row;
2023-01-17 08:11:55 +01:00
} else if(_pat == 2) {
var aa = _srot + lerp(_aran[0], _aran[1], i / _amo);
2023-01-17 08:11:55 +01:00
posx = _spos[0] + lengthdir_x(_arad, aa);
posy = _spos[1] + lengthdir_y(_arad, aa);
}
2023-02-14 05:32:32 +01:00
scax = eval_curve_x(_msca, i / (_amo - 1)) * _rsca;
2023-01-17 08:11:55 +01:00
scay = scax;
rot = _rots + _rrot[0] + (_rrot[1] - _rrot[0]) * i / _amo;
2023-01-17 08:11:55 +01:00
var _an_dist = abs(i - _an_mid * (_amo - 1));
2023-01-25 06:49:00 +01:00
var _inf = 0;
2024-01-08 08:10:50 +01:00
if(_an_use && _an_dist < _an_ran * _amo) {
2023-02-14 05:32:32 +01:00
_inf = eval_curve_x(_an_fal, _an_dist / (_an_ran * _amo));
2023-01-17 08:11:55 +01:00
posx += _an_pos[0] * _inf;
posy += _an_pos[1] * _inf;
rot += _an_rot * _inf;
scax += _an_sca[0] * _inf;
scay += _an_sca[1] * _inf;
}
2024-04-11 05:51:13 +02:00
var _surf = _iSrf;
if(is_array(_iSrf)) {
var _sid = 0;
if(_arr == 0) _sid = safe_mod(i, array_length(_iSrf));
else if(_arr == 1) _sid = irandom(array_length(_iSrf) - 1);
_surf = array_safe_get_fast(_iSrf, _sid);
}
2023-01-17 08:11:55 +01:00
2024-04-11 05:51:13 +02:00
if(!is_surface(_surf)) continue;
2023-01-17 08:11:55 +01:00
2023-09-08 21:37:36 +02:00
var _sw = surface_get_width_safe(_surf);
var _sh = surface_get_height_safe(_surf);
2023-01-17 08:11:55 +01:00
var sw = _sw * scax;
var sh = _sh * scay;
if(i) {
if(_rsta == 1) {
runx += _sw / 2;
posx += _sw / 2;
}
if(_rsta == 2) {
runy += _sh / 2;
posy += _sh / 2;
}
}
var pos = point_rotate(-sw / 2, -sh / 2, 0, 0, rot);
2024-08-08 06:57:51 +02:00
var cc = evaluate_gradient_map(i / (_amo - 1), _grad, _grad_map, _grad_range, inputs[14]);
2024-01-08 08:10:50 +01:00
var aa = _color_get_alpha(cc);
2023-01-17 08:11:55 +01:00
2024-01-08 08:10:50 +01:00
if(_an_use) {
cc = merge_color_a(cc, colorMultiply(cc, _an_bld), _inf);
2024-01-08 08:10:50 +01:00
aa += _an_alp * _inf;
}
2023-01-25 06:49:00 +01:00
shader_set_interpolation(_surf);
2023-01-17 08:11:55 +01:00
draw_surface_ext_safe(_surf, posx + pos[0], posy + pos[1], scax, scay, rot, cc, aa);
if(_rsta == 1) runx += _sw / 2;
if(_rsta == 2) runy += _sh / 2;
}
BLEND_NORMAL
gpu_set_blendequation(bm_eq_add);
surface_reset_shader();
2023-09-14 16:29:39 +02:00
2024-04-11 05:51:13 +02:00
return _outSurf;
}
2023-01-17 08:11:55 +01:00
}