Fluid: Added new option to control the maximum number fluid particles in the simulation

New option that lets users the define the maximum number of fluid particles that will be allowed in the simulation. This can come in handy, for example, to ensure that the particle count will not exceed the hardware capabilities, or to avoid excessive amounts of particles in a scene.
This commit is contained in:
Sebastián Barschkis 2020-07-26 22:01:42 +02:00
parent 2ebf263f5c
commit 04195b1e74
Notes: blender-bot 2023-02-14 11:21:43 +01:00
Referenced by issue #79212, SV + H color picker doesn't keep hue constant
6 changed files with 18 additions and 2 deletions

View File

@ -876,6 +876,7 @@ void MANTA::initializeRNAMap(FluidModifierData *fmd)
mRNAMap["CACHE_DIR"] = cacheDirectory;
mRNAMap["COMPRESSION_OPENVDB"] = vdbCompressionMethod;
mRNAMap["PRECISION_OPENVDB"] = vdbPrecisionHalf;
mRNAMap["PP_PARTICLE_MAXIMUM"] = to_string(fds->sys_particle_maximum);
/* Fluid object names. */
mRNAMap["NAME_FLAGS"] = FLUID_NAME_FLAGS;

View File

@ -48,7 +48,8 @@ meshRadiusFactor_s$ID$ = $MESH_PARTICLE_RADIUS$\n\
smoothenPos_s$ID$ = $MESH_SMOOTHEN_POS$\n\
smoothenNeg_s$ID$ = $MESH_SMOOTHEN_NEG$\n\
randomness_s$ID$ = $PARTICLE_RANDOMNESS$\n\
surfaceTension_s$ID$ = $LIQUID_SURFACE_TENSION$\n";
surfaceTension_s$ID$ = $LIQUID_SURFACE_TENSION$\n\
maxSysParticles_s$ID$ = $PP_PARTICLE_MAXIMUM$\n";
const std::string liquid_variables_particles =
"\n\
@ -216,6 +217,7 @@ def liquid_adaptive_step_$ID$(framenr):\n\
else:\n\
pVel_pp$ID$.setSource(grid=None, isMAC=False)\n\
\n\
pp_s$ID$.maxParticles = maxSysParticles_s$ID$ # remember, 0 means no particle cap\n\
sampleLevelsetWithParticles(phi=phiIn_s$ID$, flags=flags_s$ID$, parts=pp_s$ID$, discretization=particleNumber_s$ID$, randomness=randomness_s$ID$)\n\
flags_s$ID$.updateFromLevelset(phi_s$ID$)\n\
\n\

View File

@ -473,6 +473,7 @@ class PHYSICS_PT_liquid(PhysicButtonsPanel, Panel):
col = flow.column()
col.prop(domain, "simulation_method", expand=False)
col.prop(domain, "flip_ratio", text="FLIP Ratio")
col.prop(domain, "sys_particle_maximum", text="System Maximum")
col = col.column(align=True)
col.prop(domain, "particle_radius", text="Particle Radius")
col.prop(domain, "particle_number", text="Sampling")

View File

@ -4856,6 +4856,7 @@ void BKE_fluid_modifier_create_type_data(struct FluidModifierData *fmd)
fmd->domain->particle_radius = 1.0f;
fmd->domain->particle_band_width = 3.0f;
fmd->domain->fractions_threshold = 0.05f;
fmd->domain->sys_particle_maximum = 0;
/* diffusion options*/
fmd->domain->surface_tension = 0.0f;
@ -5100,6 +5101,7 @@ void BKE_fluid_modifier_copy(const struct FluidModifierData *fmd,
tfds->particle_radius = fds->particle_radius;
tfds->particle_band_width = fds->particle_band_width;
tfds->fractions_threshold = fds->fractions_threshold;
tfds->sys_particle_maximum = fds->sys_particle_maximum;
/* diffusion options*/
tfds->surface_tension = fds->surface_tension;

View File

@ -524,8 +524,9 @@ typedef struct FluidDomainSettings {
float particle_band_width;
float fractions_threshold;
float flip_ratio;
int sys_particle_maximum;
short simulation_method;
char _pad4[6];
char _pad4[2];
/* Diffusion options. */
float surface_tension;

View File

@ -1683,6 +1683,15 @@ static void rna_def_fluid_domain_settings(BlenderRNA *brna)
"and reduce the boundary smoothening effect)");
RNA_def_property_update(prop, NC_OBJECT | ND_MODIFIER, "rna_Fluid_datacache_reset");
prop = RNA_def_property(srna, "sys_particle_maximum", PROP_INT, PROP_NONE);
RNA_def_property_int_sdna(prop, NULL, "sys_particle_maximum");
RNA_def_property_range(prop, 0, INT_MAX);
RNA_def_property_ui_text(
prop,
"System Maximum",
"Maximum number of fluid particles that are allowed in this simulation");
RNA_def_property_update(prop, NC_OBJECT | ND_MODIFIER, "rna_Fluid_datacache_reset");
/* diffusion options */
prop = RNA_def_property(srna, "use_diffusion", PROP_BOOLEAN, PROP_NONE);