Pixel-Composer/scripts/node_strand_collision/node_strand_collision.gml

56 lines
1.6 KiB
Plaintext
Raw Normal View History

2023-03-19 09:17:39 +01:00
function Node_Strand_Collision(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
name = "Strand Collision";
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);;
manual_ungroupable = false;
2023-03-19 09:17:39 +01:00
inputs[| 0] = nodeValue("Strand", self, JUNCTION_CONNECT.input, VALUE_TYPE.strands, noone)
.setVisible(true, true);
inputs[| 1] = nodeValue("Collision mesh", self, JUNCTION_CONNECT.input, VALUE_TYPE.mesh, noone)
.setVisible(true, true);
outputs[| 0] = nodeValue("Strand", self, JUNCTION_CONNECT.output, VALUE_TYPE.strands, noone);
2024-03-14 14:35:19 +01:00
static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
var _msh = getInputData(1);
2023-03-19 09:17:39 +01:00
if(_msh == noone) return;
draw_set_color(COLORS._main_accent);
_msh.draw(_x, _y, _s);
}
2023-10-09 16:07:33 +02:00
static update = function(frame = CURRENT_FRAME) {
var _str = getInputData(0);
var _msh = getInputData(1);
2023-03-19 09:17:39 +01:00
if(_str == noone) return;
var __str = _str;
if(!is_array(_str)) __str = [ _str ];
if(instanceof(_msh) != "Mesh") return;
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++ ) {
var p = h.points[j];
if(_msh.pointIn(p.x, p.y)) {
p.x = p.px;
p.y = p.py;
}
}
}
outputs[| 0].setValue(_str);
}
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
var bbox = drawGetBbox(xx, yy, _s);
draw_sprite_fit(s_node_strandSim_collide, 0, bbox.xc, bbox.yc, bbox.w, bbox.h);
}
}