Pixel-Composer/scripts/node_FLIP_domain/node_FLIP_domain.gml

171 lines
5.0 KiB
Plaintext
Raw Normal View History

2023-12-29 14:30:54 +01:00
function Node_FLIP_Domain(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
name = "Domain";
color = COLORS.node_blend_fluid;
icon = THEME.fluid_sim;
2024-03-28 14:18:02 +01:00
setDimension(96, 96);
2023-12-29 14:30:54 +01:00
manual_ungroupable = false;
2024-03-22 09:44:11 +01:00
update_on_frame = true;
2023-12-29 14:30:54 +01:00
2024-08-18 06:16:20 +02:00
newInput(0, nodeValue_Dimension(self));
2023-12-29 14:30:54 +01:00
2024-08-18 06:16:20 +02:00
newInput(1, nodeValue_Int("Particle Size", self, 1));
2023-12-29 14:30:54 +01:00
2024-08-18 06:16:20 +02:00
newInput(2, nodeValue_Int("Particle Density", self, 10));
2023-12-29 14:30:54 +01:00
2024-08-18 09:13:41 +02:00
newInput(3, nodeValue_Float("FLIP Ratio", self, 0.8))
2023-12-29 14:30:54 +01:00
.setDisplay(VALUE_DISPLAY.slider);
2024-08-18 06:16:20 +02:00
newInput(4, nodeValue_Float("Resolve accelerator", self, 1.5));
2023-12-29 14:30:54 +01:00
2024-08-18 06:16:20 +02:00
newInput(5, nodeValue_Int("Iteration", self, 8));
2023-12-29 14:30:54 +01:00
2024-08-18 09:13:41 +02:00
newInput(6, nodeValue_Float("Damping", self, 0.8))
2023-12-29 14:30:54 +01:00
.setDisplay(VALUE_DISPLAY.slider);
2024-08-18 06:16:20 +02:00
newInput(7, nodeValue_Float("Gravity", self, 5));
2023-12-29 14:30:54 +01:00
2024-08-18 06:16:20 +02:00
newInput(8, nodeValue_Float("Time Step", self, 0.05));
2023-12-29 14:30:54 +01:00
2024-08-18 06:16:20 +02:00
newInput(9, nodeValue_Toggle("Wall", self, 0b1111, { data: [ "T", "B", "L", "R" ] }));
2023-12-30 14:21:56 +01:00
2024-08-18 09:13:41 +02:00
newInput(10, nodeValue_Float("Viscosity", self, 0.))
2023-12-31 14:09:49 +01:00
.setDisplay(VALUE_DISPLAY.slider, { range: [ -1, 1, 0.01 ] });
2023-12-30 14:21:56 +01:00
2024-08-18 09:13:41 +02:00
newInput(11, nodeValue_Float("Friction", self, 0.))
2023-12-30 14:21:56 +01:00
.setDisplay(VALUE_DISPLAY.slider);
2024-08-18 09:13:41 +02:00
newInput(12, nodeValue_Float("Wall Elasticity", self, 0.))
2024-01-07 12:18:20 +01:00
.setDisplay(VALUE_DISPLAY.slider, { range: [ 0, 2, 0.01 ] });
2024-03-22 09:44:11 +01:00
2024-08-18 06:16:20 +02:00
newInput(13, nodeValue_Rotation("Gravity Direction", self, 0));
2024-03-22 09:44:11 +01:00
2023-12-29 14:30:54 +01:00
input_display_list = [
2024-03-21 13:57:44 +01:00
["Domain", false], 0, 1, 9, 12,
["Solver", true], 3, 8,
2024-03-22 09:44:11 +01:00
["Physics", false], 7, 13, 10, 11,
2023-12-29 14:30:54 +01:00
]
2024-09-04 03:57:11 +02:00
newOutput(0, nodeValue_Output("Domain", self, VALUE_TYPE.fdomain, noone));
2023-12-29 14:30:54 +01:00
2024-01-07 12:18:20 +01:00
#region attributes
array_push(attributeEditors, "FLIP Solver");
attributes.max_particles = 10000;
array_push(attributeEditors, ["Maximum particles", function() { return attributes.max_particles; },
new textBox(TEXTBOX_INPUT.number, function(val) {
attributes.max_particles = val;
})]);
attributes.iteration = 8;
array_push(attributeEditors, ["Global iteration", function() { return attributes.iteration; },
new textBox(TEXTBOX_INPUT.number, function(val) {
attributes.iteration = val;
triggerRender();
})]);
attributes.iteration_pressure = 2;
array_push(attributeEditors, ["Pressure iteration", function() { return attributes.iteration_pressure; },
new textBox(TEXTBOX_INPUT.number, function(val) {
attributes.iteration_pressure = val;
triggerRender();
})]);
attributes.iteration_particle = 2;
array_push(attributeEditors, ["Particle iteration", function() { return attributes.iteration_particle; },
new textBox(TEXTBOX_INPUT.number, function(val) {
attributes.iteration_particle = val;
triggerRender();
})]);
attributes.overrelax = 1.5;
array_push(attributeEditors, ["Overrelaxation", function() { return attributes.overrelax; },
new textBox(TEXTBOX_INPUT.number, function(val) {
attributes.overrelax = val;
triggerRender();
})]);
attributes.skip_incompressible = false;
array_push(attributeEditors, ["Skip incompressible", function() { return attributes.skip_incompressible; },
new checkBox(function() {
attributes.skip_incompressible = !attributes.skip_incompressible;
triggerRender();
})]);
#endregion
2024-03-15 13:38:08 +01:00
domain = instance_create(0, 0, FLIP_Domain);
toReset = true;
2023-12-29 14:30:54 +01:00
2024-03-21 13:57:44 +01:00
static step = function() {
var _col = getInputData(9);
2024-08-08 06:57:51 +02:00
inputs[12].setVisible(_col);
2024-03-21 13:57:44 +01:00
}
2023-12-29 14:30:54 +01:00
static update = function(frame = CURRENT_FRAME) {
var _dim = getInputData(0);
2024-03-14 14:35:19 +01:00
var _siz = getInputData(1); _siz = max(_siz, 1);
2023-12-29 14:30:54 +01:00
var _den = getInputData(2);
var _flp = getInputData(3);
var _dmp = getInputData(6);
var _grv = getInputData(7);
var _dt = getInputData(8);
2023-12-30 14:21:56 +01:00
var _col = getInputData(9);
var _vis = getInputData(10);
var _fric = getInputData(11);
2024-01-07 12:18:20 +01:00
var _ela = getInputData(12);
2024-03-22 09:44:11 +01:00
var _gdir = getInputData(13);
2023-12-29 14:30:54 +01:00
2023-12-31 14:09:49 +01:00
var _ovr = attributes.overrelax;
var _itr = attributes.iteration;
var _itrP = attributes.iteration_pressure;
var _itrR = attributes.iteration_particle;
2024-03-22 09:44:11 +01:00
var width = _dim[0] + _siz * 2;
var height = _dim[1] + _siz * 2;
2024-03-15 13:38:08 +01:00
if(IS_FIRST_FRAME || toReset) {
2023-12-29 14:30:54 +01:00
var particleSize = _siz;
var density = _den;
var maxParticles = attributes.max_particles;
domain.init(width, height, particleSize, density, maxParticles);
}
2024-03-15 13:38:08 +01:00
toReset = false;
2023-12-29 14:30:54 +01:00
domain.velocityDamping = _dmp;
domain.dt = _dt;
2023-12-31 14:09:49 +01:00
2023-12-29 14:30:54 +01:00
domain.iteration = _itr;
2023-12-31 14:09:49 +01:00
domain.numPressureIters = _itrP;
domain.numParticleIters = _itrR;
2023-12-29 14:30:54 +01:00
domain.g = _grv;
2024-03-22 09:44:11 +01:00
domain.gDirection = _gdir;
2023-12-29 14:30:54 +01:00
domain.flipRatio = _flp;
domain.overRelaxation = _ovr;
2023-12-30 14:21:56 +01:00
domain.viscosity = _vis;
2024-03-21 13:57:44 +01:00
domain.friction = power(1 - _fric, 0.025);
2023-12-30 14:21:56 +01:00
domain.wallCollide = _col;
2024-01-07 12:18:20 +01:00
domain.wallElasticity = _ela;
domain.skip_incompressible = attributes.skip_incompressible;
2023-12-29 14:30:54 +01:00
domain.update();
2024-08-08 06:57:51 +02:00
outputs[0].setValue(domain);
2023-12-29 14:30:54 +01:00
}
2023-12-30 14:21:56 +01:00
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
2023-12-30 14:21:56 +01:00
var bbox = drawGetBbox(xx, yy, _s);
draw_sprite_bbox_uniform(s_node_fluidSim_domain, 0, bbox);
}
2024-03-22 09:44:11 +01:00
static getPreviewValues = function() { return domain.domain_preview; }
2023-12-29 14:30:54 +01:00
}