Fluid: Fixes for fluid guiding
Fluid guiding functionality was broken in the bake / read cache loop in fluid.c. Committing this to the release branch as otherwise fluid guiding would not have worked as expected (i.e. not at all).
This commit is contained in:
parent
4a08eb0707
commit
86e24ea10c
|
@ -2001,6 +2001,9 @@ int MANTA::bakeGuiding(FluidModifierData *mmd, int framenr)
|
|||
|
||||
std::string gformat = getCacheFileEnding(mmd->domain->cache_data_format);
|
||||
|
||||
bool final_cache = (mmd->domain->cache_type == FLUID_DOMAIN_CACHE_FINAL);
|
||||
std::string resumable_cache = (final_cache) ? "False" : "True";
|
||||
|
||||
BLI_path_join(cacheDirGuiding,
|
||||
sizeof(cacheDirGuiding),
|
||||
mmd->domain->cache_directory,
|
||||
|
@ -2010,7 +2013,7 @@ int MANTA::bakeGuiding(FluidModifierData *mmd, int framenr)
|
|||
|
||||
ss.str("");
|
||||
ss << "bake_guiding_" << mCurrentID << "('" << escapeSlashes(cacheDirGuiding) << "', " << framenr
|
||||
<< ", '" << gformat << "')";
|
||||
<< ", '" << gformat << "', " << resumable_cache << ")";
|
||||
pythonCommands.push_back(ss.str());
|
||||
|
||||
runPythonString(pythonCommands);
|
||||
|
|
|
@ -559,12 +559,9 @@ def bake_particles_$ID$(path_data, path_particles, framenr, format_data, format_
|
|||
|
||||
const std::string fluid_bake_guiding =
|
||||
"\n\
|
||||
def bake_guiding_process_$ID$(framenr, format_guiding, path_guiding):\n\
|
||||
def bake_guiding_process_$ID$(framenr, format_guiding, path_guiding, resumable):\n\
|
||||
mantaMsg('Bake fluid guiding')\n\
|
||||
\n\
|
||||
if framenr>1:\n\
|
||||
fluid_load_guiding_$ID$(path_guiding, framenr-1, format_guiding)\n\
|
||||
\n\
|
||||
# Average out velocities from multiple guiding objects at one cell\n\
|
||||
x_guidevel_s$ID$.safeDivide(numGuides_s$ID$)\n\
|
||||
y_guidevel_s$ID$.safeDivide(numGuides_s$ID$)\n\
|
||||
|
@ -582,13 +579,13 @@ def bake_guiding_process_$ID$(framenr, format_guiding, path_guiding):\n\
|
|||
extrapolateVec3Simple(vel=guidevelC_s$ID$, phi=phiGuideIn_s$ID$, distance=4, inside=False)\n\
|
||||
resampleVec3ToMac(source=guidevelC_s$ID$, target=guidevel_sg$ID$)\n\
|
||||
\n\
|
||||
fluid_save_guiding_$ID$(path_guiding, framenr, format_guiding)\n\
|
||||
fluid_save_guiding_$ID$(path_guiding, framenr, format_guiding, resumable)\n\
|
||||
\n\
|
||||
def bake_guiding_$ID$(path_guiding, framenr, format_guiding):\n\
|
||||
def bake_guiding_$ID$(path_guiding, framenr, format_guiding, resumable):\n\
|
||||
if not withMPBake or isWindows:\n\
|
||||
bake_guiding_process_$ID$(framenr, format_guiding, path_guiding)\n\
|
||||
bake_guiding_process_$ID$(framenr, format_guiding, path_guiding, resumable)\n\
|
||||
else:\n\
|
||||
fluid_cache_multiprocessing_start_$ID$(function=bake_guiding_process_$ID$, framenr=framenr, format_guiding=format_guiding, path_guiding=path_guiding)\n";
|
||||
fluid_cache_multiprocessing_start_$ID$(function=bake_guiding_process_$ID$, framenr=framenr, format_guiding=format_guiding, path_guiding=path_guiding, resumable=resumable)\n";
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// IMPORT
|
||||
|
|
|
@ -162,9 +162,6 @@ class PHYSICS_PT_settings(PhysicButtonsPanel, Panel):
|
|||
if md.fluid_type == 'DOMAIN':
|
||||
domain = md.domain_settings
|
||||
|
||||
# Deactivate UI if guides are enabled but not baked yet.
|
||||
layout.active = not self.check_domain_has_unbaked_guide(domain)
|
||||
|
||||
is_baking_any = domain.is_cache_baking_any
|
||||
has_baked_data = domain.has_cache_baked_data
|
||||
|
||||
|
@ -176,7 +173,9 @@ class PHYSICS_PT_settings(PhysicButtonsPanel, Panel):
|
|||
flow.enabled = not is_baking_any and not has_baked_data
|
||||
|
||||
col = flow.column()
|
||||
col.enabled = not domain.has_cache_baked_guide
|
||||
col.prop(domain, "resolution_max", text="Resolution Divisions")
|
||||
col = flow.column()
|
||||
col.prop(domain, "time_scale", text="Time Scale")
|
||||
col.prop(domain, "cfl_condition", text="CFL Number")
|
||||
|
||||
|
@ -201,7 +200,17 @@ class PHYSICS_PT_settings(PhysicButtonsPanel, Panel):
|
|||
|
||||
if domain.cache_type == 'MODULAR':
|
||||
col.separator()
|
||||
|
||||
# Deactivate bake operator if guides are enabled but not baked yet.
|
||||
note_flag = True
|
||||
if self.check_domain_has_unbaked_guide(domain) and domain.cache_type == 'MODULAR':
|
||||
note = layout.split()
|
||||
note_flag = False
|
||||
note.enabled = note_flag
|
||||
note.label(icon='INFO', text="Unbaked Guides: Bake Guides or disable them.")
|
||||
|
||||
split = layout.split()
|
||||
split.enabled = note_flag
|
||||
|
||||
bake_incomplete = (domain.cache_frame_pause_data < domain.cache_frame_end)
|
||||
if domain.has_cache_baked_data and not domain.is_cache_baking_data and bake_incomplete:
|
||||
|
@ -354,10 +363,13 @@ class PHYSICS_PT_smoke_dissolve(PhysicButtonsPanel, Panel):
|
|||
return (context.engine in cls.COMPAT_ENGINES)
|
||||
|
||||
def draw_header(self, context):
|
||||
md = context.fluid
|
||||
domain = md.domain_settings
|
||||
md = context.fluid.domain_settings
|
||||
domain = context.fluid.domain_settings
|
||||
|
||||
self.layout.prop(domain, "use_dissolve_smoke", text="")
|
||||
is_baking_any = domain.is_cache_baking_any
|
||||
|
||||
self.layout.enabled = not is_baking_any
|
||||
self.layout.prop(md, "use_dissolve_smoke", text="")
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
@ -433,6 +445,11 @@ class PHYSICS_PT_liquid(PhysicButtonsPanel, Panel):
|
|||
|
||||
def draw_header(self, context):
|
||||
md = context.fluid.domain_settings
|
||||
domain = context.fluid.domain_settings
|
||||
|
||||
is_baking_any = domain.is_cache_baking_any
|
||||
|
||||
self.layout.enabled = not is_baking_any
|
||||
self.layout.prop(md, "use_flip_particles", text="")
|
||||
|
||||
def draw(self, context):
|
||||
|
@ -618,6 +635,12 @@ class PHYSICS_PT_adaptive_domain(PhysicButtonsPanel, Panel):
|
|||
if not PhysicButtonsPanel.poll_gas_domain(context):
|
||||
return False
|
||||
|
||||
md = context.fluid
|
||||
domain = md.domain_settings
|
||||
# Effector guides require a fixed domain size
|
||||
if domain.use_guide and domain.guide_source == 'EFFECTOR':
|
||||
return False
|
||||
|
||||
return (context.engine in cls.COMPAT_ENGINES)
|
||||
|
||||
def draw_header(self, context):
|
||||
|
@ -678,9 +701,7 @@ class PHYSICS_PT_noise(PhysicButtonsPanel, Panel):
|
|||
layout.use_property_split = True
|
||||
|
||||
domain = context.fluid.domain_settings
|
||||
|
||||
# Deactivate UI if guides are enabled but not baked yet.
|
||||
layout.enabled = domain.use_noise and not self.check_domain_has_unbaked_guide(domain)
|
||||
layout.enabled = domain.use_noise
|
||||
|
||||
is_baking_any = domain.is_cache_baking_any
|
||||
has_baked_noise = domain.has_cache_baked_noise
|
||||
|
@ -701,8 +722,16 @@ class PHYSICS_PT_noise(PhysicButtonsPanel, Panel):
|
|||
if domain.cache_type == 'MODULAR':
|
||||
col.separator()
|
||||
|
||||
# Deactivate bake operator if data has not been baked yet.
|
||||
note_flag = True
|
||||
if domain.use_noise and not domain.has_cache_baked_data and domain.cache_type == 'MODULAR':
|
||||
note = layout.split()
|
||||
note_flag = False
|
||||
note.enabled = note_flag
|
||||
note.label(icon='INFO', text="Unbaked Data: Bake Data first.")
|
||||
|
||||
split = layout.split()
|
||||
split.enabled = domain.has_cache_baked_data
|
||||
split.enabled = domain.has_cache_baked_data and note_flag
|
||||
|
||||
bake_incomplete = (domain.cache_frame_pause_noise < domain.cache_frame_end)
|
||||
if domain.has_cache_baked_noise and not domain.is_cache_baking_noise and bake_incomplete:
|
||||
|
@ -744,9 +773,7 @@ class PHYSICS_PT_mesh(PhysicButtonsPanel, Panel):
|
|||
layout.use_property_split = True
|
||||
|
||||
domain = context.fluid.domain_settings
|
||||
|
||||
# Deactivate UI if guides are enabled but not baked yet.
|
||||
layout.enabled = domain.use_mesh and not self.check_domain_has_unbaked_guide(domain)
|
||||
layout.enabled = domain.use_mesh
|
||||
|
||||
is_baking_any = domain.is_cache_baking_any
|
||||
has_baked_mesh = domain.has_cache_baked_mesh
|
||||
|
@ -780,8 +807,16 @@ class PHYSICS_PT_mesh(PhysicButtonsPanel, Panel):
|
|||
if domain.cache_type == 'MODULAR':
|
||||
col.separator()
|
||||
|
||||
# Deactivate bake operator if data has not been baked yet.
|
||||
note_flag = True
|
||||
if domain.use_mesh and not domain.has_cache_baked_data and domain.cache_type == 'MODULAR':
|
||||
note = layout.split()
|
||||
note_flag = False
|
||||
note.enabled = note_flag
|
||||
note.label(icon='INFO', text="Unbaked Data: Bake Data first.")
|
||||
|
||||
split = layout.split()
|
||||
split.enabled = domain.has_cache_baked_data
|
||||
split.enabled = domain.has_cache_baked_data and note_flag
|
||||
|
||||
bake_incomplete = (domain.cache_frame_pause_mesh < domain.cache_frame_end)
|
||||
if domain.has_cache_baked_mesh and not domain.is_cache_baking_mesh and bake_incomplete:
|
||||
|
@ -817,9 +852,6 @@ class PHYSICS_PT_particles(PhysicButtonsPanel, Panel):
|
|||
|
||||
domain = context.fluid.domain_settings
|
||||
|
||||
# Deactivate UI if guides are enabled but not baked yet.
|
||||
layout.enabled = not self.check_domain_has_unbaked_guide(domain)
|
||||
|
||||
is_baking_any = domain.is_cache_baking_any
|
||||
has_baked_particles = domain.has_cache_baked_particles
|
||||
using_particles = domain.use_spray_particles or domain.use_foam_particles or domain.use_bubble_particles
|
||||
|
@ -887,8 +919,17 @@ class PHYSICS_PT_particles(PhysicButtonsPanel, Panel):
|
|||
if domain.cache_type == 'MODULAR':
|
||||
col.separator()
|
||||
|
||||
# Deactivate bake operator if data has not been baked yet.
|
||||
note_flag = True
|
||||
if using_particles and not domain.has_cache_baked_data and domain.cache_type == 'MODULAR':
|
||||
note = layout.split()
|
||||
note_flag = False
|
||||
note.enabled = note_flag
|
||||
note.label(icon='INFO', text="Unbaked Data: Bake Data first.")
|
||||
|
||||
split = layout.split()
|
||||
split.enabled = (
|
||||
note_flag and
|
||||
domain.has_cache_baked_data and
|
||||
(domain.use_spray_particles or
|
||||
domain.use_bubble_particles or
|
||||
|
@ -931,9 +972,6 @@ class PHYSICS_PT_diffusion(PhysicButtonsPanel, Panel):
|
|||
|
||||
domain = context.fluid.domain_settings
|
||||
|
||||
# Deactivate UI if guides are enabled but not baked yet.
|
||||
layout.active = not self.check_domain_has_unbaked_guide(domain)
|
||||
|
||||
is_baking_any = domain.is_cache_baking_any
|
||||
has_baked_any = domain.has_cache_baked_any
|
||||
has_baked_data = domain.has_cache_baked_data
|
||||
|
@ -1018,7 +1056,8 @@ class PHYSICS_PT_guide(PhysicButtonsPanel, Panel):
|
|||
col = split.column()
|
||||
col.operator("fluid.free_guides", text="Free")
|
||||
elif not domain.has_cache_baked_guide and domain.is_cache_baking_guide:
|
||||
split.operator("fluid.pause_bake", text="Pause Guides")
|
||||
split.enabled = False
|
||||
split.operator("fluid.pause_bake", text="Baking Guides - ESC to pause")
|
||||
elif not domain.has_cache_baked_guide and not domain.is_cache_baking_guide:
|
||||
split.operator("fluid.bake_guides", text="Bake Guides")
|
||||
else:
|
||||
|
|
|
@ -3239,7 +3239,6 @@ static void manta_guiding(
|
|||
FluidDomainSettings *mds = mmd->domain;
|
||||
float fps = scene->r.frs_sec / scene->r.frs_sec_base;
|
||||
float dt = DT_DEFAULT * (25.0f / fps) * mds->time_scale;
|
||||
;
|
||||
|
||||
BLI_mutex_lock(&object_update_lock);
|
||||
|
||||
|
@ -3325,15 +3324,6 @@ static void BKE_fluid_modifier_processDomain(FluidModifierData *mmd,
|
|||
BKE_fluid_modifier_reset_ex(mmd, false);
|
||||
}
|
||||
|
||||
BKE_fluid_modifier_init(mmd, depsgraph, ob, scene, me);
|
||||
|
||||
/* 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;
|
||||
|
||||
/* Guiding parent res pointer needs initialization */
|
||||
guide_parent = mds->guide_parent;
|
||||
if (guide_parent) {
|
||||
|
@ -3343,6 +3333,15 @@ static void BKE_fluid_modifier_processDomain(FluidModifierData *mmd,
|
|||
}
|
||||
}
|
||||
|
||||
BKE_fluid_modifier_init(mmd, depsgraph, ob, scene, me);
|
||||
|
||||
/* 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;
|
||||
|
||||
objs = BKE_collision_objects_create(
|
||||
depsgraph, ob, mds->fluid_group, &numobj, eModifierType_Fluid);
|
||||
update_flowsflags(mds, objs, numobj);
|
||||
|
@ -3403,7 +3402,7 @@ static void BKE_fluid_modifier_processDomain(FluidModifierData *mmd,
|
|||
resume_guide = (!is_startframe) && (mds->cache_frame_pause_guide == scene_framenr);
|
||||
|
||||
bool read_cache, bake_cache;
|
||||
read_cache = false, bake_cache = baking_data || baking_noise || baking_mesh || baking_particles;
|
||||
read_cache = false, bake_cache = baking_data || baking_noise || baking_mesh || baking_particles || baking_guide;
|
||||
|
||||
bool with_gdomain;
|
||||
with_gdomain = (mds->guide_source == FLUID_DOMAIN_GUIDE_SRC_DOMAIN);
|
||||
|
@ -3419,14 +3418,14 @@ static void BKE_fluid_modifier_processDomain(FluidModifierData *mmd,
|
|||
switch (mode) {
|
||||
case FLUID_DOMAIN_CACHE_FINAL:
|
||||
/* Just load the data that has already been baked */
|
||||
if (!baking_data && !baking_noise && !baking_mesh && !baking_particles) {
|
||||
if (!baking_data && !baking_noise && !baking_mesh && !baking_particles && !baking_guide) {
|
||||
read_cache = true;
|
||||
bake_cache = false;
|
||||
}
|
||||
break;
|
||||
case FLUID_DOMAIN_CACHE_MODULAR:
|
||||
/* Just load the data that has already been baked */
|
||||
if (!baking_data && !baking_noise && !baking_mesh && !baking_particles) {
|
||||
if (!baking_data && !baking_noise && !baking_mesh && !baking_particles && !baking_guide) {
|
||||
read_cache = true;
|
||||
bake_cache = false;
|
||||
break;
|
||||
|
@ -4561,7 +4560,7 @@ void BKE_fluid_modifier_create_type_data(struct FluidModifierData *mmd)
|
|||
mmd->effector->flags = 0;
|
||||
|
||||
/* guide options */
|
||||
mmd->effector->guide_mode = FLUID_EFFECTOR_GUIDE_MAX;
|
||||
mmd->effector->guide_mode = FLUID_EFFECTOR_GUIDE_OVERRIDE;
|
||||
mmd->effector->vel_multi = 1.0f;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -505,7 +505,9 @@ static void fluid_free_startjob(void *customdata, short *stop, short *do_update,
|
|||
cache_map |= FLUID_DOMAIN_OUTDATED_PARTICLES;
|
||||
}
|
||||
if (fluid_is_free_guiding(job) || fluid_is_free_all(job)) {
|
||||
cache_map |= FLUID_DOMAIN_OUTDATED_GUIDE;
|
||||
cache_map |= (FLUID_DOMAIN_OUTDATED_DATA | FLUID_DOMAIN_OUTDATED_NOISE |
|
||||
FLUID_DOMAIN_OUTDATED_MESH | FLUID_DOMAIN_OUTDATED_PARTICLES |
|
||||
FLUID_DOMAIN_OUTDATED_GUIDE);
|
||||
}
|
||||
#ifdef WITH_FLUID
|
||||
BKE_fluid_cache_free(mds, job->ob, cache_map);
|
||||
|
|
Loading…
Reference in New Issue