2023-02-28 09:43:01 +01:00
|
|
|
function Node_Warp(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
|
2022-01-13 05:24:03 +01:00
|
|
|
name = "Warp";
|
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(0, nodeValue_Surface("Surface in", self));
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-08-18 09:13:41 +02:00
|
|
|
newInput(1, nodeValue_Vec2("Top left", self, [ 0, 0 ] ))
|
2022-12-27 13:30:02 +01:00
|
|
|
.setUnitRef(function(index) { return getDimension(index); });
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-08-18 09:13:41 +02:00
|
|
|
newInput(2, nodeValue_Vec2("Top right", self, [ DEF_SURF_W, 0 ] ))
|
2022-12-27 13:30:02 +01:00
|
|
|
.setUnitRef(function(index) { return getDimension(index); });
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-08-18 09:13:41 +02:00
|
|
|
newInput(3, nodeValue_Vec2("Bottom left", self, [ 0, DEF_SURF_H ] ))
|
2022-12-27 13:30:02 +01:00
|
|
|
.setUnitRef(function(index) { return getDimension(index); });
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-08-18 09:13:41 +02:00
|
|
|
newInput(4, nodeValue_Vec2("Bottom right", self, DEF_SURF ))
|
2022-12-27 13:30:02 +01:00
|
|
|
.setUnitRef(function(index) { return getDimension(index); });
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(5, nodeValue_Bool("Active", self, true));
|
2023-02-14 05:32:32 +01:00
|
|
|
active_index = 5;
|
2024-01-26 14:38:50 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(6, nodeValue_Bool("Use custom dimension", self, false));
|
2024-01-26 14:38:50 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(7, nodeValue_Dimension(self));
|
2024-01-26 14:38:50 +01:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
outputs[0] = nodeValue_Output("Surface out", self, VALUE_TYPE.surface, noone);
|
2023-02-14 05:32:32 +01:00
|
|
|
|
|
|
|
input_display_list = [ 5,
|
2024-01-26 14:38:50 +01:00
|
|
|
["Surfaces", false], 0, 6, 7,
|
2023-02-14 05:32:32 +01:00
|
|
|
["Wrap", false], 1, 2, 3, 4
|
|
|
|
]
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-03-19 09:17:39 +01:00
|
|
|
attribute_surface_depth();
|
2023-03-21 03:01:53 +01:00
|
|
|
attribute_interpolation();
|
2023-03-19 09:17:39 +01:00
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
drag_side = -1;
|
2024-01-27 14:36:36 +01:00
|
|
|
drag_mx = 0;
|
|
|
|
drag_my = 0;
|
|
|
|
drag_s = [[0, 0], [0, 0]];
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-04-03 09:40:37 +02:00
|
|
|
attributes.initalset = LOADING || APPENDING;
|
2023-09-02 10:43:33 +02:00
|
|
|
|
2024-01-30 15:04:56 +01:00
|
|
|
warp_surface = array_create(2);
|
|
|
|
|
2024-07-12 11:11:43 +02:00
|
|
|
static onValueFromUpdate = function(index) {
|
2024-04-03 09:40:37 +02:00
|
|
|
if(index == 0 && attributes.initalset == false) {
|
2023-10-02 08:57:44 +02:00
|
|
|
var _surf = getInputData(0);
|
2023-09-02 10:43:33 +02:00
|
|
|
if(!is_surface(_surf)) return;
|
|
|
|
|
2023-09-08 21:37:36 +02:00
|
|
|
var _sw = surface_get_width_safe(_surf);
|
|
|
|
var _sh = surface_get_height_safe(_surf);
|
2023-09-02 10:43:33 +02:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
inputs[1].setValue([ 0, 0 ]);
|
|
|
|
inputs[2].setValue([ _sw, 0 ]);
|
|
|
|
inputs[3].setValue([ 0, _sh ]);
|
|
|
|
inputs[4].setValue([ _sw, _sh ]);
|
2023-09-02 10:43:33 +02:00
|
|
|
|
2024-04-03 09:40:37 +02:00
|
|
|
attributes.initalset = true;
|
2023-09-02 10:43:33 +02:00
|
|
|
}
|
2024-07-12 11:11:43 +02:00
|
|
|
} if(!LOADING && !APPENDING) run_in(1, function() { onValueFromUpdate(0); })
|
2023-09-02 10:43:33 +02:00
|
|
|
|
2024-07-12 11:11:43 +02:00
|
|
|
static step = function() {
|
2024-01-26 14:38:50 +01:00
|
|
|
var _useDim = getInputData(6);
|
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
inputs[7].setVisible(_useDim);
|
2024-01-26 14:38:50 +01:00
|
|
|
dimension_index = _useDim? 7 : 0;
|
2024-07-12 11:11:43 +02:00
|
|
|
}
|
2024-01-26 14:38:50 +01:00
|
|
|
|
2024-07-12 11:11:43 +02:00
|
|
|
static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny, params) {
|
2024-05-10 04:01:14 +02:00
|
|
|
PROCESSOR_OVERLAY_CHECK
|
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
var _surf = outputs[0].getValue();
|
2022-01-13 05:24:03 +01:00
|
|
|
if(is_array(_surf)) {
|
|
|
|
if(array_length(_surf) == 0) return;
|
2022-01-16 05:17:35 +01:00
|
|
|
_surf = _surf[preview_index];
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
|
2024-07-13 03:18:17 +02:00
|
|
|
var _ss = current_data[0];
|
|
|
|
if(!is_surface(_ss)) return;
|
2024-07-12 11:11:43 +02:00
|
|
|
|
2024-05-10 04:01:14 +02:00
|
|
|
var tl = array_clone(current_data[1]);
|
|
|
|
var tr = array_clone(current_data[2]);
|
|
|
|
var bl = array_clone(current_data[3]);
|
|
|
|
var br = array_clone(current_data[4]);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-12-19 13:35:30 +01:00
|
|
|
tl[0] = _x + tl[0] * _s;
|
|
|
|
tr[0] = _x + tr[0] * _s;
|
|
|
|
bl[0] = _x + bl[0] * _s;
|
|
|
|
br[0] = _x + br[0] * _s;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-12-19 13:35:30 +01:00
|
|
|
tl[1] = _y + tl[1] * _s;
|
|
|
|
tr[1] = _y + tr[1] * _s;
|
|
|
|
bl[1] = _y + bl[1] * _s;
|
|
|
|
br[1] = _y + br[1] * _s;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-01-30 15:04:56 +01:00
|
|
|
#region preview
|
|
|
|
var sw = surface_get_width(_surf) * _s;
|
|
|
|
var sh = surface_get_height(_surf) * _s;
|
|
|
|
|
|
|
|
warp_surface[0] = surface_verify(warp_surface[0], params.w, params.h);
|
|
|
|
warp_surface[1] = surface_verify(warp_surface[1], sw, sh);
|
|
|
|
|
|
|
|
surface_set_target(warp_surface[1]);
|
|
|
|
draw_clear(c_black);
|
|
|
|
draw_set_color(c_dkgrey);
|
|
|
|
|
|
|
|
for(var i = 0; i <= 1; i += 0.125) {
|
|
|
|
draw_line_width(0, i * sh, sw, i * sh, 2);
|
|
|
|
draw_line_width(i * sw, 0, i * sw, sh, 2);
|
|
|
|
}
|
|
|
|
surface_reset_target();
|
|
|
|
|
|
|
|
warpSurface( warp_surface[0], warp_surface[1], params.w, params.h, tl, tr, bl, br, true );
|
|
|
|
|
2024-07-13 03:18:17 +02:00
|
|
|
// BLEND_ADD
|
|
|
|
// draw_surface_safe(warp_surface[0]);
|
|
|
|
// BLEND_NORMAL
|
2024-01-30 15:04:56 +01:00
|
|
|
#endregion
|
|
|
|
|
2022-11-18 03:20:31 +01:00
|
|
|
draw_set_color(COLORS._main_accent);
|
2022-01-13 05:24:03 +01:00
|
|
|
draw_line(tl[0], tl[1], tr[0], tr[1]);
|
|
|
|
draw_line(tl[0], tl[1], bl[0], bl[1]);
|
|
|
|
draw_line(br[0], br[1], tr[0], tr[1]);
|
|
|
|
draw_line(br[0], br[1], bl[0], bl[1]);
|
|
|
|
|
2024-01-26 14:38:50 +01:00
|
|
|
var _hactive = active;
|
|
|
|
if(point_in_circle(_mx, _my, tl[0], tl[1], 12)) _hactive = false;
|
|
|
|
if(point_in_circle(_mx, _my, tr[0], tr[1], 12)) _hactive = false;
|
|
|
|
if(point_in_circle(_mx, _my, bl[0], bl[1], 12)) _hactive = false;
|
|
|
|
if(point_in_circle(_mx, _my, br[0], br[1], 12)) _hactive = false;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-09-21 06:09:40 +02:00
|
|
|
var dx = 0;
|
|
|
|
var dy = 0;
|
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
if(drag_side > -1) {
|
2022-12-19 13:35:30 +01:00
|
|
|
dx = (_mx - drag_mx) / _s;
|
|
|
|
dy = (_my - drag_my) / _s;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-12-10 05:06:01 +01:00
|
|
|
if(mouse_release(mb_left)) {
|
2022-01-13 05:24:03 +01:00
|
|
|
drag_side = -1;
|
|
|
|
UNDO_HOLDING = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-30 15:04:56 +01:00
|
|
|
#region edit
|
|
|
|
draw_set_color(COLORS.node_overlay_gizmo_inactive);
|
|
|
|
if(drag_side == 0) {
|
|
|
|
draw_line_width(tl[0], tl[1], tr[0], tr[1], 3);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-01-30 15:04:56 +01:00
|
|
|
var _tlx = value_snap(drag_s[0][0] + dx, _snx);
|
|
|
|
var _tly = value_snap(drag_s[0][1] + dy, _sny);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-01-30 15:04:56 +01:00
|
|
|
var _trx = value_snap(drag_s[1][0] + dx, _snx);
|
|
|
|
var _try = value_snap(drag_s[1][1] + dy, _sny);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
var _up1 = inputs[1].setValue([ _tlx, _tly ]);
|
|
|
|
var _up2 = inputs[2].setValue([ _trx, _try ]);
|
2023-09-15 20:12:02 +02:00
|
|
|
|
2024-01-30 15:04:56 +01:00
|
|
|
if(_up1 || _up2) UNDO_HOLDING = true;
|
|
|
|
} else if(drag_side == 1) {
|
|
|
|
draw_line_width(tl[0], tl[1], bl[0], bl[1], 3);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-01-30 15:04:56 +01:00
|
|
|
var _tlx = value_snap(drag_s[0][0] + dx, _snx);
|
|
|
|
var _tly = value_snap(drag_s[0][1] + dy, _sny);
|
2022-12-19 13:35:30 +01:00
|
|
|
|
2024-01-30 15:04:56 +01:00
|
|
|
var _blx = value_snap(drag_s[1][0] + dx, _snx);
|
|
|
|
var _bly = value_snap(drag_s[1][1] + dy, _sny);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
var _up1 = inputs[1].setValue([ _tlx, _tly ]);
|
|
|
|
var _up3 = inputs[3].setValue([ _blx, _bly ]);
|
2023-09-15 20:12:02 +02:00
|
|
|
|
2024-01-30 15:04:56 +01:00
|
|
|
if(_up1 || _up3) UNDO_HOLDING = true;
|
|
|
|
} else if(drag_side == 2) {
|
|
|
|
draw_line_width(br[0], br[1], tr[0], tr[1], 3);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-01-30 15:04:56 +01:00
|
|
|
var _brx = value_snap(drag_s[0][0] + dx, _snx);
|
|
|
|
var _bry = value_snap(drag_s[0][1] + dy, _sny);
|
2022-12-19 13:35:30 +01:00
|
|
|
|
2024-01-30 15:04:56 +01:00
|
|
|
var _trx = value_snap(drag_s[1][0] + dx, _snx);
|
|
|
|
var _try = value_snap(drag_s[1][1] + dy, _sny);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
var _up4 = inputs[4].setValue([ _brx, _bry ]);
|
|
|
|
var _up2 = inputs[2].setValue([ _trx, _try ]);
|
2023-09-15 20:12:02 +02:00
|
|
|
|
2024-01-30 15:04:56 +01:00
|
|
|
if(_up4 || _up2) UNDO_HOLDING = true;
|
|
|
|
} else if(drag_side == 3) {
|
|
|
|
draw_line_width(br[0], br[1], bl[0], bl[1], 3);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-01-30 15:04:56 +01:00
|
|
|
var _brx = value_snap(drag_s[0][0] + dx, _snx);
|
|
|
|
var _bry = value_snap(drag_s[0][1] + dy, _sny);
|
2022-12-19 13:35:30 +01:00
|
|
|
|
2024-01-30 15:04:56 +01:00
|
|
|
var _blx = value_snap(drag_s[1][0] + dx, _snx);
|
|
|
|
var _bly = value_snap(drag_s[1][1] + dy, _sny);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
var _up4 = inputs[4].setValue([ _brx, _bry ]);
|
|
|
|
var _up3 = inputs[3].setValue([ _blx, _bly ]);
|
2023-09-15 20:12:02 +02:00
|
|
|
|
2024-01-30 15:04:56 +01:00
|
|
|
if(_up4 || _up3) UNDO_HOLDING = true;
|
|
|
|
} else if(_hactive) {
|
|
|
|
draw_set_color(COLORS._main_accent);
|
|
|
|
if(distance_to_line_infinite(_mx, _my, tl[0], tl[1], tr[0], tr[1]) < 12) {
|
|
|
|
draw_line_width(tl[0], tl[1], tr[0], tr[1], 3);
|
|
|
|
if(mouse_press(mb_left)) {
|
|
|
|
drag_side = 0;
|
|
|
|
drag_mx = _mx;
|
|
|
|
drag_my = _my;
|
|
|
|
drag_s = [ current_data[1], current_data[2] ];
|
|
|
|
}
|
|
|
|
} else if(distance_to_line_infinite(_mx, _my, tl[0], tl[1], bl[0], bl[1]) < 12) {
|
|
|
|
draw_line_width(tl[0], tl[1], bl[0], bl[1], 3);
|
|
|
|
if(mouse_press(mb_left)) {
|
|
|
|
drag_side = 1;
|
|
|
|
drag_mx = _mx;
|
|
|
|
drag_my = _my;
|
|
|
|
drag_s = [ current_data[1], current_data[3] ];
|
|
|
|
}
|
|
|
|
} else if(distance_to_line_infinite(_mx, _my, br[0], br[1], tr[0], tr[1]) < 12) {
|
|
|
|
draw_line_width(br[0], br[1], tr[0], tr[1], 3);
|
|
|
|
if(mouse_press(mb_left)) {
|
|
|
|
drag_side = 2;
|
|
|
|
drag_mx = _mx;
|
|
|
|
drag_my = _my;
|
|
|
|
drag_s = [ current_data[4], current_data[2] ];
|
|
|
|
}
|
|
|
|
} else if(distance_to_line_infinite(_mx, _my, br[0], br[1], bl[0], bl[1]) < 12) {
|
|
|
|
draw_line_width(br[0], br[1], bl[0], bl[1], 3);
|
|
|
|
if(mouse_press(mb_left)) {
|
|
|
|
drag_side = 3;
|
|
|
|
drag_mx = _mx;
|
|
|
|
drag_my = _my;
|
|
|
|
drag_s = [ current_data[4], current_data[3] ];
|
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
}
|
2022-12-19 13:35:30 +01:00
|
|
|
|
2024-07-02 12:18:32 +02:00
|
|
|
var _hov = false;
|
2024-08-08 06:57:51 +02:00
|
|
|
var hv = inputs[1].drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny); active = !hv; _hov |= hv;
|
|
|
|
var hv = inputs[2].drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny); active = !hv; _hov |= hv;
|
|
|
|
var hv = inputs[3].drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny); active = !hv; _hov |= hv;
|
|
|
|
var hv = inputs[4].drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny); active = !hv; _hov |= hv;
|
2024-07-02 12:18:32 +02:00
|
|
|
|
|
|
|
return _hov;
|
2024-01-30 15:04:56 +01:00
|
|
|
#endregion
|
2024-07-12 11:11:43 +02:00
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-07-12 11:11:43 +02:00
|
|
|
static warpSurface = function(surf, warp, sw, sh, tl, tr, bl, br, filt = false) {
|
2023-03-29 15:02:03 +02:00
|
|
|
var teq = round(tl[1]) == round(tr[1]);
|
|
|
|
var beq = round(bl[1]) == round(br[1]);
|
|
|
|
var leq = round(tl[0]) == round(bl[0]);
|
|
|
|
var req = round(tr[0]) == round(br[0]);
|
|
|
|
|
|
|
|
if(teq && beq && leq && req) {
|
2024-01-30 15:04:56 +01:00
|
|
|
surface_set_shader(surf)
|
|
|
|
shader_set_interpolation(warp);
|
|
|
|
|
|
|
|
if(filt) gpu_set_tex_filter(true);
|
|
|
|
draw_surface_stretched_safe(warp, tl[0], tl[1], tr[0] - tl[0], bl[1] - tl[1]);
|
|
|
|
if(filt) gpu_set_tex_filter(false);
|
2023-03-29 15:02:03 +02:00
|
|
|
surface_reset_shader();
|
2024-01-30 15:04:56 +01:00
|
|
|
|
2023-03-29 15:02:03 +02:00
|
|
|
} else {
|
2024-01-30 15:04:56 +01:00
|
|
|
surface_set_shader(surf, sh_warp_4points);
|
|
|
|
shader_set_interpolation(warp);
|
2024-01-26 14:38:50 +01:00
|
|
|
|
2024-01-30 15:04:56 +01:00
|
|
|
shader_set_f("dimension", surface_get_dimension(warp));
|
2023-03-29 15:02:03 +02:00
|
|
|
shader_set_f("p0", br[0] / sw, br[1] / sh);
|
|
|
|
shader_set_f("p1", tr[0] / sw, tr[1] / sh);
|
|
|
|
shader_set_f("p2", tl[0] / sw, tl[1] / sh);
|
|
|
|
shader_set_f("p3", bl[0] / sw, bl[1] / sh);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-01-30 15:04:56 +01:00
|
|
|
if(filt) gpu_set_tex_filter(true);
|
|
|
|
draw_surface_stretched(warp, 0, 0, sw, sh);
|
|
|
|
if(filt) gpu_set_tex_filter(false);
|
2023-03-29 15:02:03 +02:00
|
|
|
surface_reset_shader();
|
|
|
|
}
|
2024-07-12 11:11:43 +02:00
|
|
|
}
|
2024-01-30 15:04:56 +01:00
|
|
|
|
2024-07-12 11:11:43 +02:00
|
|
|
static processData = function(_outSurf, _data, _output_index, _array_index) {
|
2024-01-30 15:04:56 +01:00
|
|
|
var tl = _data[1];
|
|
|
|
var tr = _data[2];
|
|
|
|
var bl = _data[3];
|
|
|
|
var br = _data[4];
|
|
|
|
|
|
|
|
var _useDim = _data[6];
|
|
|
|
var _dim = _data[7];
|
|
|
|
|
2024-07-12 11:11:43 +02:00
|
|
|
if(!is_surface(_data[0])) return _outSurf;
|
|
|
|
|
2024-01-30 15:04:56 +01:00
|
|
|
var sw = _useDim? _dim[0] : surface_get_width_safe(_data[0]);
|
|
|
|
var sh = _useDim? _dim[1] : surface_get_height_safe(_data[0]);
|
|
|
|
|
|
|
|
warpSurface(_outSurf, _data[0], sw, sh, tl, tr, bl, br);
|
2023-03-29 15:02:03 +02:00
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
return _outSurf;
|
2024-07-12 11:11:43 +02:00
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|