Pixel-Composer/scripts/node_smoke_group/node_smoke_group.gml

116 lines
3.9 KiB
Plaintext
Raw Normal View History

2024-03-19 09:49:29 +01:00
#macro FLUID_DOMAIN_CHECK if(!instance_exists(_dom) && is_instanceof(group, Node_Smoke_Group)) _dom = group.domain; if(_dom == noone || !instance_exists(_dom)) return;
2023-10-07 09:09:18 +02:00
2024-03-19 09:49:29 +01:00
function Node_Smoke_Group(_x, _y, _group = noone) : Node_Collection(_x, _y, _group) constructor {
2023-11-10 11:32:46 +01:00
name = "SmokeSim";
color = COLORS.node_blend_smoke;
icon = THEME.smoke_sim;
2023-02-14 02:48:33 +01:00
ungroupable = false;
2023-02-14 02:48:33 +01:00
update_on_frame = true;
manual_ungroupable = false;
2023-10-07 16:23:40 +02:00
outputNode = noone;
2024-08-18 06:16:20 +02:00
newInput(0, nodeValue_Dimension(self));
2023-10-07 09:09:18 +02:00
2024-08-18 06:16:20 +02:00
newInput(1, nodeValue_Surface("Collision", self));
2023-10-07 09:09:18 +02:00
2024-08-18 06:16:20 +02:00
newInput(2, nodeValue_Enum_Button("Material dissipation type", self, 1, [ "Multiply", "Subtract" ]));
2023-10-07 09:09:18 +02:00
2024-08-18 09:13:41 +02:00
newInput(3, nodeValue_Float("Material dissipation", self, 0.02))
2023-10-07 09:09:18 +02:00
.setDisplay(VALUE_DISPLAY.slider, { range: [ 0, 0.1, 0.01 ] });
2024-08-18 06:16:20 +02:00
newInput(4, nodeValue_Enum_Button("Velocity dissipation type", self, 1, [ "Multiply", "Subtract" ]));
2023-10-07 09:09:18 +02:00
2024-08-18 09:13:41 +02:00
newInput(5, nodeValue_Float("Velocity dissipation", self, 0.00))
2023-10-07 09:09:18 +02:00
.setDisplay(VALUE_DISPLAY.slider, { range: [ 0, 0.1, 0.01 ] });
2024-08-18 06:16:20 +02:00
newInput(6, nodeValue_Vec2("Acceleration", self, [ 0, 0 ]));
2023-10-07 09:09:18 +02:00
2024-08-18 06:16:20 +02:00
newInput(7, nodeValue_Vec2("Material intertia", self, [ 1, -0.2 ]));
2023-10-07 09:09:18 +02:00
2024-08-18 09:13:41 +02:00
newInput(8, nodeValue_Float("Initial pressure", self, 0.75))
2023-10-07 09:09:18 +02:00
.setDisplay(VALUE_DISPLAY.slider);
2024-08-18 09:13:41 +02:00
newInput(9, nodeValue_Float("Material Maccormack weight", self, 1))
2023-10-07 09:09:18 +02:00
.setDisplay(VALUE_DISPLAY.slider);
2024-08-18 09:13:41 +02:00
newInput(10, nodeValue_Float("Velocity Maccormack weight", self, 0))
2023-10-07 09:09:18 +02:00
.setDisplay(VALUE_DISPLAY.slider);
2024-08-18 06:16:20 +02:00
newInput(11, nodeValue_Bool("Wrap", self, false));
2023-10-07 09:09:18 +02:00
input_display_list_def = [
["Domain", false], 0, 11, 1,
["Properties", false], 8, 6, 7,
["Dissipation", false], 2, 3, 4, 5,
["Huh?", true], 9, 10,
["Inputs", false],
];
2024-08-08 06:57:51 +02:00
custom_input_index = array_length(inputs);
2023-10-07 09:09:18 +02:00
domain = fd_rectangle_create(PROJECT.attributes.surface_dimension[0], PROJECT.attributes.surface_dimension[1]);
2024-05-03 13:40:46 +02:00
if(NODE_NEW_MANUAL) {
2024-03-19 09:49:29 +01:00
var _render = nodeBuild("Node_Smoke_Render_Output", 128, -32, self);
2023-02-14 02:48:33 +01:00
}
2023-10-03 07:14:28 +02:00
static update = function() {
for( var i = 0, n = array_length(nodes); i < n; i++ ) {
var node = nodes[i];
2023-10-03 07:14:28 +02:00
if(node.cacheExist()) node.cachedPropagate();
}
2023-10-07 09:09:18 +02:00
var _dim = getInputData( 0);
var coll = getInputData( 1);
var mdisTyp = getInputData( 2);
var mdis = getInputData( 3);
var vdisTyp = getInputData( 4);
var vdis = getInputData( 5);
var acc = getInputData( 6);
var matInr = getInputData( 7);
var inPress = getInputData( 8);
var mMac = getInputData( 9);
var vMac = getInputData(10);
var wrap = getInputData(11);
2024-01-19 09:33:37 +01:00
if(IS_FIRST_FRAME || !is_surface(domain.sf_world)) {
2023-10-07 09:09:18 +02: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)) draw_surface_stretched_safe(coll, 0, 0, _dim[0], _dim[1]);
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);
2023-02-14 02:48:33 +01:00
}
2023-03-08 14:59:54 +01:00
2023-10-07 16:23:40 +02:00
static getAnimationCacheExist = function(frame) {
if(outputNode == noone) return false;
return outputNode.cacheExist(frame);
}
2023-02-14 02:48:33 +01:00
}