From a768e60f21e67e1e98148908d7a11b7d6fa3ff01 Mon Sep 17 00:00:00 2001 From: Tanasart Date: Sat, 20 Apr 2024 08:02:56 +0700 Subject: [PATCH] active canvas fix --- .../node_active_canvas.gml.backup0 | 144 ++++++++++++++++++ .../node_active_canvas.gml.backup1 | 144 ++++++++++++++++++ .../node_canvas/node_canvas.gml.backup0 | 2 +- .../node_canvas/node_canvas.gml.backup1 | 2 +- .../node_active_canvas/node_active_canvas.gml | 2 + 5 files changed, 292 insertions(+), 2 deletions(-) create mode 100644 #backups/scripts/node_active_canvas/node_active_canvas.gml.backup0 create mode 100644 #backups/scripts/node_active_canvas/node_active_canvas.gml.backup1 diff --git a/#backups/scripts/node_active_canvas/node_active_canvas.gml.backup0 b/#backups/scripts/node_active_canvas/node_active_canvas.gml.backup0 new file mode 100644 index 000000000..553328ed0 --- /dev/null +++ b/#backups/scripts/node_active_canvas/node_active_canvas.gml.backup0 @@ -0,0 +1,144 @@ +// 2024-04-20 08:02:45 +function Node_Active_Canvas(_x, _y, _group = noone) : Node(_x, _y, _group) constructor { + name = "Active Canvas"; + + inputs[| 0] = nodeValue("Dimension", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, DEF_SURF ) + .setDisplay(VALUE_DISPLAY.vector); + + inputs[| 1] = nodeValue("Texture", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone ); + + inputs[| 2] = nodeValue("Position", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 0, 0 ] ) + .setDisplay(VALUE_DISPLAY.vector); + + inputs[| 3] = nodeValue("Rotation", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0 ) + .setDisplay(VALUE_DISPLAY.rotation); + + inputs[| 4] = nodeValue("Scale", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 1, 1 ] ) + .setDisplay(VALUE_DISPLAY.vector); + + inputs[| 5] = nodeValue("Color", self, JUNCTION_CONNECT.input, VALUE_TYPE.color, c_white ); + + inputs[| 6] = nodeValue("Alpha", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1 ) + .setDisplay(VALUE_DISPLAY.slider); + + inputs[| 7] = nodeValue("Active", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true ); + + inputs[| 8] = nodeValue("Distance", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 1, 1 ] ) + .setDisplay(VALUE_DISPLAY.range, { linked : true }); + + outputs[| 0] = nodeValue("Output", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone ); + + input_display_list = [ 0, + [ "Brush transform", false ], 7, 2, 3, 4, + [ "Brush properties", false ], 1, 5, 8, + ]; + + brush_prev = noone; + brush_next_dist = 0; + + temp_surface = [ surface_create(1, 1) ]; + + static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) { #region + inputs[| 2].drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny); + } #endregion + + static step = function() { #region + + } #endregion + + static brush_draw_surface = function(_surf, _x, _y, _sx, _sy, _rot, _clr, _alp) { #region + INLINE + + var _bsw = surface_get_width_safe(_surf); + var _bsh = surface_get_height_safe(_surf); + var _p = point_rotate(-_bsw * _sx / 2, -_bsh * _sy / 2, 0, 0, _rot); + draw_surface_ext_safe(_surf, _x + _p[0], _y + _p[1], _sx, _sy, _rot, _clr, _alp); + } #endregion + + static update = function() { #region + var _surf = outputs[| 0].getValue(); + + var _dim = getInputData(0); + var _bsurf = getInputData(1); + var _bpos = getInputData(2); + var _brot = getInputData(3); + var _bsca = getInputData(4); + var _bcol = getInputData(5); + var _balp = _color_get_alpha(_bcol); + var _bact = getInputData(7); + var _bdst = getInputData(8); + + _surf = surface_verify(_surf, _dim[0], _dim[1]); + temp_surface[0] = surface_verify(temp_surface[0], _dim[0], _dim[1]); + + var _bdense = _bdst[0] == _bdst[1] && _bdst[0] == 1; + _bdst[0] = max(0.01, _bdst[0]); + _bdst[1] = max(0.01, _bdst[1]); + + outputs[| 0].setValue(_surf); + if(!_bact) return; + + surface_set_target(temp_surface[0]); + DRAW_CLEAR + BLEND_OVERRIDE + + if(!IS_FIRST_FRAME) + draw_surface_ext(_surf, 0, 0, 1, 1, 0, c_white, 1); + + BLEND_NORMAL + surface_reset_target(); + + surface_set_target(_surf); + DRAW_CLEAR + + draw_surface(temp_surface[0], 0, 0); + + if(!is_surface(_bsurf)) { + if(IS_FIRST_FRAME || brush_prev == noone) + draw_point_color(_bpos[0] - 1, _bpos[1] - 1, _bcol); + else + draw_line_color(brush_prev[2][0] - 1, brush_prev[2][1] - 1, _bpos[0] - 1, _bpos[1] - 1, brush_prev[5], _bcol); + } else { + BLEND_ALPHA + + if(IS_FIRST_FRAME || brush_prev == noone) { + brush_draw_surface(_bsurf, _bpos[0], _bpos[1], _bsca[0], _bsca[1], _brot, _bcol, _balp); + } else { + var _x0 = brush_prev[2][0]; + var _y0 = brush_prev[2][1]; + var diss = point_distance(_x0, _y0, _bpos[0], _bpos[1]); + var dirr = point_direction(_x0, _y0, _bpos[0], _bpos[1]); + + var st_x = lengthdir_x(1, dirr); + var st_y = lengthdir_y(1, dirr); + + var _draw = !brush_prev[7]; + var _i = _draw? 0 : brush_next_dist; + var _dst = diss; + + if(_i < diss) { + while(_i < diss) { + var _px = _x0 + st_x * _i; + var _py = _y0 + st_y * _i; + + brush_draw_surface(_bsurf, _px, _py, _bsca[0], _bsca[1], _brot, _bcol, _balp); + + brush_next_dist = random_range(_bdst[0], _bdst[1]); + _i += brush_next_dist; + _dst -= brush_next_dist; + } + + brush_next_dist -= _dst; + } else + brush_next_dist -= diss; + + if(_bdense) brush_draw_surface(_bsurf, _bpos[0], _bpos[1], _bsca[0], _bsca[1], _brot, _bcol, _balp); + } + BLEND_NORMAL + } + surface_reset_target(); + + for( var i = 0, n = array_length(inputs_data); i < n; i++ ) + brush_prev[i] = variable_clone(inputs_data[i], 1); + } #endregion +} \ No newline at end of file diff --git a/#backups/scripts/node_active_canvas/node_active_canvas.gml.backup1 b/#backups/scripts/node_active_canvas/node_active_canvas.gml.backup1 new file mode 100644 index 000000000..89507ad94 --- /dev/null +++ b/#backups/scripts/node_active_canvas/node_active_canvas.gml.backup1 @@ -0,0 +1,144 @@ +// 2024-04-20 07:59:42 +function Node_Active_Canvas(_x, _y, _group = noone) : Node(_x, _y, _group) constructor { + name = "Active Canvas"; + + inputs[| 0] = nodeValue("Dimension", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, DEF_SURF ) + .setDisplay(VALUE_DISPLAY.vector); + + inputs[| 1] = nodeValue("Texture", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone ); + + inputs[| 2] = nodeValue("Position", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 0, 0 ] ) + .setDisplay(VALUE_DISPLAY.vector); + + inputs[| 3] = nodeValue("Rotation", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0 ) + .setDisplay(VALUE_DISPLAY.rotation); + + inputs[| 4] = nodeValue("Scale", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 1, 1 ] ) + .setDisplay(VALUE_DISPLAY.vector); + + inputs[| 5] = nodeValue("Color", self, JUNCTION_CONNECT.input, VALUE_TYPE.color, c_white ); + + inputs[| 6] = nodeValue("Alpha", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1 ) + .setDisplay(VALUE_DISPLAY.slider); + + inputs[| 7] = nodeValue("Active", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true ); + + inputs[| 8] = nodeValue("Distance", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 1, 1 ] ) + .setDisplay(VALUE_DISPLAY.range, { linked : true }); + + outputs[| 0] = nodeValue("Output", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone ); + + input_display_list = [ 0, + [ "Brush transform", false ], 7, 2, 3, 4, + [ "Brush properties", false ], 1, 5, 8, + ]; + + brush_prev = noone; + brush_next_dist = 0; + + temp_surface = [ surface_create(1, 1) ]; + + static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) { #region + inputs[| 2].drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny); + } #endregion + + static step = function() { #region + + } #endregion + + static brush_draw_surface = function(_surf, _x, _y, _sx, _sy, _rot, _clr, _alp) { #region + INLINE + + var _bsw = surface_get_width_safe(_surf); + var _bsh = surface_get_height_safe(_surf); + var _p = point_rotate(-_bsw * _sx / 2, -_bsh * _sy / 2, 0, 0, _rot); + draw_surface_ext_safe(_surf, _x + _p[0], _y + _p[1], _sx, _sy, _rot, _clr, _alp); + } #endregion + + static update = function() { #region + var _surf = outputs[| 0].getValue(); + + var _dim = getInputData(0); + var _bsurf = getInputData(1); + var _bpos = getInputData(2); + var _brot = getInputData(3); + var _bsca = getInputData(4); + var _bcol = getInputData(5); + var _balp = _color_get_alpha(_bcol); + var _bact = getInputData(7); + var _bdst = getInputData(8); + + _surf = surface_verify(_surf, _dim[0], _dim[1]); + temp_surface[0] = surface_verify(temp_surface[0], _dim[0], _dim[1]); + + var _bdense = _bdst[0] == _bdst[1] && _bdst[0] == 1; + _bdst[0] = max(0.01, _bdst[0]); + _bdst[1] = max(0.01, _bdst[1]); + + outputs[| 0].setValue(_surf); + if(!_bact) return; + + surface_set_target(temp_surface[0]); + DRAW_CLEAR + BLEND_OVERRIDE + + if(!IS_FIRST_FRAME) + draw_surface_ext(_surf, 0, 0, 1, 1, 0, c_white, 1); + + BLEND_NORMAL + surface_reset_target(); + + surface_set_target(_surf); + DRAW_CLEAR + + draw_surface(temp_surface[0], 0, 0); + + if(!is_surface(_bsurf)) { + if(IS_FIRST_FRAME || brush_prev == noone) + draw_point_color(_bpos[0] - 1, _bpos[1] - 1, _bcol); + else + draw_line_color(brush_prev[2][0] - 1, brush_prev[2][1] - 1, _bpos[0] - 1, _bpos[1] - 1, brush_prev[5], _bcol); + } else { + BLEND_ALPHA + + if(IS_FIRST_FRAME || brush_prev == noone) { + brush_draw_surface(_bsurf, _bpos[0], _bpos[1], _bsca[0], _bsca[1], _brot, _bcol, _balp); + } else { + var _x0 = brush_prev[2][0]; + var _y0 = brush_prev[2][1]; + var diss = point_distance(_x0, _y0, _bpos[0], _bpos[1]); + var dirr = point_direction(_x0, _y0, _bpos[0], _bpos[1]); + + var st_x = lengthdir_x(1, dirr); + var st_y = lengthdir_y(1, dirr); + + var _draw = !brush_prev[7]; + var _i = _draw? 0 : brush_next_dist; + var _dst = diss; + + if(_i < diss) { + while(_i < diss) { + var _px = _x0 + st_x * _i; + var _py = _y0 + st_y * _i; + + brush_draw_surface(_bsurf, _px, _py, _bsca[0], _bsca[1], _brot, _bcol, _balp); + + brush_next_dist = random_range(_bdst[0], _bdst[1]); + _i += brush_next_dist; + _dst -= brush_next_dist; + } + + brush_next_dist -= _dst; + } else + brush_next_dist -= diss; + + if(_bdense) brush_draw_surface(_bsurf, _bpos[0], _bpos[1], _bsca[0], _bsca[1], _brot, _bcol, _balp); + } + BLEND_NORMAL + } + surface_reset_target(); + + for( var i = 0, n = array_length(inputs_data); i < n; i++ ) + brush_prev[i] = variable_clone(inputs_data[i], 1); + } #endregion +} \ No newline at end of file diff --git a/#backups/scripts/node_canvas/node_canvas.gml.backup0 b/#backups/scripts/node_canvas/node_canvas.gml.backup0 index 2a796d67d..daf6e9a80 100644 --- a/#backups/scripts/node_canvas/node_canvas.gml.backup0 +++ b/#backups/scripts/node_canvas/node_canvas.gml.backup0 @@ -1,4 +1,4 @@ -// 2024-04-18 16:15:18 +// 2024-04-19 07:55:21 function Node_Canvas(_x, _y, _group = noone) : Node(_x, _y, _group) constructor { name = "Canvas"; color = COLORS.node_blend_canvas; diff --git a/#backups/scripts/node_canvas/node_canvas.gml.backup1 b/#backups/scripts/node_canvas/node_canvas.gml.backup1 index 58799db9b..cb59628a2 100644 --- a/#backups/scripts/node_canvas/node_canvas.gml.backup1 +++ b/#backups/scripts/node_canvas/node_canvas.gml.backup1 @@ -1,4 +1,4 @@ -// 2024-04-18 16:15:08 +// 2024-04-18 18:31:59 function Node_Canvas(_x, _y, _group = noone) : Node(_x, _y, _group) constructor { name = "Canvas"; color = COLORS.node_blend_canvas; diff --git a/scripts/node_active_canvas/node_active_canvas.gml b/scripts/node_active_canvas/node_active_canvas.gml index 6e825ed77..764a1a119 100644 --- a/scripts/node_active_canvas/node_active_canvas.gml +++ b/scripts/node_active_canvas/node_active_canvas.gml @@ -71,6 +71,8 @@ function Node_Active_Canvas(_x, _y, _group = noone) : Node(_x, _y, _group) const temp_surface[0] = surface_verify(temp_surface[0], _dim[0], _dim[1]); var _bdense = _bdst[0] == _bdst[1] && _bdst[0] == 1; + _bdst[0] = max(0.01, _bdst[0]); + _bdst[1] = max(0.01, _bdst[1]); outputs[| 0].setValue(_surf); if(!_bact) return;