2023-02-28 09:43:01 +01:00
function Node_Repeat(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
2023-01-17 08:11:55 +01:00
name = "Repeat";
2023-02-14 05:32:32 +01:00
inputs[| 0] = nodeValue("Surface in", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone );
2023-01-17 08:11:55 +01:00
2023-07-21 12:40:20 +02:00
inputs[| 1] = nodeValue("Dimension", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, DEF_SURF)
2023-01-17 08:11:55 +01:00
.setDisplay(VALUE_DISPLAY.vector);
2023-02-14 05:32:32 +01:00
inputs[| 2] = nodeValue("Amount", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 2);
2023-01-17 08:11:55 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 3] = nodeValue("Pattern", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
2023-01-17 08:11:55 +01:00
.setDisplay(VALUE_DISPLAY.enum_scroll, [ "Linear", "Grid", "Circular" ]);
2023-07-21 12:40:20 +02:00
inputs[| 4] = nodeValue("Repeat position", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [DEF_SURF_W / 2, 0])
2023-01-17 08:11:55 +01:00
.setDisplay(VALUE_DISPLAY.vector)
.setUnitRef(function() { return getDimension(); });
2023-02-14 05:32:32 +01:00
inputs[| 5] = nodeValue("Repeat rotation", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, [0, 0])
2023-01-17 08:11:55 +01:00
.setDisplay(VALUE_DISPLAY.rotation_range);
2023-02-14 05:32:32 +01:00
inputs[| 6] = nodeValue("Scale multiply", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1);
2023-01-17 08:11:55 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 7] = nodeValue("Angle range", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, [0, 360])
2023-01-17 08:11:55 +01:00
.setDisplay(VALUE_DISPLAY.rotation_range);
2023-02-14 05:32:32 +01:00
inputs[| 8] = nodeValue("Radius", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1);
2023-01-17 08:11:55 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 9] = nodeValue("Start position", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [0, 0])
2023-01-17 08:11:55 +01:00
.setDisplay(VALUE_DISPLAY.vector)
.setUnitRef(function(index) { return inputs[| 1].getValue(); });
2023-02-14 05:32:32 +01:00
inputs[| 10] = nodeValue("Scale over copy", self, JUNCTION_CONNECT.input, VALUE_TYPE.curve, CURVE_DEF_11 );
2023-01-17 08:11:55 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 11] = nodeValue("Path", self, JUNCTION_CONNECT.input, VALUE_TYPE.pathnode, noone, "Make each copy follow along path." )
2023-01-17 08:11:55 +01:00
.setVisible(true, true);
2023-02-14 05:32:32 +01:00
inputs[| 12] = nodeValue("Path range", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [0, 1], "Range of the path to follow.")
2023-01-17 08:11:55 +01:00
.setDisplay(VALUE_DISPLAY.slider_range, [0, 1, 0.01]);
2023-02-14 05:32:32 +01:00
inputs[| 13] = nodeValue("Path shift", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0);
2023-01-17 08:11:55 +01:00
2023-05-28 20:00:51 +02:00
inputs[| 14] = nodeValue("Color over copy", self, JUNCTION_CONNECT.input, VALUE_TYPE.gradient, new gradientObject(c_white) );
2023-01-17 08:11:55 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 15] = nodeValue("Alpha over copy", self, JUNCTION_CONNECT.input, VALUE_TYPE.curve, CURVE_DEF_11 );
2023-01-17 08:11:55 +01:00
2023-02-15 10:43:24 +01:00
inputs[| 16] = nodeValue("Array select", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0, "Whether to select image from an array in order, at random, pr spread or each image to one output." )
2023-02-14 07:37:13 +01:00
.setDisplay(VALUE_DISPLAY.enum_button, [ "Order", "Random", "Spread" ]);
2023-01-17 08:11:55 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 17] = nodeValue("Seed", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, irandom(99999) );
2023-01-17 08:11:55 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 18] = nodeValue("Column", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 4);
2023-01-17 08:11:55 +01:00
2023-07-21 12:40:20 +02:00
inputs[| 19] = nodeValue("Column shift", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [0, DEF_SURF_H / 2])
2023-01-17 08:11:55 +01:00
.setDisplay(VALUE_DISPLAY.vector)
.setUnitRef(function() { return getDimension(); });
2023-02-14 05:32:32 +01:00
inputs[| 20] = nodeValue("Animator midpoint", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0.5)
2023-01-17 08:11:55 +01:00
.setDisplay(VALUE_DISPLAY.slider, [-1, 2, 0.01]);
2023-02-14 05:32:32 +01:00
inputs[| 21] = nodeValue("Animator range", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0.1)
2023-01-17 08:11:55 +01:00
.setDisplay(VALUE_DISPLAY.slider, [0, 1, 0.01]);
2023-02-14 05:32:32 +01:00
inputs[| 22] = nodeValue("Animator position", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 0, 0 ])
2023-01-17 08:11:55 +01:00
.setDisplay(VALUE_DISPLAY.vector);
2023-02-14 05:32:32 +01:00
inputs[| 23] = nodeValue("Animator rotation", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
2023-01-17 08:11:55 +01:00
.setDisplay(VALUE_DISPLAY.rotation);
2023-02-14 05:32:32 +01:00
inputs[| 24] = nodeValue("Animator scale", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 0, 0 ])
2023-01-17 08:11:55 +01:00
.setDisplay(VALUE_DISPLAY.vector);
2023-02-14 05:32:32 +01:00
inputs[| 25] = nodeValue("Animator falloff", self, JUNCTION_CONNECT.input, VALUE_TYPE.curve, CURVE_DEF_10);
2023-01-25 06:49:00 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 26] = nodeValue("Stack", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0, "Place each copy next to each other, taking surface dimension into account.")
2023-01-17 08:11:55 +01:00
.setDisplay(VALUE_DISPLAY.enum_button, [ "None", "X", "Y" ]);
2023-02-14 05:32:32 +01:00
inputs[| 27] = nodeValue("Animator blend", self, JUNCTION_CONNECT.input, VALUE_TYPE.color, c_white);
2023-01-25 06:49:00 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 28] = nodeValue("Animator alpha", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1)
2023-01-25 06:49:00 +01:00
.setDisplay(VALUE_DISPLAY.slider, [0, 1, 0.01]);
2023-02-14 05:32:32 +01:00
outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone);
2023-01-17 08:11:55 +01:00
input_display_list = [
2023-05-03 21:42:17 +02:00
["Output", true], 0, 1, 16, 17,
2023-01-17 08:11:55 +01:00
["Pattern", false], 3, 9, 2, 18, 7, 8,
["Path", true], 11, 12, 13,
["Transform", false], 4, 26, 19, 5, 6, 10,
["Render", false], 14, 15,
2023-01-25 06:49:00 +01:00
["Animator", true], 20, 21, 25, 22, 23, 24, 27, 28,
2023-01-17 08:11:55 +01:00
];
2023-03-19 09:17:39 +01:00
attribute_surface_depth();
2023-01-17 08:11:55 +01:00
static getDimension = function() {
var _surf = inputs[| 0].getValue();
if(is_array(_surf)) {
if(array_length(_surf) == 0) return [1, 1];
if(!is_surface(_surf[0])) return [1, 1];
2023-09-08 21:37:36 +02:00
return [ surface_get_width_safe(_surf[0]), surface_get_height_safe(_surf[0]) ];
2023-01-17 08:11:55 +01:00
}
if(!is_surface(_surf)) return [1, 1];
2023-09-08 21:37:36 +02:00
return [ surface_get_width_safe(_surf), surface_get_height_safe(_surf) ];
2023-01-17 08:11:55 +01:00
}
static drawOverlay = function(active, _x, _y, _s, _mx, _my, _snx, _sny) {
if(inputs[| 9].drawOverlay(active, _x, _y, _s, _mx, _my, _snx, _sny, THEME.anchor))
active = false;
var _pat = inputs[| 3].getValue();
var _spos = inputs[| 9].getValue();
var px = _x + _spos[0] * _s;
var py = _y + _spos[1] * _s;
2023-02-14 05:32:32 +01:00
2023-01-17 08:11:55 +01:00
if(_pat == 0 || _pat == 1) {
if(inputs[| 4].drawOverlay(active, px, py, _s, _mx, _my, _snx, _sny))
active = false;
} else if(_pat == 2) {
if(inputs[| 8].drawOverlay(active, px, py, _s, _mx, _my, _snx, _sny))
active = false;
}
}
2023-02-14 07:37:13 +01:00
function doRepeat(_outSurf, _inSurf) {
2023-02-14 05:32:32 +01:00
var _dim = inputs[| 1].getValue();
var _amo = inputs[| 2].getValue();
var _pat = inputs[| 3].getValue();
2023-01-17 08:11:55 +01:00
var _spos = inputs[| 9].getValue();
var _rpos = inputs[| 4].getValue();
var _rsta = inputs[| 26].getValue();
var _rrot = inputs[| 5].getValue();
var _rsca = inputs[| 6].getValue();
var _msca = inputs[| 10].getValue();
var _aran = inputs[| 7].getValue();
var _arad = inputs[| 8].getValue();
var _path = inputs[| 11].getValue();
var _prng = inputs[| 12].getValue();
var _prsh = inputs[| 13].getValue();
var _grad = inputs[| 14].getValue();
var _alph = inputs[| 15].getValue();
var _arr = inputs[| 16].getValue();
var _sed = inputs[| 17].getValue();
var _col = inputs[| 18].getValue();
var _cls = inputs[| 19].getValue();
var _an_mid = inputs[| 20].getValue();
var _an_ran = inputs[| 21].getValue();
var _an_fal = inputs[| 25].getValue();
var _an_pos = inputs[| 22].getValue();
var _an_rot = inputs[| 23].getValue();
var _an_sca = inputs[| 24].getValue();
2023-01-25 06:49:00 +01:00
var _an_bld = inputs[| 27].getValue();
var _an_alp = inputs[| 28].getValue();
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_target(_outSurf);
2023-03-19 09:17:39 +01:00
DRAW_CLEAR
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;
} else if(_pat == 2) {
var aa = _aran[0] + (_aran[1] - _aran[0]) * i / _amo;
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 = _rrot[0] + (_rrot[1] - _rrot[0]) * i / (_amo - 1);
var _an_dist = abs(i - _an_mid * (_amo - 1));
2023-01-25 06:49:00 +01:00
var _inf = 0;
2023-01-17 08:11:55 +01:00
if(_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;
}
var _surf = _inSurf;
2023-02-14 07:37:13 +01:00
if(is_array(_inSurf))
2023-02-20 10:16:31 +01:00
_surf = array_safe_get(_inSurf, _arr? irandom(array_length(_inSurf) - 1) : safe_mod(i, array_length(_inSurf)));
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);
2023-03-02 07:59:14 +01:00
var cc = _grad.eval(i / (_amo - 1));
2023-02-14 05:32:32 +01:00
var aa = eval_curve_x(_alph, i / (_amo - 1));
2023-01-17 08:11:55 +01:00
2023-01-25 06:49:00 +01:00
cc = merge_color(cc, colorMultiply(cc, _an_bld), _inf);
aa += _an_alp * _inf;
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;
}
surface_reset_target();
2023-02-14 07:37:13 +01:00
}
2023-07-06 19:49:16 +02:00
function update(frame = PROJECT.animator.current_frame) {
2023-02-14 07:37:13 +01:00
var _inSurf = inputs[| 0].getValue();
if(is_array(_inSurf) && array_length(_inSurf) == 0) return;
if(!is_array(_inSurf) && !is_surface(_inSurf)) return;
2023-03-19 09:17:39 +01:00
var _dim = inputs[| 1].getValue();
var _pat = inputs[| 3].getValue();
var cDep = attrDepth();
2023-02-14 07:37:13 +01:00
var _arr = inputs[| 16].getValue();
2023-02-14 05:32:32 +01:00
2023-02-14 07:37:13 +01: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);
var runx, runy, posx, posy, scax, scay, rot;
var _outSurf = outputs[| 0].getValue();
if(is_array(_inSurf) && _arr == 2) {
if(!is_array(_outSurf)) surface_free(_outSurf);
else {
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(_outSurf); i < n; i++ )
2023-02-14 07:37:13 +01:00
surface_free(_outSurf[i]);
}
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(_inSurf); i < n; i++ ) {
2023-03-19 09:17:39 +01:00
var _out = surface_create(_dim[0], _dim[1], cDep);
2023-02-14 07:37:13 +01:00
_outSurf[i] = _out;
doRepeat(_out, _inSurf[i]);
}
outputs[| 0].setValue(_outSurf);
} else {
2023-03-19 09:17:39 +01:00
_outSurf = surface_verify(_outSurf, _dim[0], _dim[1], cDep);
2023-02-14 07:37:13 +01:00
outputs[| 0].setValue(_outSurf);
doRepeat(_outSurf, _inSurf);
}
2023-01-17 08:11:55 +01:00
}
}