Pixel-Composer/scripts/node_smoke_add/node_smoke_add.gml

129 lines
4.1 KiB
Text
Raw Normal View History

2024-03-19 09:49:29 +01:00
function Node_Smoke_Add(_x, _y, _group = noone) : Node_Smoke(_x, _y, _group) constructor {
2023-11-10 11:32:46 +01:00
name = "Add Emitter";
color = COLORS.node_blend_smoke;
icon = THEME.smoke_sim;
2024-03-28 14:18:02 +01:00
setDimension(96, 96);
2023-02-14 02:48:33 +01:00
manual_ungroupable = false;
2023-12-29 14:30:54 +01:00
inputs[| 0] = nodeValue("Domain", self, JUNCTION_CONNECT.input, VALUE_TYPE.sdomain, noone)
2023-02-14 02:48:33 +01:00
.setVisible(true, true);
inputs[| 1] = nodeValue("Fluid brush", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone);
2023-12-18 13:54:33 +01:00
inputs[| 2] = nodeValue("Position", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, [0, 0])
2023-02-14 02:48:33 +01:00
.setDisplay(VALUE_DISPLAY.vector);
inputs[| 3] = nodeValue("Active", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true);
inputs[| 4] = nodeValue("Inherit velocity", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0)
.setDisplay(VALUE_DISPLAY.slider, { range: [ -1, 1, 0.01 ] });
2023-02-14 02:48:33 +01:00
inputs[| 5] = nodeValue("Density", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1)
.setDisplay(VALUE_DISPLAY.slider);
2023-02-14 02:48:33 +01:00
2023-09-26 14:35:25 +02:00
inputs[| 6] = nodeValue("Expand velocity mask", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0);
inputs[| 7] = nodeValue("Velocity", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [0, 0])
.setDisplay(VALUE_DISPLAY.vector);
2023-02-14 02:48:33 +01:00
input_display_list = [
2023-09-26 14:35:25 +02:00
["Domain", false], 0,
["Fluid", false], 3, 1, 5, 2,
["Velocity", false], 7, 4, 6,
2023-02-14 02:48:33 +01:00
];
2023-09-26 14:35:25 +02:00
_prevPos = noone;
2023-12-29 14:30:54 +01:00
outputs[| 0] = nodeValue("Domain", self, JUNCTION_CONNECT.output, VALUE_TYPE.sdomain, noone);
2023-02-14 02:48:33 +01:00
2023-10-07 09:09:18 +02:00
temp_surface = [ surface_create(1, 1) ];
2024-03-14 14:35:19 +01:00
static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) { #region
var _mat = getInputData(1);
var _pos = getInputData(2);
2023-02-14 02:48:33 +01:00
if(is_surface(_mat)) {
2023-09-08 21:37:36 +02:00
var sw = surface_get_width_safe(_mat) * _s;
var sh = surface_get_height_safe(_mat) * _s;
2023-02-14 02:48:33 +01:00
var mx = _x + _pos[0] * _s - sw / 2;
var my = _y + _pos[1] * _s - sh / 2;
2023-03-19 09:17:39 +01:00
draw_surface_ext_safe(_mat, mx, my, _s, _s, 0, c_white, 0.5);
2023-02-14 02:48:33 +01:00
}
2024-03-14 14:35:19 +01:00
inputs[| 2].drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
2023-09-26 14:35:25 +02:00
} #endregion
2023-02-14 02:48:33 +01:00
2023-10-09 16:07:33 +02:00
static update = function(frame = CURRENT_FRAME) {
2023-02-14 02:48:33 +01:00
var _dom = inputs[| 0].getValue(frame);
var _mat = inputs[| 1].getValue(frame);
var _pos = inputs[| 2].getValue(frame);
var _act = inputs[| 3].getValue(frame);
var _inh = inputs[| 4].getValue(frame);
var _den = inputs[| 5].getValue(frame);
2023-09-26 14:35:25 +02:00
var _msk = inputs[| 6].getValue(frame);
var _vel = inputs[| 7].getValue(frame);
2023-02-14 02:48:33 +01:00
2023-10-07 09:09:18 +02:00
FLUID_DOMAIN_CHECK
2023-02-14 02:48:33 +01:00
outputs[| 0].setValue(_dom);
if(!_act) return;
if(!is_surface(_mat)) return;
2023-09-08 21:37:36 +02:00
var sw = surface_get_width_safe(_mat);
var sh = surface_get_height_safe(_mat);
2023-02-14 02:48:33 +01:00
2023-09-26 14:35:25 +02:00
var dx = _vel[0];
var dy = _vel[1];
2023-02-14 02:48:33 +01:00
if(_prevPos != noone && _inh != 0) {
2023-09-26 14:35:25 +02:00
dx += (_pos[0] - _prevPos[0]) * _inh;
dy += (_pos[1] - _prevPos[1]) * _inh;
}
2023-10-07 09:09:18 +02:00
temp_surface[0] = surface_verify(temp_surface[0], sw, sh);
surface_set_shader(temp_surface[0], sh_fluid_bleach);
draw_surface_safe(_mat);
surface_reset_shader();
2023-09-26 14:35:25 +02:00
if(dx != 0 || dy != 0) {
if(_msk == 0)
2023-10-07 09:09:18 +02:00
fd_rectangle_add_velocity_surface(_dom, temp_surface[0], _pos[0] - sw / 2, _pos[1] - sh / 2, 1, 1, dx, dy);
2023-09-26 14:35:25 +02:00
else {
var _vw = sw + max(0, _msk * 2);
var _vh = sh + max(0, _msk * 2);
var _vmask = surface_create(_vw, _vh);
surface_set_shader(_vmask,,, BLEND.over);
2023-10-07 09:09:18 +02:00
draw_surface_safe(temp_surface[0], max(0, _msk), max(0, _msk));
2023-09-26 14:35:25 +02:00
surface_reset_shader();
var vel_mask = surface_create(_vw, _vh);
surface_set_shader(vel_mask, sh_mask_expand);
shader_set_f("dimension", _vw, _vh);
shader_set_f("amount", _msk);
draw_surface_safe(_vmask);
surface_reset_shader();
fd_rectangle_add_velocity_surface(_dom, vel_mask, _pos[0] - _vw / 2, _pos[1] - _vh / 2, 1, 1, dx, dy);
2023-10-07 09:09:18 +02:00
2023-09-26 14:35:25 +02:00
surface_free(_vmask);
surface_free(vel_mask);
}
2023-02-14 02:48:33 +01:00
}
2023-10-07 09:09:18 +02:00
fd_rectangle_add_material_surface(_dom, temp_surface[0], _pos[0] - sw / 2, _pos[1] - sh / 2, 1, 1, c_white, _den);
2023-02-14 02:48:33 +01:00
_prevPos[0] = _pos[0];
_prevPos[1] = _pos[1];
}
2023-03-05 07:16:44 +01:00
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
2023-02-14 02:48:33 +01:00
var bbox = drawGetBbox(xx, yy, _s);
var _mat = getInputData(1);
2023-02-14 02:48:33 +01:00
if(!is_surface(_mat)) return;
draw_surface_fit(_mat, bbox.xc, bbox.yc, bbox.w, bbox.h);
}
}