[Draw Line] Add force loop option.

This commit is contained in:
Tanasart 2024-12-22 16:18:56 +07:00
parent 2947485630
commit 41b47a4b04
2 changed files with 71 additions and 53 deletions

View file

@ -81,9 +81,11 @@ function Node_Line(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) cons
newInput(34, nodeValue_Enum_Scroll("SSAA", self, 0, [ "None", "2x", "4x", "8x" ])); newInput(34, nodeValue_Enum_Scroll("SSAA", self, 0, [ "None", "2x", "4x", "8x" ]));
newInput(35, nodeValue_Bool("Force Loop", self, false));
input_display_list = [ input_display_list = [
["Output", true], 0, 1, 30, 31, ["Output", true], 0, 1, 30, 31,
["Line data", false], 27, 6, 7, 28, 32, 33, 19, 2, 20, ["Line data", false], 27, 6, 7, 28, 32, 33, 35, 19, 2, 20,
["Line settings", false], 17, 3, 11, 12, 8, 25, 9, 26, 13, 14, ["Line settings", false], 17, 3, 11, 12, 8, 25, 9, 26, 13, 14,
["Wiggle", false], 4, 5, ["Wiggle", false], 4, 5,
["Render", false], 10, 24, 15, 16, 34, ["Render", false], 10, 24, 15, 16, 34,
@ -229,6 +231,8 @@ function Node_Line(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) cons
var _pnt1 = _data[33]; var _pnt1 = _data[33];
var _aa = power(2, _data[34]); var _aa = power(2, _data[34]);
var _loop = _data[35];
if(_dtype == 1 && _pat == noone) if(_dtype == 1 && _pat == noone)
_dtype = 0; _dtype = 0;
@ -457,6 +461,7 @@ function Node_Line(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) cons
} }
array_resize(points, pointAmo); array_resize(points, pointAmo);
if(_loop) points[pointAmo] = points[0];
lines[_lineAmo] = points; lines[_lineAmo] = points;
line_data[_lineAmo] = { length: _pathLength }; line_data[_lineAmo] = { length: _pathLength };
@ -503,24 +508,35 @@ function Node_Line(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) cons
if(_uselen) { if(_uselen) {
for (var j = 0; j < m; j++) { for (var j = 0; j < m; j++) {
_lin[j] = { x: _seg[j][0], y: _seg[j][1], prog: _seg[j][2], progCrop: _seg[j][2], weight: 1 }; _lin[j] = {
x : _seg[j][0],
minx = min(minx, _lin[j].x); y : _seg[j][1],
miny = min(miny, _lin[j].y); prog : _seg[j][2],
maxx = max(maxx, _lin[j].x); progCrop : _seg[j][2],
maxy = max(maxy, _lin[j].y); weight : 1,
};
} }
} else { } else {
for (var j = 0; j < m; j++) { for (var j = 0; j < m; j++) {
_lin[j] = { x: _seg[j][0], y: _seg[j][1], prog: _len[j] / _lenTotal, progCrop: _len[j] / _lenTotal, weight: 1 }; _lin[j] = {
x : _seg[j][0],
y : _seg[j][1],
prog : _len[j] / _lenTotal,
progCrop : _len[j] / _lenTotal,
weight : 1,
};
}
}
if(_loop) _lin[m] = _lin[0];
for (var j = 0; j < m; j++) {
minx = min(minx, _lin[j].x); minx = min(minx, _lin[j].x);
miny = min(miny, _lin[j].y); miny = min(miny, _lin[j].y);
maxx = max(maxx, _lin[j].x); maxx = max(maxx, _lin[j].x);
maxy = max(maxy, _lin[j].y); maxy = max(maxy, _lin[j].y);
} }
}
lines[i] = _lin; lines[i] = _lin;
line_data[i] = { length: _lenTotal }; line_data[i] = { length: _lenTotal };

View file

@ -11,7 +11,7 @@ function Node_Path_Wave(_x, _y, _group = noone) : Node(_x, _y, _group) construct
newInput(3, nodeValue_Range("Shift", self, [ 0, 0 ], { linked : true })); newInput(3, nodeValue_Range("Shift", self, [ 0, 0 ], { linked : true }));
newInput(4, nodeValue_Bool("Smooth", self, false)); newInput(4, nodeValue_Enum_Button("Mode", self, 0, [ "Zigzag", "Sine", "Square" ]));
newInput(5, nodeValueSeed(self)); newInput(5, nodeValueSeed(self));
@ -35,7 +35,7 @@ function Node_Path_Wave(_x, _y, _group = noone) : Node(_x, _y, _group) construct
fre = 0; fre = 0;
amp = 0; amp = 0;
shf = 0; shf = 0;
smt = 0; mode = 0;
seed = 0; seed = 0;
wig = 0 wig = 0
@ -125,7 +125,6 @@ function Node_Path_Wave(_x, _y, _group = noone) : Node(_x, _y, _group) construct
var _fre = fre ; var _fre = fre ;
var _amp = amp ; var _amp = amp ;
var _shf = shf ; var _shf = shf ;
var _smt = smt ;
var _seed = seed + ind; var _seed = seed + ind;
var _wig = wig ; var _wig = wig ;
@ -159,8 +158,11 @@ function Node_Path_Wave(_x, _y, _group = noone) : Node(_x, _y, _group) construct
var dir = point_direction(p0.x, p0.y, p1.x, p1.y) + 90; var dir = point_direction(p0.x, p0.y, p1.x, p1.y) + 90;
var prg; var prg;
if(_smt) prg = cos(_t * pi * 2); switch(mode) {
else prg = (abs(frac(_t) * 2 - 1) - 0.5) * 2; case 0 : prg = (abs(frac(_t) * 2 - 1) - 0.5) * 2; break;
case 1 : prg = cos(_t * pi * 2); break;
case 2 : prg = (frac(_t) > .5) * 2 - 1; break;
}
if(amp_curve) prg *= amp_curve.get(_rat); if(amp_curve) prg *= amp_curve.get(_rat);
@ -184,7 +186,7 @@ function Node_Path_Wave(_x, _y, _group = noone) : Node(_x, _y, _group) construct
fre = getInputData(1); fre = getInputData(1);
amp = getInputData(2); amp = getInputData(2);
shf = getInputData(3); shf = getInputData(3);
smt = getInputData(4); mode = getInputData(4);
seed = getInputData(5); seed = getInputData(5);
wig = getInputData(6); wig = getInputData(6);