Pixel-Composer/scripts/node_fluid_domain/node_fluid_domain.gml

113 lines
4.3 KiB
Plaintext
Raw Normal View History

2023-02-28 09:43:01 +01:00
function Node_Fluid_Domain(_x, _y, _group = noone) : Node_Fluid(_x, _y, _group) constructor {
2023-11-10 11:32:46 +01:00
name = "Domain";
color = COLORS.node_blend_smoke;
icon = THEME.smoke_sim;
2023-02-14 02:48:33 +01:00
min_h = 128;
2023-07-21 12:40:20 +02:00
inputs[| 0] = nodeValue("Dimension", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, DEF_SURF)
2023-02-14 02:48:33 +01:00
.setDisplay(VALUE_DISPLAY.vector);
inputs[| 1] = nodeValue("Collision", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone);
inputs[| 2] = nodeValue("Material dissipation type", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 1)
.setDisplay(VALUE_DISPLAY.enum_button, [ "Multiply", "Subtract" ]);
inputs[| 3] = nodeValue("Material dissipation", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0.02)
.setDisplay(VALUE_DISPLAY.slider, { range: [ 0, 0.1, 0.01 ] });
2023-02-14 02:48:33 +01:00
inputs[| 4] = nodeValue("Velocity dissipation type", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 1)
.setDisplay(VALUE_DISPLAY.enum_button, [ "Multiply", "Subtract" ]);
inputs[| 5] = nodeValue("Velocity dissipation", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0.00)
.setDisplay(VALUE_DISPLAY.slider, { range: [ 0, 0.1, 0.01 ] });
2023-02-14 02:48:33 +01:00
inputs[| 6] = nodeValue("Acceleration", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 0, 0 ])
.setDisplay(VALUE_DISPLAY.vector);
inputs[| 7] = nodeValue("Material intertia", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 1, -0.2 ])
.setDisplay(VALUE_DISPLAY.vector);
inputs[| 8] = nodeValue("Initial pressure", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0.75)
.setDisplay(VALUE_DISPLAY.slider);
2023-02-14 02:48:33 +01:00
2023-10-07 09:09:18 +02:00
inputs[| 9] = nodeValue("Material Maccormack weight", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1)
.setDisplay(VALUE_DISPLAY.slider);
2023-02-14 02:48:33 +01:00
2023-10-07 09:09:18 +02:00
inputs[| 10] = nodeValue("Velocity Maccormack weight", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0)
.setDisplay(VALUE_DISPLAY.slider);
2023-02-14 02:48:33 +01:00
inputs[| 11] = nodeValue("Wrap", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false);
2023-11-10 11:32:46 +01:00
outputs[| 0] = nodeValue("Domain", self, JUNCTION_CONNECT.output, VALUE_TYPE.fdomain, noone);
2023-02-14 02:48:33 +01:00
input_display_list = [
["Domain", false], 0, 11, 1,
["Properties", false], 8, 6, 7,
["Dissipation", false], 2, 3, 4, 5,
["Huh?", true], 9, 10,
];
domain = fd_rectangle_create(256, 256);
_dim_old = [0, 0];
2023-10-09 16:07:33 +02:00
static update = function(frame = CURRENT_FRAME) { #region
2023-02-14 02:48:33 +01:00
RETURN_ON_REST
var _dim = inputs[| 0].getValue(frame);
var coll = inputs[| 1].getValue(frame);
var mdisTyp = inputs[| 2].getValue(frame);
var mdis = inputs[| 3].getValue(frame);
var vdisTyp = inputs[| 4].getValue(frame);
var vdis = inputs[| 5].getValue(frame);
var acc = inputs[| 6].getValue(frame);
var matInr = inputs[| 7].getValue(frame);
var inPress = inputs[| 8].getValue(frame);
var mMac = inputs[| 9].getValue(frame);
var vMac = inputs[| 10].getValue(frame);
var wrap = inputs[| 11].getValue(frame);
2023-10-09 16:07:33 +02:00
if(CURRENT_FRAME == 0 || !is_surface(domain.sf_world)) {
2023-02-14 02:48:33 +01:00
fd_rectangle_clear(domain);
fd_rectangle_destroy(domain);
domain = fd_rectangle_create(_dim[0], _dim[1]);
fd_rectangle_set_visualization_shader(domain, FD_VISUALIZATION_SHADER.COLORIZE);
fd_rectangle_set_material_type(domain, FD_MATERIAL_TYPE.A_16);
fd_rectangle_set_velocity_time_step(domain, 1);
fd_rectangle_set_material_time_step(domain, 1);
fd_rectangle_set_pressure_iteration_type(domain, -2);
fd_rectangle_set_initial_value_pressure(domain, inPress);
}
surface_set_target(domain.sf_world);
draw_clear_alpha($00FFFF, 0);
if(is_surface(coll))
2023-03-19 09:17:39 +01:00
draw_surface_stretched_safe(coll, 0, 0, _dim[0], _dim[1]);
2023-02-14 02:48:33 +01:00
surface_reset_target();
fd_rectangle_set_material_dissipation_type(domain, mdisTyp);
fd_rectangle_set_material_dissipation_value(domain, mdis);
fd_rectangle_set_velocity_dissipation_type(domain, vdisTyp);
fd_rectangle_set_velocity_dissipation_value(domain, vdis);
fd_rectangle_set_acceleration(domain, acc[0], acc[1], matInr[0], matInr[1]);
fd_rectangle_set_velocity_maccormack_weight(domain, vMac);
fd_rectangle_set_material_maccormack_weight(domain, mMac);
fd_rectangle_set_repeat(domain, wrap);
outputs[| 0].setValue(domain);
2023-10-07 09:09:18 +02:00
} #region
2023-02-14 02:48:33 +01:00
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);
}
}