2023-02-28 09:43:01 +01:00
|
|
|
function Node_Scale(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
|
2022-01-13 05:24:03 +01:00
|
|
|
name = "Scale";
|
2023-03-19 09:17:39 +01:00
|
|
|
dimension_index = -1;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-10-10 07:12:42 +02:00
|
|
|
manage_atlas = false;
|
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
inputs[0] = nodeValue_Surface("Surface in", self);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
inputs[1] = nodeValue_Float("Scale", self, 1);
|
2022-01-17 12:10:30 +01:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
inputs[2] = nodeValue_Enum_Button("Mode", self, 0, [ "Upscale", "Scale to fit" ]);
|
2023-01-25 06:49:00 +01:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
inputs[3] = nodeValue_Vector("Target dimension", self, DEF_SURF);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
inputs[4] = nodeValue_Bool("Active", self, true);
|
2023-02-14 05:32:32 +01:00
|
|
|
active_index = 4;
|
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
inputs[5] = nodeValue_Bool("Scale atlas position", self, true);
|
2023-10-10 07:12:42 +02:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
outputs[0] = nodeValue_Output("Surface out", self, VALUE_TYPE.surface, noone);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
input_display_list = [ 4,
|
2023-11-08 14:37:51 +01:00
|
|
|
["Surfaces", true], 0,
|
2023-10-10 07:12:42 +02:00
|
|
|
["Scale", false], 2, 1, 3, 5,
|
2023-01-25 06:49:00 +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
|
|
|
|
2024-03-02 10:08:44 +01:00
|
|
|
static step = function() { #region
|
2023-10-10 07:12:42 +02:00
|
|
|
var _surf = getSingleValue(0);
|
|
|
|
|
|
|
|
var _atlas = is_instanceof(_surf, SurfaceAtlas);
|
2024-08-08 06:57:51 +02:00
|
|
|
inputs[5].setVisible(_atlas);
|
2024-03-02 10:08:44 +01:00
|
|
|
} #endregion
|
2023-10-10 07:12:42 +02:00
|
|
|
|
2023-08-17 16:56:54 +02:00
|
|
|
static processData = function(_outSurf, _data, _output_index, _array_index) {
|
2024-04-03 09:40:37 +02:00
|
|
|
var surf = _data[0];
|
2023-03-19 09:17:39 +01:00
|
|
|
var scale = _data[1];
|
|
|
|
var mode = _data[2];
|
|
|
|
var targ = _data[3];
|
2023-10-10 07:12:42 +02:00
|
|
|
var _atlS = _data[5];
|
2023-03-19 09:17:39 +01:00
|
|
|
var cDep = attrDepth();
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
inputs[1].setVisible(mode == 0);
|
|
|
|
inputs[3].setVisible(mode == 1);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-04-03 09:40:37 +02:00
|
|
|
var isAtlas = is_instanceof(surf, SurfaceAtlas);
|
2023-10-10 07:12:42 +02:00
|
|
|
if(isAtlas && !is_instanceof(_outSurf, SurfaceAtlas))
|
|
|
|
_outSurf = _data[0].clone(true);
|
|
|
|
var _surf = isAtlas? _outSurf.getSurface() : _outSurf;
|
|
|
|
|
|
|
|
var ww, hh, scx = 1, scy = 1;
|
2023-01-25 06:49:00 +01:00
|
|
|
switch(mode) {
|
|
|
|
case 0 :
|
2023-10-10 07:12:42 +02:00
|
|
|
scx = scale;
|
|
|
|
scy = scale;
|
2024-04-03 09:40:37 +02:00
|
|
|
ww = scale * surface_get_width_safe(surf);
|
|
|
|
hh = scale * surface_get_height_safe(surf);
|
2023-01-25 06:49:00 +01:00
|
|
|
break;
|
2023-10-10 07:12:42 +02:00
|
|
|
case 1 :
|
2024-04-03 09:40:37 +02:00
|
|
|
scx = targ[0] / surface_get_width_safe(surf);
|
|
|
|
scy = targ[1] / surface_get_height_safe(surf);
|
2023-01-25 06:49:00 +01:00
|
|
|
ww = targ[0];
|
|
|
|
hh = targ[1];
|
|
|
|
break;
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
2023-01-25 06:49:00 +01:00
|
|
|
|
2023-10-10 07:12:42 +02:00
|
|
|
_surf = surface_verify(_surf, ww, hh, cDep);
|
2023-01-25 06:49:00 +01:00
|
|
|
|
2023-10-10 07:12:42 +02:00
|
|
|
surface_set_shader(_surf);
|
2023-03-21 03:01:53 +01:00
|
|
|
shader_set_interpolation(_data[0]);
|
|
|
|
draw_surface_stretched_safe(_data[0], 0, 0, ww, hh);
|
|
|
|
surface_reset_shader();
|
2023-01-25 06:49:00 +01:00
|
|
|
|
2023-10-10 07:12:42 +02:00
|
|
|
if(isAtlas) {
|
|
|
|
if(_atlS) {
|
2024-04-03 09:40:37 +02:00
|
|
|
_outSurf.x = surf.x * scx;
|
|
|
|
_outSurf.y = surf.y * scy;
|
2023-10-10 07:12:42 +02:00
|
|
|
} else {
|
2024-04-03 09:40:37 +02:00
|
|
|
_outSurf.x = surf.x;
|
|
|
|
_outSurf.y = surf.y;
|
2023-10-10 07:12:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
_outSurf.setSurface(_surf);
|
2023-10-10 11:41:39 +02:00
|
|
|
} else
|
|
|
|
_outSurf = _surf;
|
2023-10-10 07:12:42 +02:00
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
return _outSurf;
|
|
|
|
}
|
|
|
|
}
|