2023-03-19 09:17:39 +01:00
|
|
|
function Node_Strand_Render(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
|
2023-12-22 08:42:02 +01:00
|
|
|
name = "Strand Render";
|
2023-03-19 09:17:39 +01:00
|
|
|
color = COLORS.node_blend_strand;
|
|
|
|
icon = THEME.strandSim;
|
2023-10-02 14:41:44 +02:00
|
|
|
use_cache = CACHE_USE.auto;
|
2023-03-19 09:17:39 +01:00
|
|
|
|
2023-12-22 08:42:02 +01:00
|
|
|
manual_ungroupable = false;
|
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(0, nodeValue_Dimension(self));
|
2023-03-19 09:17:39 +01:00
|
|
|
|
2024-08-20 10:15:53 +02:00
|
|
|
newInput(1, nodeValue("Strand", self, CONNECT_TYPE.input, VALUE_TYPE.strands, noone))
|
2023-03-19 09:17:39 +01:00
|
|
|
.setVisible(true, true);
|
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(2, nodeValue_Range("Thickness", self, [ 1, 1 ], { linked : true }));
|
2023-03-19 09:17:39 +01:00
|
|
|
|
2024-08-20 10:15:53 +02:00
|
|
|
newInput(3, nodeValue("Thickness over length", self, CONNECT_TYPE.input, VALUE_TYPE.curve, CURVE_DEF_11));
|
2023-03-19 09:17:39 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(4, nodeValue_Gradient("Random color", self, new gradientObject(cola(c_white))));
|
2023-03-19 09:17:39 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(5, nodeValue_Gradient("Color over length", self, new gradientObject(cola(c_white))));
|
2023-03-19 09:17:39 +01:00
|
|
|
|
2024-08-18 09:13:41 +02:00
|
|
|
newInput(6, nodeValue_Float("Seed", self, seed_random(6)))
|
2024-08-08 06:57:51 +02:00
|
|
|
.setDisplay(VALUE_DISPLAY._default, { side_button : button(function() { randomize(); inputs[6].setValue(seed_random(6)); }).setIcon(THEME.icon_random, 0, COLORS._main_icon) });
|
2023-03-19 09:17:39 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(7, nodeValue_Float("Child", self, 0, "Render extra strands between the real strands."));
|
2023-03-19 09:17:39 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(8, nodeValue_Int("Update quality", self, 4));
|
2023-12-18 08:27:31 +01:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
outputs[0] = nodeValue_Output("Surface out", self, VALUE_TYPE.surface, noone);
|
2023-03-19 09:17:39 +01:00
|
|
|
|
2023-12-18 08:27:31 +01:00
|
|
|
input_display_list = [ 6, 8,
|
2023-03-19 09:17:39 +01:00
|
|
|
["Output", false], 0,
|
|
|
|
["Strand", false], 7, 1, 2, 3,
|
|
|
|
["Color", false], 4, 5,
|
|
|
|
];
|
|
|
|
|
|
|
|
insp2UpdateTooltip = "Clear cache";
|
|
|
|
insp2UpdateIcon = [ THEME.cache, 0, COLORS._main_icon ];
|
|
|
|
|
|
|
|
static onInspector2Update = function() { clearCache(); }
|
|
|
|
|
2024-03-14 14:35:19 +01:00
|
|
|
static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) { #region
|
2023-10-02 08:57:44 +02:00
|
|
|
var _str = getInputData(1);
|
2023-03-19 09:17:39 +01:00
|
|
|
if(_str == noone) return;
|
|
|
|
if(!is_array(_str)) _str = [ _str ];
|
|
|
|
|
2023-07-25 20:12:40 +02:00
|
|
|
for( var i = 0, n = array_length(_str); i < n; i++ )
|
2023-03-19 09:17:39 +01:00
|
|
|
_str[i].draw(_x, _y, _s);
|
2023-12-18 08:27:31 +01:00
|
|
|
} #endregion
|
2023-03-19 09:17:39 +01:00
|
|
|
|
2023-10-09 16:07:33 +02:00
|
|
|
static update = function(frame = CURRENT_FRAME) {
|
2023-07-06 19:49:16 +02:00
|
|
|
if(!PROJECT.animator.is_playing && recoverCache()) return;
|
2023-03-19 09:17:39 +01:00
|
|
|
|
2023-10-02 08:57:44 +02:00
|
|
|
var _dim = getInputData(0);
|
|
|
|
var _str = getInputData(1);
|
|
|
|
var _thk = getInputData(2);
|
|
|
|
var _tln = getInputData(3);
|
|
|
|
var _bld = getInputData(4);
|
|
|
|
var _col = getInputData(5);
|
|
|
|
var _sed = getInputData(6);
|
|
|
|
var _chd = getInputData(7);
|
2023-12-18 08:27:31 +01:00
|
|
|
var _stp = getInputData(8);
|
2023-03-19 09:17:39 +01:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
var _surf = outputs[0].getValue();
|
2023-03-19 09:17:39 +01:00
|
|
|
_surf = surface_verify(_surf, _dim[0], _dim[1]);
|
2024-08-08 06:57:51 +02:00
|
|
|
outputs[0].setValue(_surf);
|
2023-03-19 09:17:39 +01:00
|
|
|
|
|
|
|
if(_str == noone) return;
|
|
|
|
if(!is_array(_str)) _str = [ _str ];
|
|
|
|
|
|
|
|
random_set_seed(_sed);
|
|
|
|
var _sedIndex = 0;
|
|
|
|
|
|
|
|
surface_set_target(_surf);
|
|
|
|
DRAW_CLEAR
|
|
|
|
var h0 = [], h1 = [];
|
|
|
|
|
|
|
|
for( var h = 0; h < array_length(_str); h++ ) {
|
|
|
|
var _strand = _str[h];
|
|
|
|
var hairs = _strand.hairs;
|
|
|
|
|
2023-12-18 08:27:31 +01:00
|
|
|
if(_stp) _strand.step(_stp);
|
|
|
|
|
2023-07-25 20:12:40 +02:00
|
|
|
for( var i = 0, n = array_length(hairs); i < n; i++ ) {
|
2023-03-19 09:17:39 +01:00
|
|
|
var hair = hairs[i];
|
|
|
|
var os, ns, ot, nt;
|
|
|
|
|
|
|
|
var len = array_length(hair.points);
|
|
|
|
var bld = _bld.eval(random1D(_sed + _sedIndex)); _sedIndex++;
|
|
|
|
var clr = c_black;
|
|
|
|
|
|
|
|
for( var j = 0; j < len; j++ ) {
|
|
|
|
ns = hair.points[j];
|
|
|
|
nt = eval_curve_x(_tln, j / (len - 1));
|
|
|
|
nt *= random1D(_sed + _sedIndex, _thk[0], _thk[1]); _sedIndex++;
|
|
|
|
|
|
|
|
if(j) {
|
|
|
|
clr = _col.eval(j / (len - 1));
|
|
|
|
clr = colorMultiply(bld, clr);
|
|
|
|
draw_set_color(clr);
|
|
|
|
draw_line_width2(os.x, os.y, ns.x, ns.y, ot, nt, 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
ot = nt;
|
|
|
|
os = ns;
|
|
|
|
|
|
|
|
h1[j] = [ nt, clr ];
|
|
|
|
}
|
|
|
|
|
|
|
|
if(_chd && (i > 0 || _strand.loop)) {
|
|
|
|
var hair0 = i == 0? hairs[array_length(hairs) - 1] : hairs[i - 1];
|
|
|
|
|
|
|
|
for( var j = 1; j < _chd + 1; j++ ) {
|
|
|
|
var lrp = j / (_chd + 1);
|
|
|
|
|
|
|
|
var ox, oy, nx, ny, ot, nt, oc, nc;
|
|
|
|
for( var k = 0; k < len; k++ ) {
|
|
|
|
var nx0 = hair0.points[k].x;
|
|
|
|
var ny0 = hair0.points[k].y;
|
|
|
|
|
|
|
|
var nx1 = hair.points[k].x;
|
|
|
|
var ny1 = hair.points[k].y;
|
|
|
|
|
|
|
|
nx = lerp(nx0, nx1, lrp);
|
|
|
|
ny = lerp(ny0, ny1, lrp);
|
|
|
|
|
|
|
|
if(k) {
|
|
|
|
ot = i == 0? h1[k][0] : h0[k][0];
|
|
|
|
nt = h1[k][0];
|
|
|
|
|
|
|
|
oc = i == 0? h1[k][1] : h0[k][1];
|
|
|
|
nc = h1[k][1];
|
|
|
|
|
|
|
|
draw_set_color(merge_color(oc, nc, lrp));
|
|
|
|
draw_line_width2(ox, oy, nx, ny, ot, nt, 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
ox = nx;
|
|
|
|
oy = ny;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
h0 = array_clone(h1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
surface_reset_target();
|
|
|
|
cacheCurrentFrame(_surf);
|
|
|
|
}
|
|
|
|
}
|