Fix T83777: Crash when enabling guides

Also adjusted adjusted guiding UI parameters so that guiding will not get invalidated when changing domain values.
This commit is contained in:
Sebastián Barschkis
2021-01-10 19:09:37 +01:00
parent 5b90ed6c06
commit 30310a4fc8
4 changed files with 21 additions and 10 deletions

View File

@@ -1394,15 +1394,14 @@ bool MANTA::readGuiding(FluidModifierData *fmd, int framenr, bool sourceDomain)
if (with_debug) if (with_debug)
cout << "MANTA::readGuiding()" << endl; cout << "MANTA::readGuiding()" << endl;
FluidDomainSettings *fds = fmd->domain;
if (!mUsingGuiding) if (!mUsingGuiding)
return false; return false;
if (!fds) if (!fmd)
return false; return false;
ostringstream ss; ostringstream ss;
vector<string> pythonCommands; vector<string> pythonCommands;
FluidDomainSettings *fds = fmd->domain;
string directory = (sourceDomain) ? getDirectory(fmd, FLUID_DOMAIN_DIR_DATA) : string directory = (sourceDomain) ? getDirectory(fmd, FLUID_DOMAIN_DIR_DATA) :
getDirectory(fmd, FLUID_DOMAIN_DIR_GUIDE); getDirectory(fmd, FLUID_DOMAIN_DIR_GUIDE);

View File

@@ -412,7 +412,9 @@ def fluid_post_step_$ID$():\n\
mantaMsg('Fluid post step')\n\ mantaMsg('Fluid post step')\n\
\n\ \n\
# Copy vel grid to reals grids (which Blender internal will in turn use for vel access)\n\ # Copy vel grid to reals grids (which Blender internal will in turn use for vel access)\n\
copyVec3ToReal(source=vel_s$ID$, targetX=x_vel_s$ID$, targetY=y_vel_s$ID$, targetZ=z_vel_s$ID$)\n"; copyVec3ToReal(source=vel_s$ID$, targetX=x_vel_s$ID$, targetY=y_vel_s$ID$, targetZ=z_vel_s$ID$)\n\
if using_guiding_s$ID$:\n\
copyVec3ToReal(source=guidevel_sg$ID$, targetX=x_guidevel_s$ID$, targetY=y_guidevel_s$ID$, targetZ=z_guidevel_s$ID$)\n";
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// DESTRUCTION // DESTRUCTION
@@ -676,7 +678,9 @@ const std::string fluid_load_guiding =
def fluid_load_guiding_$ID$(path, framenr, file_format):\n\ def fluid_load_guiding_$ID$(path, framenr, file_format):\n\
mantaMsg('Fluid load guiding, frame ' + str(framenr))\n\ mantaMsg('Fluid load guiding, frame ' + str(framenr))\n\
guidevel_sg$ID$.setName('$NAME_VELOCITY_GUIDE$')\n\ guidevel_sg$ID$.setName('$NAME_VELOCITY_GUIDE$')\n\
fluid_file_import_s$ID$(dict=fluid_guiding_dict_s$ID$, path=path, framenr=framenr, file_format=file_format, file_name=file_guiding_s$ID$)\n"; fluid_file_import_s$ID$(dict=fluid_guiding_dict_s$ID$, path=path, framenr=framenr, file_format=file_format, file_name=file_guiding_s$ID$)\n\
\n\
copyVec3ToReal(source=guidevel_sg$ID$, targetX=x_guidevel_s$ID$, targetY=y_guidevel_s$ID$, targetZ=z_guidevel_s$ID$)\n";
const std::string fluid_load_vel = const std::string fluid_load_vel =
"\n\ "\n\

View File

