Pixel-Composer/objects/FLIP_Domain/Create_0.gml

124 lines
3.6 KiB
Plaintext
Raw Normal View History

2023-12-29 14:30:54 +01:00
/// @description Insert description here
#region params
domain = noone;
particlePosBuff = noone;
width = 0;
height = 0;
particleSize = 0;
density = 0;
2023-12-30 14:21:56 +01:00
viscosity = 0;
friction = 0;
2023-12-29 14:30:54 +01:00
maxParticles = 0;
numParticles = 0;
velocityDamping = 0.9;
dt = 0.1;
iteration = 8;
2023-12-31 14:09:49 +01:00
numPressureIters = 2;
numParticleIters = 2;
2023-12-29 14:30:54 +01:00
g = 1;
flipRatio = 0.8;
overRelaxation = 1.5;
2023-12-30 14:21:56 +01:00
2023-12-31 14:09:49 +01:00
obstracles = [];
2023-12-30 14:21:56 +01:00
wallCollide = true;
2024-01-07 12:18:20 +01:00
wallElasticity = 1;
skip_incompressible = false;
particleRadius = 0;
2023-12-29 14:30:54 +01:00
#endregion
function init(width, height, particleSize, density, maxParticles) { #region domain init
2023-12-30 14:21:56 +01:00
particlePos = array_create(maxParticles * 2);
2024-03-21 13:57:44 +01:00
particleHist = array_create(maxParticles * 2 * TOTAL_FRAMES);
2023-12-30 14:21:56 +01:00
particleLife = array_create(maxParticles);
obstracles = [];
numParticles = 0;
2023-12-29 14:30:54 +01:00
if(domain != noone &&
self.width == width &&
self.height == height &&
self.particleSize == particleSize &&
self.density == density &&
self.maxParticles == maxParticles) {
FLIP_resetDomain(domain);
return;
}
self.width = width ;
self.height = height ;
self.particleSize = particleSize;
self.density = density ;
self.maxParticles = maxParticles;
particlePosBuff = buffer_create(maxParticles * 2 * 8, buffer_grow, 8);
2023-12-30 14:21:56 +01:00
particleLifeBuff = buffer_create(maxParticles * 8, buffer_grow, 8);
aPosBuff = buffer_get_address(particlePosBuff);
aLifeBuff = buffer_get_address(particleLifeBuff);
2023-12-29 14:30:54 +01:00
domain = FLIP_initDomain(width, height, particleSize, density, maxParticles);
particleRadius = FLIP_getParticleRadius(domain);
2023-12-31 14:09:49 +01:00
cellX = floor(width / particleSize) + 1;
cellY = floor(height / particleSize) + 1;
2023-12-29 14:30:54 +01:00
} #endregion
function update() { #region
FLIP_setQuality( domain, iteration, numPressureIters, numParticleIters);
FLIP_setGravity( domain, g);
2023-12-30 14:21:56 +01:00
FLIP_setViscosity( domain, viscosity);
2024-03-21 13:57:44 +01:00
FLIP_setFriction( domain, friction);
2023-12-29 14:30:54 +01:00
FLIP_setFlipRatio( domain, flipRatio);
FLIP_setVelocityDamping( domain, velocityDamping);
FLIP_setOverRelaxation( domain, overRelaxation);
2024-01-07 12:18:20 +01:00
FLIP_setWallCollisions( domain, wallCollide, wallElasticity);
2023-12-29 14:30:54 +01:00
} #endregion
function step() { #region
FLIP_resetDensity(domain);
2024-01-07 12:18:20 +01:00
if(skip_incompressible) {
FLIP_setTimeStep(domain, dt);
repeat(iteration) {
FLIP_simulate_integrateParticles(domain);
FLIP_simulate_pushParticlesApart(domain);
FLIP_simulate_handleParticleCollisions(domain);
//FLIP_simulate_transferVelocities(domain, 1);
//FLIP_simulate_updateParticleDensity(domain);
//FLIP_simulate_solveIncompressibility(domain);
//FLIP_simulate_transferVelocities(domain, 0);
}
2024-03-21 13:57:44 +01:00
} else {
2024-01-07 12:18:20 +01:00
FLIP_simulate(domain, dt);
2024-03-21 13:57:44 +01:00
//FLIP_setTimeStep(domain, dt);
//repeat(iteration) {
// FLIP_simulate_integrateParticles(domain);
// FLIP_simulate_pushParticlesApart(domain);
// FLIP_simulate_handleParticleCollisions(domain);
// FLIP_simulate_transferVelocities(domain, 1);
// FLIP_simulate_updateParticleDensity(domain);
// FLIP_simulate_solveIncompressibility(domain);
// FLIP_simulate_transferVelocities(domain, 0);
//}
}
2023-12-30 14:21:56 +01:00
FLIP_setParticleBuffer(domain, aPosBuff, aLifeBuff);
buffer_seek(particlePosBuff, buffer_seek_start, 0);
buffer_seek(particleLifeBuff, buffer_seek_start, 0);
2024-01-07 12:18:20 +01:00
for(var i = 0; i < maxParticles * 2; i++) {
2024-03-21 13:57:44 +01:00
particleHist[maxParticles * 2 * CURRENT_FRAME + i] = particlePos[i];
2024-01-07 12:18:20 +01:00
particlePos[i] = buffer_read(particlePosBuff, buffer_f64);
}
2023-12-30 14:21:56 +01:00
for(var i = 0; i < maxParticles; i++)
particleLife[i] = buffer_read(particleLifeBuff, buffer_f64);
2023-12-29 14:30:54 +01:00
} #endregion