Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastián Barschkis <sebbas@sebbas.org>2020-03-22 23:46:30 +0300
committerSebastián Barschkis <sebbas@sebbas.org>2020-03-22 23:46:43 +0300
commit0c571db4add35ae78089cd8e88fa6f7a9125b123 (patch)
treed5342a8d040d0429685426d8858db729f1d5d600 /source/blender/blenkernel/intern/fluid.c
parent95b6090afca21b2e03bcd278ae94d1321e407029 (diff)
Fix T73988: Mantaflow fluid simulation - Particles for Spray, Foam and Bubbles are one frame ahead of Mesh
Fixes an issue with secondary particles being out of sync with the main simulation. Cleaned up the secondary particle code in general too (making sure that all solver attributes - timestep, framelength, etc. - are set correctly).
Diffstat (limited to 'source/blender/blenkernel/intern/fluid.c')
-rw-r--r--source/blender/blenkernel/intern/fluid.c41
1 files changed, 23 insertions, 18 deletions
diff --git a/source/blender/blenkernel/intern/fluid.c b/source/blender/blenkernel/intern/fluid.c
index 15f3fdf6a40..58a1ae28d42 100644
--- a/source/blender/blenkernel/intern/fluid.c
+++ b/source/blender/blenkernel/intern/fluid.c
@@ -538,7 +538,7 @@ static bool BKE_fluid_modifier_init(
/* Initially dt is equal to frame length (dt can change with adaptive-time stepping though). */
mds->dt = mds->frame_length;
mds->time_per_frame = 0;
- mds->time_total = (scene_framenr - 1) * mds->frame_length;
+ mds->time_total = abs(scene_framenr - mds->cache_frame_start) * mds->frame_length;
mmd->time = scene_framenr;
@@ -3561,7 +3561,7 @@ static int manta_step(
BLI_mutex_lock(&object_update_lock);
/* Loop as long as time_per_frame (sum of sub dt's) does not exceed actual framelength. */
- while (time_per_frame < frame_length) {
+ while (time_per_frame + FLT_EPSILON < frame_length) {
manta_adapt_timestep(mds->fluid);
dt = manta_get_timestep(mds->fluid);
@@ -3569,10 +3569,6 @@ static int manta_step(
* new MANTA object). */
mds->dt = dt;
- /* Count for how long this while loop is running. */
- time_per_frame += dt;
- time_total += dt;
-
/* Calculate inflow geometry. */
update_flowsfluids(depsgraph, scene, ob, mds, time_per_frame, frame_length, frame, dt);
@@ -3596,11 +3592,15 @@ static int manta_step(
if (mds->total_cells > 1) {
update_effectors(depsgraph, scene, ob, mds, dt);
manta_bake_data(mds->fluid, mmd, frame);
-
- mds->time_per_frame = time_per_frame;
- mds->time_total = time_total;
}
+ /* Count for how long this while loop is running. */
+ time_per_frame += dt;
+ time_total += dt;
+
+ mds->time_per_frame = time_per_frame;
+ mds->time_total = time_total;
+
/* If user requested stop, quit baking */
if (G.is_break && !mode_replay) {
result = 0;
@@ -3701,8 +3701,7 @@ static void BKE_fluid_modifier_processDomain(FluidModifierData *mmd,
bool is_startframe;
is_startframe = (scene_framenr == mds->cache_frame_start);
- /* Reset fluid if no fluid present (obviously)
- * or if timeline gets reset to startframe */
+ /* Reset fluid if no fluid present. */
if (!mds->fluid) {
BKE_fluid_modifier_reset_ex(mmd, false);
@@ -3713,7 +3712,7 @@ static void BKE_fluid_modifier_processDomain(FluidModifierData *mmd,
}
BLI_assert(mds->fluid);
- /* Guiding parent res pointer needs initialization */
+ /* Guiding parent res pointer needs initialization. */
guide_parent = mds->guide_parent;
if (guide_parent) {
mmd_parent = (FluidModifierData *)modifiers_findByType(guide_parent, eModifierType_Fluid);
@@ -3722,12 +3721,13 @@ static void BKE_fluid_modifier_processDomain(FluidModifierData *mmd,
}
}
- /* ensure that time parameters are initialized correctly before every step */
+ /* Ensure that time parameters are initialized correctly before every step. */
float fps = scene->r.frs_sec / scene->r.frs_sec_base;
mds->frame_length = DT_DEFAULT * (25.0f / fps) * mds->time_scale;
mds->dt = mds->frame_length;
mds->time_per_frame = 0;
- mds->time_total = (scene_framenr - 1) * mds->frame_length;
+ /* Get distance between cache start and current frame for total time. */
+ mds->time_total = abs(scene_framenr - mds->cache_frame_start) * mds->frame_length;
objs = BKE_collision_objects_create(
depsgraph, ob, mds->fluid_group, &numobj, eModifierType_Fluid);
@@ -3743,7 +3743,7 @@ static void BKE_fluid_modifier_processDomain(FluidModifierData *mmd,
MEM_freeN(objs);
}
- /* Ensure cache directory is not relative */
+ /* Ensure cache directory is not relative. */
const char *relbase = modifier_path_relbase_from_global(ob);
BLI_path_abs(mds->cache_directory, relbase);
@@ -3801,7 +3801,7 @@ static void BKE_fluid_modifier_processDomain(FluidModifierData *mmd,
/* Ensure positivity of previous frame. */
CLAMP(prev_frame, 1, prev_frame);
- /* Cache mode specific settings */
+ /* Cache mode specific settings. */
switch (mode) {
case FLUID_DOMAIN_CACHE_FINAL:
/* Just load the data that has already been baked */
@@ -3872,8 +3872,13 @@ static void BKE_fluid_modifier_processDomain(FluidModifierData *mmd,
/* Read particles cache. */
if (with_liquid && with_particles) {
- /* Update particle data from file is faster than via Python (manta_read_particles()). */
- has_particles = manta_update_particle_structures(mds->fluid, mmd, particles_frame);
+ if (!baking_data && !baking_particles && !mode_replay) {
+ /* Update particle data from file is faster than via Python (manta_read_particles()). */
+ has_particles = manta_update_particle_structures(mds->fluid, mmd, particles_frame);
+ }
+ else {
+ has_particles = manta_read_particles(mds->fluid, mmd, particles_frame);
+ }
}
/* Read guide cache. */