2023-03-19 09:17:39 +01:00
|
|
|
function Node_Strand_Gravity(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
|
2023-12-22 08:42:02 +01:00
|
|
|
name = "Strand Gravity";
|
2023-03-19 09:17:39 +01:00
|
|
|
color = COLORS.node_blend_strand;
|
|
|
|
icon = THEME.strandSim;
|
2024-05-02 12:13:35 +02:00
|
|
|
setDimension(96, 48);;
|
2023-12-22 08:42:02 +01:00
|
|
|
|
|
|
|
manual_ungroupable = false;
|
2023-03-19 09:17:39 +01:00
|
|
|
|
2024-08-20 10:15:53 +02:00
|
|
|
newInput(0, 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(1, nodeValue_Float("Gravity", self, 1));
|
2023-03-19 09:17:39 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(2, nodeValue_Rotation("Direction", self, 0));
|
2023-03-19 09:17:39 +01:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
outputs[0] = nodeValue_Output("Strand", self, VALUE_TYPE.strands, noone);
|
2023-03-19 09:17:39 +01:00
|
|
|
|
2023-10-09 16:07:33 +02:00
|
|
|
static update = function(frame = CURRENT_FRAME) {
|
2023-10-02 08:57:44 +02:00
|
|
|
var _str = getInputData(0);
|
|
|
|
var _gra = getInputData(1);
|
|
|
|
var _dir = getInputData(2);
|
2023-03-19 09:17:39 +01:00
|
|
|
|
|
|
|
if(_str == noone) return;
|
|
|
|
var __str = _str;
|
|
|
|
if(!is_array(_str)) __str = [ _str ];
|
|
|
|
|
|
|
|
var gx = lengthdir_x(_gra, _dir);
|
|
|
|
var gy = lengthdir_y(_gra, _dir);
|
|
|
|
|
|
|
|
for( var k = 0; k < array_length(__str); k++ )
|
2023-07-25 20:12:40 +02:00
|
|
|
for( var i = 0, n = array_length(__str[k].hairs); i < n; i++ ) {
|
2023-03-19 09:17:39 +01:00
|
|
|
var h = __str[k].hairs[i];
|
|
|
|
|
|
|
|
for( var j = 1; j < array_length(h.points); j++ ) {
|
|
|
|
h.points[j].x += gx;
|
|
|
|
h.points[j].y += gy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
outputs[0].setValue(_str);
|
2023-03-19 09:17:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
|
|
|
|
var bbox = drawGetBbox(xx, yy, _s);
|
|
|
|
draw_sprite_fit(s_node_strandSim_gravity, 0, bbox.xc, bbox.yc, bbox.w, bbox.h);
|
|
|
|
}
|
|
|
|
}
|