@@ -3921,7 +3921,7 @@ static void BKE_fluid_modifier_processDomain(FluidModifierData *fmd,
prev_guide = manta_has_guiding(fds->fluid, fmd, prev_frame, guide_parent); prev_guide = manta_has_guiding(fds->fluid, fmd, prev_frame, guide_parent);
/* Unused for now. */ /* Unused for now. */
UNUSED_VARS(has_guide, prev_guide, next_mesh, next_guide); UNUSED_VARS(next_mesh, next_guide);
bool with_gdomain; bool with_gdomain;
with_gdomain = (fds->guide_source == FLUID_DOMAIN_GUIDE_SRC_DOMAIN); with_gdomain = (fds->guide_source == FLUID_DOMAIN_GUIDE_SRC_DOMAIN);
@@ -4072,6 +4072,9 @@ static void BKE_fluid_modifier_processDomain(FluidModifierData *fmd,
break; break;
case FLUID_DOMAIN_CACHE_REPLAY: case FLUID_DOMAIN_CACHE_REPLAY:
default: default:
if (with_guide) {
baking_guide = !has_guide && (is_startframe || prev_guide);
}
baking_data = !has_data && (is_startframe || prev_data); baking_data = !has_data && (is_startframe || prev_data);
if (with_smoke && with_noise) { if (with_smoke && with_noise) {
baking_noise = !has_noise && (is_startframe || prev_noise); baking_noise = !has_noise && (is_startframe || prev_noise);

View File

@@ -81,6 +81,11 @@ static void rna_Fluid_datacache_reset(Main *UNUSED(bmain), Scene *UNUSED(scene),
Object *ob = (Object *)ptr->owner_id; Object *ob = (Object *)ptr->owner_id;
int cache_map = (FLUID_DOMAIN_OUTDATED_DATA | FLUID_DOMAIN_OUTDATED_NOISE | int cache_map = (FLUID_DOMAIN_OUTDATED_DATA | FLUID_DOMAIN_OUTDATED_NOISE |
FLUID_DOMAIN_OUTDATED_MESH | FLUID_DOMAIN_OUTDATED_PARTICLES); FLUID_DOMAIN_OUTDATED_MESH | FLUID_DOMAIN_OUTDATED_PARTICLES);
/* In replay mode, always invalidate guiding cache too. */
if (settings->cache_type == FLUID_DOMAIN_CACHE_REPLAY) {
cache_map |= FLUID_DOMAIN_OUTDATED_GUIDE;
}
BKE_fluid_cache_free(settings, ob, cache_map); BKE_fluid_cache_free(settings, ob, cache_map);
} }
# endif # endif
@@ -2251,13 +2256,13 @@ static void rna_def_fluid_domain_settings(BlenderRNA *brna)
RNA_def_property_float_sdna(prop, NULL, "guide_alpha"); RNA_def_property_float_sdna(prop, NULL, "guide_alpha");
RNA_def_property_range(prop, 1.0, 100.0); RNA_def_property_range(prop, 1.0, 100.0);
RNA_def_property_ui_text(prop, "Weight", "Guiding weight (higher value results in greater lag)"); RNA_def_property_ui_text(prop, "Weight", "Guiding weight (higher value results in greater lag)");
RNA_def_property_update(prop, NC_OBJECT | ND_MODIFIER, "rna_Fluid_guidingcache_reset"); RNA_def_property_update(prop, NC_OBJECT | ND_MODIFIER, "rna_Fluid_datacache_reset");
prop = RNA_def_property(srna, "guide_beta", PROP_INT, PROP_NONE); prop = RNA_def_property(srna, "guide_beta", PROP_INT, PROP_NONE);
RNA_def_property_int_sdna(prop, NULL, "guide_beta"); RNA_def_property_int_sdna(prop, NULL, "guide_beta");
RNA_def_property_range(prop, 1, 50); RNA_def_property_range(prop, 1, 50);
RNA_def_property_ui_text(prop, "Size", "Guiding size (higher value results in larger vortices)"); RNA_def_property_ui_text(prop, "Size", "Guiding size (higher value results in larger vortices)");
RNA_def_property_update(prop, NC_OBJECT | ND_MODIFIER, "rna_Fluid_guidingcache_reset"); RNA_def_property_update(prop, NC_OBJECT | ND_MODIFIER, "rna_Fluid_datacache_reset");
prop = RNA_def_property(srna, "guide_vel_factor", PROP_FLOAT, PROP_NONE); prop = RNA_def_property(srna, "guide_vel_factor", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "guide_vel_factor"); RNA_def_property_float_sdna(prop, NULL, "guide_vel_factor");
@@ -2266,7 +2271,7 @@ static void rna_def_fluid_domain_settings(BlenderRNA *brna)
prop, prop,
"Velocity Factor", "Velocity Factor",
"Guiding velocity factor (higher value results in greater guiding velocities)"); "Guiding velocity factor (higher value results in greater guiding velocities)");
RNA_def_property_update(prop, NC_OBJECT | ND_MODIFIER, "rna_Fluid_guidingcache_reset"); RNA_def_property_update(prop, NC_OBJECT | ND_MODIFIER, "rna_Fluid_datacache_reset");
prop = RNA_def_property(srna, "guide_source", PROP_ENUM, PROP_NONE); prop = RNA_def_property(srna, "guide_source", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "guide_source"); RNA_def_property_enum_sdna(prop, NULL, "guide_source");
@@ -2289,7 +2294,7 @@ static void rna_def_fluid_domain_settings(BlenderRNA *brna)
RNA_def_property_boolean_sdna(prop, NULL, "flags", FLUID_DOMAIN_USE_GUIDE); RNA_def_property_boolean_sdna(prop, NULL, "flags", FLUID_DOMAIN_USE_GUIDE);
RNA_def_property_ui_text(prop, "Use Guiding", "Enable fluid guiding"); RNA_def_property_ui_text(prop, "Use Guiding", "Enable fluid guiding");
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
RNA_def_property_update(prop, NC_OBJECT | ND_MODIFIER, "rna_Fluid_guidingcache_reset"); RNA_def_property_update(prop, NC_OBJECT | ND_MODIFIER, "rna_Fluid_update");
/* cache options */ /* cache options */