From 1cabe20a0035ed5814db0a8c77b1a9455564ad4b Mon Sep 17 00:00:00 2001 From: Tanasart Date: Tue, 2 Jul 2024 13:56:01 +0700 Subject: [PATCH] - [Pin] Fix junction type not being update instantanously when connected. --- PixelComposer.yyp | 1 + .../canvas_tool_corner/canvas_tool_corner.gml | 478 +++++++++++++++++- scripts/draw_arc/draw_arc.gml | 5 +- scripts/node_canvas/node_canvas.gml | 9 +- scripts/node_pin/node_pin.gml | 35 +- scripts/node_value/node_value.gml | 3 +- scripts/svg_objects/svg_objects.gml | 2 - shaders/sh_image_trace/sh_image_trace.fsh | 23 +- 8 files changed, 508 insertions(+), 48 deletions(-) diff --git a/PixelComposer.yyp b/PixelComposer.yyp index 25239f202..ca90e4181 100644 --- a/PixelComposer.yyp +++ b/PixelComposer.yyp @@ -473,6 +473,7 @@ {"$GMIncludedFile":"","%Name":"Tree sway.pxc","CopyToMask":-1,"filePath":"datafiles/Welcome files/Sample Projects","name":"Tree sway.pxc","resourceType":"GMIncludedFile","resourceVersion":"2.0",}, {"$GMIncludedFile":"","%Name":"Canvas.png","CopyToMask":-1,"filePath":"datafiles/Welcome files/Templates","name":"Canvas.png","resourceType":"GMIncludedFile","resourceVersion":"2.0",}, {"$GMIncludedFile":"","%Name":"Canvas.pxc","CopyToMask":-1,"filePath":"datafiles/Welcome files/Templates","name":"Canvas.pxc","resourceType":"GMIncludedFile","resourceVersion":"2.0",}, + {"$GMIncludedFile":"","%Name":"Canvas.pxc1","CopyToMask":-1,"filePath":"datafiles/Welcome files/Templates","name":"Canvas.pxc1","resourceType":"GMIncludedFile","resourceVersion":"2.0",}, {"$GMIncludedFile":"","%Name":"Welcome files.zip","CopyToMask":-1,"filePath":"datafiles/Welcome files","name":"Welcome files.zip","resourceType":"GMIncludedFile","resourceVersion":"2.0",}, ], "isEcma":false, diff --git a/scripts/canvas_tool_corner/canvas_tool_corner.gml b/scripts/canvas_tool_corner/canvas_tool_corner.gml index 7faf09235..d33ff825f 100644 --- a/scripts/canvas_tool_corner/canvas_tool_corner.gml +++ b/scripts/canvas_tool_corner/canvas_tool_corner.gml @@ -6,11 +6,276 @@ function canvas_tool_corner() : canvas_tool_shader() constructor { modifying = false; amount = 0; + temp_surface = [ 0, 0 ]; + anchors = []; + anchorsRounded = []; + function init() { mouse_init = true; } function onInit(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) { mouse_sx = _mx; mouse_sy = _my; + + anchors = []; + anchorsRounded = []; + + #region content extract + var _sel = node.tool_selection; + var _surf = _sel.selection_surface; + var _dim = surface_get_dimension(_surf); + + temp_surface[0] = surface_verify(temp_surface[0], _dim[0], _dim[1]); + + surface_set_shader(temp_surface[0], sh_image_trace); + shader_set_f("dimension", _dim); + shader_set_i("diagonal", 0); + draw_surface(_surf, 0, 0); + surface_reset_shader(); + + var _w = _dim[0], _h = _dim[1]; + var xx = 0, yy = 0; + + var _buff = buffer_from_surface(temp_surface[0], false); + var _emp = true; + var _ind = 0; + + buffer_seek(_buff, buffer_seek_start, 0); + repeat(_w * _h) { + var _b = buffer_read(_buff, buffer_u32); + if(_b > 0) { + _emp = false; + xx = _ind % _w; + yy = floor(_ind / _w); + break; + } + _ind++; + } + #endregion + + var _sx = xx, _sy = yy; + var _px = xx, _py = yy; + var _nx = xx, _ny = yy; + var _amo = _w * _h; + var _rep = 0; + var corner = 0; + + var _a = array_create(_amo); + var _ind = 0; + var _daw = false; + + do { + buffer_write_at(_buff, (yy * _w + xx) * 4, buffer_u32, 0); + + _nx = xx; + _ny = yy; + + if(corner == 1 || corner == 3) _nx++; + if(corner == 2 || corner == 3) _ny++; + + if(_ind == 0 || _px != _nx || _py != _ny) _a[_ind++] = [ _nx, _ny ]; + // print($"{corner} : {[ _nx, _ny ]}"); + + _px = _nx; _py = _ny; + + if(xx < _w - 1 && buffer_read_at(_buff, ((yy ) * _w + xx + 1) * 4, buffer_u32)) { + if(corner == 2) { + _a[_ind++] = [ xx, yy ]; + // print($"{corner} - 0 : {[ xx, yy ]}"); + _px = xx; _py = yy; + + corner = 0; + } + if(corner == 1) corner = 0; + if(corner == 3) corner = 2; + + xx++; + } + else if(yy < _h - 1 && buffer_read_at(_buff, ((yy + 1) * _w + xx ) * 4, buffer_u32)) { + if(corner == 0) { + _a[_ind++] = [ xx + 1, yy ]; + // print($"{corner} - 1 : {[ xx + 1, yy ]}"); + _px = xx + 1; _py = yy; + + corner = 1; + } + if(corner == 2) corner = 0; + if(corner == 3) corner = 1; + + yy++; + } + else if(xx > 0 && buffer_read_at(_buff, ((yy ) * _w + xx - 1) * 4, buffer_u32)) { + if(corner == 1) { + _a[_ind++] = [ xx + 1, yy + 1 ]; + // print($"{corner} - 3 : {[ xx + 1, yy + 1 ]}"); + _px = xx + 1; _py = yy + 1; + + corner = 3; + } + if(corner == 0) corner = 1; + if(corner == 2) corner = 3; + + xx--; + } + else if(yy > 0 && buffer_read_at(_buff, ((yy - 1) * _w + xx ) * 4, buffer_u32)) { + if(corner == 3) { + _a[_ind++] = [ xx, yy + 1 ]; + // print($"{corner} - 2 : {[ xx, yy + 1 ]}"); + _px = xx; _py = yy + 1; + + corner = 2; + } + if(corner == 0) corner = 2; + if(corner == 1) corner = 3; + + yy--; + } + + else if(xx < _w - 1 && yy < _h - 1 && buffer_read_at(_buff, ((yy + 1) * _w + xx + 1) * 4, buffer_u32)) { + if(corner == 0) { _a[_ind++] = [ xx + 1, yy ]; /*print($"{corner} ++ : {[ xx + 1, yy ]}");*/ } + if(corner == 1) { _a[_ind++] = [ xx + 1, yy + 1 ]; /*print($"{corner} ++ : {[ xx + 1, yy + 1 ]}");*/ } + if(corner == 2) { _a[_ind++] = [ xx + 1, yy + 1 ]; /*print($"{corner} ++ : {[ xx + 1, yy + 1 ]}");*/ } + if(corner == 3) { _a[_ind++] = [ xx + 1, yy + 1 ]; /*print($"{corner} ++ : {[ xx + 1, yy + 1 ]}");*/ } + + xx++; yy++; + } + + else if(xx < _w - 1 && yy > 0 && buffer_read_at(_buff, ((yy - 1) * _w + xx + 1) * 4, buffer_u32)) { + if(corner == 0) { _a[_ind++] = [ xx + 1, yy ]; /*print($"{corner} +- : {[ xx + 1, yy ]}");*/ } + if(corner == 1) { _a[_ind++] = [ xx + 1, yy - 1 ]; /*print($"{corner} +- : {[ xx + 1, yy - 1 ]}");*/ } + if(corner == 2) { _a[_ind++] = [ xx, yy ]; /*print($"{corner} +- : {[ xx, yy ]}");*/ } + if(corner == 3) { _a[_ind++] = [ xx + 1, yy ]; /*print($"{corner} +- : {[ xx + 1, yy ]}");*/ } + + xx++; yy--; + } + + else if(xx > 0 && yy < _h - 1 && buffer_read_at(_buff, ((yy + 1) * _w + xx - 1) * 4, buffer_u32)) { + if(corner == 0) { _a[_ind++] = [ xx, yy + 1 ]; /*print($"{corner} -+ : {[ xx, yy + 1 ]}");*/ } + if(corner == 1) { _a[_ind++] = [ xx, yy ]; /*print($"{corner} -+ : {[ xx, yy ]}");*/ } + if(corner == 2) { _a[_ind++] = [ xx - 1, yy + 1 ]; /*print($"{corner} -+ : {[ xx - 1, yy + 1 ]}");*/ } + if(corner == 3) { _a[_ind++] = [ xx, yy + 1 ]; /*print($"{corner} -+ : {[ xx, yy + 1 ]}");*/ } + + xx--; yy++; + } + + else if(xx > 0 && yy > 0 && buffer_read_at(_buff, ((yy - 1) * _w + xx - 1) * 4, buffer_u32)) { + if(corner == 0) { _a[_ind++] = [ xx, yy - 1 ]; /*print($"{corner} -- : {[ xx, yy - 1 ]}");*/ } + if(corner == 1) { _a[_ind++] = [ xx, yy ]; /*print($"{corner} -+ : {[ xx, yy ]}");*/ } + if(corner == 2) { _a[_ind++] = [ xx, yy ]; /*print($"{corner} -+ : {[ xx, yy ]}");*/ } + if(corner == 3) { _a[_ind++] = [ xx + 1, yy ]; /*print($"{corner} -- : {[ xx + 1, yy ]}");*/ } + + xx--; yy--; + } + + if(++_rep >= _amo) break; + } until(xx == _sx && yy == _sy); + + if(xx == _sx && yy > _sy) { //y-- + if(corner == 3) { + _a[_ind++] = [ xx, yy + 1 ]; + _a[_ind++] = [ xx, yy ]; + // print($"{corner} - 2 : {[ xx, yy + 1 ]}"); + // print($"{corner} - 2 : {[ xx, yy ]}"); + } + + } else if(xx == _sx && yy < _sy) { //y++ + if(corner == 0) { + _a[_ind++] = [ xx + 1, yy ]; + _a[_ind++] = [ xx + 1, yy + 1 ]; + // print($"{corner} - 1 : {[ xx + 1, yy ]}"); + // print($"{corner} - 1 : {[ xx + 1, yy + 1 ]}"); + } + + } else if(yy == _sy && xx > _sx) { //x-- + if(corner == 1) { + _a[_ind++] = [ xx + 1, yy + 1 ]; + _a[_ind++] = [ xx, yy + 1 ]; + // print($"{corner} - 3 : {[ xx + 1, yy + 1 ]}"); + // print($"{corner} - 3 : {[ xx, yy + 1 ]}"); + } + + } else if(yy == _sy && xx < _sx) { //x++ + if(corner == 2) { + _a[_ind++] = [ xx, yy ]; + _a[_ind++] = [ xx + 1, yy ]; + // print($"{corner} - 0 : {[ xx, yy ]}"); + // print($"{corner} - 0 : {[ xx + 1, yy ]}"); + } + + } + + // print(_a); + + buffer_delete(_buff); + + anchors = array_verify(anchors, _ind); + var _aind = 0; + var _aamo = _ind; + if(_aamo <= 2) { + anchors = []; + return; + } + + var sx, sy; + var ox, oy, cx, cy; + var dx, dy; + var dd = array_create(_aamo - 1); + + ox = _a[0][0]; + oy = _a[0][1]; + + sx = ox; + sy = oy; + + anchors[_aind++] = new __vec2( sx, sy ); + + for( var i = 1; i < _aamo; i++ ) { + cx = _a[i][0]; + cy = _a[i][1]; + + dx = cx - ox; + dy = cy - oy; + dd[i - 1] = dx * 100 + dy; + // anchors[_aind++] = new __vec2( _a[i][0], _a[i][1] ); + + ox = cx; + oy = cy; + } + + // print(dd); + var len = array_length(dd); + var pattern = [dd[0]]; + var patternLen = 1; + var patternRepeat = 0; + + for (var i = 1; i < len; i++) { // can be done inline, but my tiny brain won't be able to comprehnd it weeks after + // print($"{i}: {patternLen}"); + + if (dd[i] == pattern[patternRepeat % patternLen]) { + + if ((patternRepeat % patternLen) == patternLen - 1) + patternRepeat++; + + } else { + + if (patternRepeat == 0) { + pattern[patternLen] = dd[i]; + patternLen++; + + } else { + anchors[_aind++] = new __vec2( _a[i][0], _a[i][1] ); + + pattern = [dd[i]]; + patternLen = 1; + patternRepeat = -1; + } + } + + patternRepeat++; + } + + array_resize(anchors, _aind); + + // print(anchors); } function stepEffect(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) { @@ -19,31 +284,218 @@ function canvas_tool_corner() : canvas_tool_shader() constructor { var _suf = node.getCanvasSurface(); var _dx = (_mx - mouse_sx) / _s / 4; - amount = clamp(round(_dx), 0, 3); + amount = max(_dx, 0); - surface_set_shader(preview_surface[1], sh_canvas_corner); + if(amount == 0) { + surface_set_shader(preview_surface[1]); + draw_surface(preview_surface[0], 0, 0); + surface_reset_shader(); + return; + } + + var a, b, c; + var d, dr = 0; + + anchorsRounded = []; + for( var i = 0, n = array_length(anchors); i < n; i++ ) { + a = anchors[(i - 1 + n) % n]; + b = anchors[i]; + c = anchors[(i + 1 + n) % n]; - shader_set_f("dimension", _dim); - shader_set_f("amount", amount); - shader_set_surface("base", _suf); + var _dir = sign(angle_difference(point_direction(a.x, a.y, b.x, b.y), point_direction(b.x, b.y, c.x, c.y))); - draw_surface(preview_surface[0], 0, 0); + if(dr == 0) { + dr = _dir; + } else if(dr != _dir) { + array_push(anchorsRounded, new __vec2(b.x, b.y)); + continue; + } + + dr = _dir; + d = calculateCircleCenter(a, b, c, amount); + + var _ox = d.x; + var _oy = d.y; + var _or = d.r; + + var dd = sqrt(sqr(d.d) - sqr(d.r)); + var ba = point_direction(b.x, b.y, a.x, a.y); + var bc = point_direction(b.x, b.y, c.x, c.y); + + var e = new __vec2( b.x + lengthdir_x(dd, ba), b.y + lengthdir_y(dd, ba) ); + var f = new __vec2( b.x + lengthdir_x(dd, bc), b.y + lengthdir_y(dd, bc) ); + + var ee = point_direction(d.x, d.y, e.x, e.y); + var ff = point_direction(d.x, d.y, f.x, f.y); + + var ast = 4; + var ad = angle_difference(ff, ee); + var sgn = sign(ad); + var ar = abs(ad) / ast; + + for( var j = 0; j < ar; j++ ) { + var a = ee + ast * j * sgn; + + nx = _ox + lengthdir_x(_or, a); + ny = _oy + lengthdir_y(_or, a); + + array_push(anchorsRounded, new __vec2(nx, ny)); + } + } + + var _dim = surface_get_dimension(preview_surface[0]); + var mx = mask_boundary_init[0]; + var my = mask_boundary_init[1]; + + temp_surface[1] = surface_verify(temp_surface[1], _dim[0], _dim[1]); + + surface_set_shader(temp_surface[1], noone); + if(array_length(anchorsRounded) >= 3) { + var _pTri = polygon_triangulate(anchorsRounded); + var triangles = _pTri[0]; + + draw_set_color(c_white); + draw_primitive_begin(pr_trianglelist); + for( var i = 0, n = array_length(triangles); i < n; i++ ) { + var tri = triangles[i]; + var p0 = tri[0]; + var p1 = tri[1]; + var p2 = tri[2]; + + draw_vertex(mx + p0.x, my + p0.y); + draw_vertex(mx + p1.x, my + p1.y); + draw_vertex(mx + p2.x, my + p2.y); + } + draw_primitive_end(); + } else + draw_clear(c_white); surface_reset_shader(); + surface_set_shader(preview_surface[1], noone); + draw_surface(preview_surface[0], 0, 0); + + BLEND_MULTIPLY + draw_surface(temp_surface[1], 0, 0); + BLEND_NORMAL + + surface_reset_shader(); + + // surface_set_shader(preview_surface[1], sh_canvas_corner); + + // shader_set_f("dimension", _dim); + // shader_set_f("amount", amount); + // shader_set_surface("base", _suf); + + // draw_surface(preview_surface[0], 0, 0); + // surface_reset_shader(); + } function drawPostOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) { if(!modifying) return; - var _x0 = mouse_sx; - var _y0 = mouse_sy; + if(array_length(anchorsRounded) >= 3) { - var _x1 = _x0 + amount * _s * 4; + draw_set_color(COLORS._main_accent); + var ox, oy, nx, ny, sx, sy; + var mx = mask_boundary_init[0]; + var my = mask_boundary_init[1]; + + ox = anchorsRounded[0].x; + oy = anchorsRounded[0].y; + + sx = ox; + sy = oy; + + for( var i = 1, n = array_length(anchorsRounded); i < n; i++ ) { + nx = anchorsRounded[i].x; + ny = anchorsRounded[i].y; + + draw_line(_x + (mx + ox) * _s, _y + (my + oy) * _s, + _x + (mx + nx) * _s, _y + (my + ny) * _s); + + ox = nx; + oy = ny; + } + + draw_line(_x + (mx + ox) * _s, _y + (my + oy) * _s, + _x + (mx + sx) * _s, _y + (my + sy) * _s); + + } else if(array_length(anchors) >= 3) { + + draw_set_color(COLORS._main_accent); + var ox, oy, nx, ny, sx, sy; + var mx = mask_boundary_init[0]; + var my = mask_boundary_init[1]; + + ox = anchors[0].x; + oy = anchors[0].y; + + sx = ox; + sy = oy; + + for( var i = 1, n = array_length(anchors); i < n; i++ ) { + nx = anchors[i].x; + ny = anchors[i].y; + + draw_line(_x + (mx + ox) * _s, _y + (my + oy) * _s, + _x + (mx + nx) * _s, _y + (my + ny) * _s); + + ox = nx; + oy = ny; + } + + draw_line(_x + (mx + ox) * _s, _y + (my + oy) * _s, + _x + (mx + sx) * _s, _y + (my + sy) * _s); + + } - draw_set_color(COLORS._main_accent); - draw_line(_x0, _y0, _x1, _y0); - - draw_circle(_x1, _y0, 5, false); + + // var a, b, c; + // var d; + // for( var i = 0, n = array_length(anchors); i < n; i++ ) { + // a = anchors[(i - 1 + n) % n]; + // b = anchors[i]; + // c = anchors[(i + 1 + n) % n]; + + // d = calculateCircleCenter(a, b, c, amount); + + // var _ox = _x + (mx + d[0]) * _s; + // var _oy = _y + (my + d[1]) * _s; + // var _or = d[2] * _s; + + // var dd = sqrt(sqr(d[3]) - sqr(d[2])); + // var ba = point_direction(b[0], b[1], a[0], a[1]); + // var bc = point_direction(b[0], b[1], c[0], c[1]); + + // var e = [ b[0] + lengthdir_x(dd, ba), b[1] + lengthdir_y(dd, ba) ]; + // var f = [ b[0] + lengthdir_x(dd, bc), b[1] + lengthdir_y(dd, bc) ]; + + // var ee = point_direction(d[0], d[1], e[0], e[1]); + // var ff = point_direction(d[0], d[1], f[0], f[1]); + + // // draw_circle(_ox, _oy, _or, true); + // draw_arc(_ox, _oy, _or, ee, ff, 1, 90); + // } } +} + +function calculateCircleCenter(a, b, c, r) { + + var ba = point_direction(b.x, b.y, a.x, a.y); + var bc = point_direction(b.x, b.y, c.x, c.y); + var da = point_distance(b.x, b.y, a.x, a.y); + var dc = point_distance(b.x, b.y, c.x, c.y); + r = min(r, da / 2, dc / 2); + + var a2 = angle_difference(bc, ba) / 2; + var dd = r / dsin(a2); + + return { + x: b.x + lengthdir_x(dd, ba + a2), + y: b.y + lengthdir_y(dd, ba + a2), + r: r, + d: dd, + }; } \ No newline at end of file diff --git a/scripts/draw_arc/draw_arc.gml b/scripts/draw_arc/draw_arc.gml index 501219e29..76d59d03b 100644 --- a/scripts/draw_arc/draw_arc.gml +++ b/scripts/draw_arc/draw_arc.gml @@ -1,8 +1,9 @@ function draw_arc(_x, _y, _r, _as, _at, _th = 1, _pr = 32) { var ox, oy, nx, ny; var ast = 360 / _pr; - var sgn = sign(_at - _as); - var ar = abs(_at - _as) / 360 * _pr; + var ad = angle_difference(_at, _as); + var sgn = sign(ad); + var ar = abs(ad) / 360 * _pr; for( var i = 0; i < ar; i++ ) { var a = _as + ast * i * sgn; diff --git a/scripts/node_canvas/node_canvas.gml b/scripts/node_canvas/node_canvas.gml index c1f297e4b..944b7f110 100644 --- a/scripts/node_canvas/node_canvas.gml +++ b/scripts/node_canvas/node_canvas.gml @@ -210,6 +210,7 @@ function Node_Canvas(_x, _y, _group = noone) : Node(_x, _y, _group) constructor brush = new canvas_brush(); tool_selection = new canvas_tool_selection(); + tool_selection.node = self; tool_brush = new canvas_tool_brush(brush, false); tool_eraser = new canvas_tool_brush(brush, true); @@ -717,11 +718,11 @@ function Node_Canvas(_x, _y, _group = noone) : Node(_x, _y, _group) constructor } } + tool_selection.drawing_surface = drawing_surface; + tool_selection._canvas_surface = _canvas_surface; + tool_selection.apply_draw_surface = apply_draw_surface; + if(tool_selection.is_selected) { - tool_selection.node = self; - tool_selection.drawing_surface = drawing_surface; - tool_selection._canvas_surface = _canvas_surface; - tool_selection.apply_draw_surface = apply_draw_surface; tool_selection.step(hover, active, _x, _y, _s, _mx, _my, _snx, _sny); tool_mirror_edit.sprs = (!tool_selection.is_selected && tool_attribute.mirror[0])? THEME.canvas_mirror_diag : THEME.canvas_mirror; diff --git a/scripts/node_pin/node_pin.gml b/scripts/node_pin/node_pin.gml index 4e89417f8..1faeb13f5 100644 --- a/scripts/node_pin/node_pin.gml +++ b/scripts/node_pin/node_pin.gml @@ -19,29 +19,28 @@ function Node_Pin(_x, _y, _group = noone) : Node(_x, _y, _group) constructor { outputs[| 0] = nodeValue("Out", self, JUNCTION_CONNECT.output, VALUE_TYPE.any, 0); - static step = function() { #region - if(inputs[| 0].value_from == noone) return; + static update = function() { + if(inputs[| 0].value_from != noone) { - inputs[| 0].setType(inputs[| 0].value_from.type); - outputs[| 0].setType(inputs[| 0].value_from.type); + inputs[| 0].setType(inputs[| 0].value_from.type); + outputs[| 0].setType(inputs[| 0].value_from.type); + + inputs[| 0].color_display = inputs[| 0].value_from.color_display; + outputs[| 0].color_display = inputs[| 0].color_display; + } - inputs[| 0].color_display = inputs[| 0].value_from.color_display; - outputs[| 0].color_display = inputs[| 0].color_display; - } #endregion - - static update = function() { #region var _val = getInputData(0); outputs[| 0].setValue(_val); - } #endregion + } - static pointIn = function(_x, _y, _mx, _my, _s) { #region + static pointIn = function(_x, _y, _mx, _my, _s) { var xx = x * _s + _x; var yy = y * _s + _y; return point_in_circle(_mx, _my, xx, yy, _s * 24); - } #endregion + } - static preDraw = function(_x, _y, _s) { #region + static preDraw = function(_x, _y, _s) { var xx = x * _s + _x; var yy = y * _s + _y; @@ -50,12 +49,12 @@ function Node_Pin(_x, _y, _group = noone) : Node(_x, _y, _group) constructor { outputs[| 0].x = xx; outputs[| 0].y = yy; - } #endregion + } static drawBadge = function(_x, _y, _s) {} static drawJunctionNames = function(_x, _y, _mx, _my, _s) {} - static drawJunctions = function(_x, _y, _mx, _my, _s) { #region + static drawJunctions = function(_x, _y, _mx, _my, _s) { var _dval = PANEL_GRAPH.value_dragging; var hover = _dval == noone || _dval.connect_type == JUNCTION_CONNECT.input? outputs[| 0] : inputs[| 0]; @@ -69,9 +68,9 @@ function Node_Pin(_x, _y, _group = noone) : Node(_x, _y, _group) constructor { hover_scale_to = 1; return jhov? hover : noone; - } #endregion + } - static drawNode = function(_x, _y, _mx, _my, _s) { #region + static drawNode = function(_x, _y, _mx, _my, _s) { var xx = x * _s + _x; var yy = y * _s + _y; @@ -100,5 +99,5 @@ function Node_Pin(_x, _y, _group = noone) : Node(_x, _y, _group) constructor { } return drawJunctions(_x, _y, _mx, _my, _s); - } #endregion + } } \ No newline at end of file diff --git a/scripts/node_value/node_value.gml b/scripts/node_value/node_value.gml index 3ede1e4fb..56227f005 100644 --- a/scripts/node_value/node_value.gml +++ b/scripts/node_value/node_value.gml @@ -1140,6 +1140,7 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru if(connect_type == JUNCTION_CONNECT.output) return val; + if(type == VALUE_TYPE.integer || type == VALUE_TYPE.float) print($"{typ == VALUE_TYPE.surface}"); if(typ == VALUE_TYPE.surface && (type == VALUE_TYPE.integer || type == VALUE_TYPE.float)) { #region Dimension conversion if(is_array(val)) { var eqSize = true; @@ -1149,7 +1150,7 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru for( var i = 0, n = array_length(val); i < n; i++ ) { if(!is_surface(val[i])) continue; - var surfSz = [ surface_get_width_safe(val[i]), surface_get_height_safe(val[i]) ]; + var surfSz = surface_get_dimension(val[i]); array_push(sArr, surfSz); if(i && !array_equals(surfSz, _osZ)) diff --git a/scripts/svg_objects/svg_objects.gml b/scripts/svg_objects/svg_objects.gml index 517c3c368..cd28dbe3d 100644 --- a/scripts/svg_objects/svg_objects.gml +++ b/scripts/svg_objects/svg_objects.gml @@ -171,8 +171,6 @@ function SVG_path(svgObj = noone) : SVGElement(svgObj) constructor { _pTri[3] = _ctri; shapes[i] = _pTri; - - // print($"{i}: {array_length(_pTri[0])} - {_pTri[2]}"); } } diff --git a/shaders/sh_image_trace/sh_image_trace.fsh b/shaders/sh_image_trace/sh_image_trace.fsh index df1bf1cb4..366e590e4 100644 --- a/shaders/sh_image_trace/sh_image_trace.fsh +++ b/shaders/sh_image_trace/sh_image_trace.fsh @@ -2,15 +2,14 @@ varying vec2 v_vTexcoord; varying vec4 v_vColour; uniform vec2 dimension; - vec2 tx; bool sample(float x, float y) { vec2 pos = v_vTexcoord + vec2(tx.x * x, tx.y * y); - if(pos.x < 0. || pos.y < 0. || pos.x > 1. || pos.y > 1.) return false; + if(pos.x < 0. || pos.y < 0. || pos.x > 1. || pos.y > 1.) return true; vec4 c = texture2D( gm_BaseTexture, pos ); - return (c.r + c.g + c.b) * c.a > 0.; + return (c.r + c.g + c.b) * c.a == 0.; } void main() { @@ -18,10 +17,18 @@ void main() { vec4 cc = texture2D( gm_BaseTexture, v_vTexcoord ); gl_FragColor = vec4(0.); - if(cc.r == 0.) return; + if(cc.a == 0.) return; - if(!sample(-1., 0.)) { gl_FragColor = vec4(1.); return; } - if(!sample( 1., 0.)) { gl_FragColor = vec4(1.); return; } - if(!sample(0., -1.)) { gl_FragColor = vec4(1.); return; } - if(!sample(0., 1.)) { gl_FragColor = vec4(1.); return; } + bool s1 = sample(-1., 0.); + bool s2 = sample( 1., 0.); + bool s3 = sample(0., -1.); + bool s4 = sample(0., 1.); + + if(s1 && s2) return; + if(s3 && s4) return; + + if(s1) { gl_FragColor = vec4(1.); return; } + if(s2) { gl_FragColor = vec4(1.); return; } + if(s3) { gl_FragColor = vec4(1.); return; } + if(s4) { gl_FragColor = vec4(1.); return; } }