Pixel-Composer/scripts/node_smoke_domain/node_smoke_domain.gml

105 lines
3.4 KiB
Text
Raw Normal View History

2024-03-19 09:49:29 +01:00
function Node_Smoke_Domain(_x, _y, _group = noone) : Node_Smoke(_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
manual_ungroupable = false;
2024-08-18 06:16:20 +02:00
newInput(0, nodeValue_Dimension(self));
2023-02-14 02:48:33 +01:00
2024-08-18 06:16:20 +02:00
newInput(1, nodeValue_Surface("Collision", self));
2023-02-14 02:48:33 +01:00
2024-08-18 06:16:20 +02:00
newInput(2, nodeValue_Enum_Button("Material dissipation type", self, 1, [ "Multiply", "Subtract" ]));
2023-02-14 02:48:33 +01:00
2024-08-18 09:13:41 +02:00
newInput(3, nodeValue_Float("Material dissipation", self, 0.02))
.setDisplay(VALUE_DISPLAY.slider, { range: [ 0, 0.1, 0.01 ] });
2023-02-14 02:48:33 +01:00
2024-08-18 06:16:20 +02:00
newInput(4, nodeValue_Enum_Button("Velocity dissipation type", self, 1, [ "Multiply", "Subtract" ]));
2023-02-14 02:48:33 +01:00
2024-08-18 09:13:41 +02:00
newInput(5, nodeValue_Float("Velocity dissipation", self, 0.00))
.setDisplay(VALUE_DISPLAY.slider, { range: [ 0, 0.1, 0.01 ] });
2023-02-14 02:48:33 +01:00
2024-08-18 06:16:20 +02:00
newInput(6, nodeValue_Vec2("Acceleration", self, [ 0, 0 ]));
2023-02-14 02:48:33 +01:00
2024-08-18 06:16:20 +02:00
newInput(7, nodeValue_Vec2("Material intertia", self, [ 1, -0.2 ]));
2023-02-14 02:48:33 +01:00
2024-08-18 09:13:41 +02:00
newInput(8, nodeValue_Float("Initial pressure", self, 0.75))
.setDisplay(VALUE_DISPLAY.slider);
2023-02-14 02:48:33 +01:00
2024-08-18 09:13:41 +02:00
newInput(9, nodeValue_Float("Material Maccormack weight", self, 1))
.setDisplay(VALUE_DISPLAY.slider);
2023-02-14 02:48:33 +01:00
2024-08-18 09:13:41 +02:00
newInput(10, nodeValue_Float("Velocity Maccormack weight", self, 0))
.setDisplay(VALUE_DISPLAY.slider);
2023-02-14 02:48:33 +01:00
2024-11-22 09:43:50 +01:00
newInput(11, nodeValue_Enum_Scroll("Boundary", self, 0, [ "Free", "Wall", "Wrap" ]));
newInput(12, nodeValue_Float("Timestep", self, 1));
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2023-02-14 02:48:33 +01:00
2024-09-04 03:57:11 +02:00
newOutput(0, nodeValue_Output("Domain", self, VALUE_TYPE.sdomain, noone));
2023-02-14 02:48:33 +01:00
2024-11-21 12:07:07 +01:00
newOutput(1, nodeValue_Output("Velocity", self, VALUE_TYPE.surface, noone))
.setVisible(false);
newOutput(2, nodeValue_Output("Pressure", self, VALUE_TYPE.surface, noone))
.setVisible(false);
2023-02-14 02:48:33 +01:00
input_display_list = [
2024-11-22 09:43:50 +01:00
["Domain", false], 0, 1, 11, 12,
["Properties", false], 8, 6, 7,
["Dissipation", false], 3, 5,
["Advance Setings", true], 2, 4, 9, 10,
2023-02-14 02:48:33 +01:00
];
2024-11-22 09:43:50 +01:00
domain = new smokeSim_Domain(1, 1);
2023-02-14 02:48:33 +01:00
_dim_old = [0, 0];
2024-11-21 12:07:07 +01:00
static update = function(frame = CURRENT_FRAME) {
2023-02-14 02:48:33 +01:00
RETURN_ON_REST
2024-08-06 14:04:41 +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);
2024-11-22 09:43:50 +01:00
var bound = getInputData(11);
var tstp = getInputData(12);
2023-02-14 02:48:33 +01:00
2024-01-19 09:33:37 +01:00
if(IS_FIRST_FRAME || !is_surface(domain.sf_world)) {
2024-11-21 12:07:07 +01:00
domain.resetSize(_dim[0], _dim[1]);
domain.initial_value_pressure = inPress;
2023-02-14 02:48:33 +01:00
}
surface_set_target(domain.sf_world);
draw_clear_alpha($00FFFF, 0);
2024-11-21 12:07:07 +01:00
draw_surface_stretched_safe(coll, 0, 0, _dim[0], _dim[1]);
2023-02-14 02:48:33 +01:00
surface_reset_target();
2024-11-21 12:07:07 +01:00
domain.setAcceleration(acc[0], acc[1], matInr[0], matInr[1]);
domain.setMaterial(mdisTyp, mdis);
domain.setVelocity(vdisTyp, vdis);
domain.setMaccormack(vMac, mMac);
2024-11-22 09:43:50 +01:00
domain.setBoundary(bound);
domain.time_step = tstp;
2023-02-14 02:48:33 +01:00
2024-08-08 06:57:51 +02:00
outputs[0].setValue(domain);
2024-11-21 12:07:07 +01:00
outputs[1].setValue(domain.sf_velocity);
outputs[2].setValue(domain.sf_pressure);
}
2023-02-14 02:48:33 +01:00
2024-11-21 12:07:07 +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);
2024-11-21 12:07:07 +01:00
}
2023-02-14 02:48:33 +01:00
}