Fluid: Added domain check for new OpenVDB precision 'Mini' type

Precision 'Mini' should only be available for liquids domains.
This commit is contained in:
Sebastián Barschkis 2020-10-19 21:40:04 +02:00
parent aa244a7a68
commit c6c4925771
3 changed files with 231 additions and 210 deletions

View File

@ -93,7 +93,7 @@ void BKE_fluid_flow_type_set(struct Object *object, struct FluidFlowSettings *se
void BKE_fluid_effector_type_set(struct Object *object,
struct FluidEffectorSettings *settings,
int type);
void BKE_fluid_coba_field_sanitize(struct FluidDomainSettings *settings);
void BKE_fluid_fields_sanitize(struct FluidDomainSettings *settings);
void BKE_fluid_flow_behavior_set(struct Object *object,
struct FluidFlowSettings *settings,
int behavior);

View File

@ -4683,24 +4683,31 @@ void BKE_fluid_effector_type_set(Object *UNUSED(object), FluidEffectorSettings *
settings->type = type;
}
void BKE_fluid_coba_field_sanitize(FluidDomainSettings *settings)
void BKE_fluid_fields_sanitize(FluidDomainSettings *settings)
{
/* Based on the domain type, the coba field is defaulted accordingly if the selected field
/* Based on the domain type, certain fields are defaulted accordingly if the selected field
* is unsupported. */
const char field = settings->coba_field;
const char coba_field = settings->coba_field;
const char data_depth = settings->openvdb_data_depth;
if (settings->type == FLUID_DOMAIN_TYPE_GAS) {
if (field == FLUID_DOMAIN_FIELD_PHI || field == FLUID_DOMAIN_FIELD_PHI_IN ||
field == FLUID_DOMAIN_FIELD_PHI_OUT || field == FLUID_DOMAIN_FIELD_PHI_OBSTACLE) {
if (coba_field == FLUID_DOMAIN_FIELD_PHI || coba_field == FLUID_DOMAIN_FIELD_PHI_IN ||
coba_field == FLUID_DOMAIN_FIELD_PHI_OUT ||
coba_field == FLUID_DOMAIN_FIELD_PHI_OBSTACLE) {
/* Defaulted to density for gas domain. */
settings->coba_field = FLUID_DOMAIN_FIELD_DENSITY;
}
/* Gas domains do not support vdb mini precision. */
if (data_depth == VDB_PRECISION_MINI_FLOAT) {
settings->openvdb_data_depth = VDB_PRECISION_HALF_FLOAT;
}
}
else if (settings->type == FLUID_DOMAIN_TYPE_LIQUID) {
if (field == FLUID_DOMAIN_FIELD_COLOR_R || field == FLUID_DOMAIN_FIELD_COLOR_G ||
field == FLUID_DOMAIN_FIELD_COLOR_B || field == FLUID_DOMAIN_FIELD_DENSITY ||
field == FLUID_DOMAIN_FIELD_FLAME || field == FLUID_DOMAIN_FIELD_FUEL ||
field == FLUID_DOMAIN_FIELD_HEAT) {
if (coba_field == FLUID_DOMAIN_FIELD_COLOR_R || coba_field == FLUID_DOMAIN_FIELD_COLOR_G ||
coba_field == FLUID_DOMAIN_FIELD_COLOR_B || coba_field == FLUID_DOMAIN_FIELD_DENSITY ||
coba_field == FLUID_DOMAIN_FIELD_FLAME || coba_field == FLUID_DOMAIN_FIELD_FUEL ||
coba_field == FLUID_DOMAIN_FIELD_HEAT) {
/* Defaulted to phi for liquid domain. */
settings->coba_field = FLUID_DOMAIN_FIELD_PHI;
}

View File

@ -665,12 +665,205 @@ static void rna_Fluid_cache_directory_set(struct PointerRNA *ptr, const char *va
// settings->cache_flag = 0;
}
static const EnumPropertyItem *rna_Fluid_cobafield_itemf(bContext *UNUSED(C),
PointerRNA *ptr,
PropertyRNA *UNUSED(prop),
bool *r_free)
{
FluidDomainSettings *settings = (FluidDomainSettings *)ptr->data;
EnumPropertyItem *item = NULL;
EnumPropertyItem tmp = {0, "", 0, "", ""};
int totitem = 0;
tmp.value = FLUID_DOMAIN_FIELD_FLAGS;
tmp.identifier = "FLAGS";
tmp.icon = 0;
tmp.name = "Flags";
tmp.description = "Flag grid of the fluid domain";
RNA_enum_item_add(&item, &totitem, &tmp);
tmp.value = FLUID_DOMAIN_FIELD_PRESSURE;
tmp.identifier = "PRESSURE";
tmp.icon = 0;
tmp.name = "Pressure";
tmp.description = "Pressure field of the fluid domain";
RNA_enum_item_add(&item, &totitem, &tmp);
tmp.value = FLUID_DOMAIN_FIELD_VELOCITY_X;
tmp.identifier = "VELOCITY_X";
tmp.icon = 0;
tmp.name = "X Velocity";
tmp.description = "X component of the velocity field";
RNA_enum_item_add(&item, &totitem, &tmp);
tmp.value = FLUID_DOMAIN_FIELD_VELOCITY_Y;
tmp.identifier = "VELOCITY_Y";
tmp.icon = 0;
tmp.name = "Y Velocity";
tmp.description = "Y component of the velocity field";
RNA_enum_item_add(&item, &totitem, &tmp);
tmp.value = FLUID_DOMAIN_FIELD_VELOCITY_Z;
tmp.identifier = "VELOCITY_Z";
tmp.icon = 0;
tmp.name = "Z Velocity";
tmp.description = "Z component of the velocity field";
RNA_enum_item_add(&item, &totitem, &tmp);
tmp.value = FLUID_DOMAIN_FIELD_FORCE_X;
tmp.identifier = "FORCE_X";
tmp.icon = 0;
tmp.name = "X Force";
tmp.description = "X component of the force field";
RNA_enum_item_add(&item, &totitem, &tmp);
tmp.value = FLUID_DOMAIN_FIELD_FORCE_Y;
tmp.identifier = "FORCE_Y";
tmp.icon = 0;
tmp.name = "Y Force";
tmp.description = "Y component of the force field";
RNA_enum_item_add(&item, &totitem, &tmp);
tmp.value = FLUID_DOMAIN_FIELD_FORCE_Z;
tmp.identifier = "FORCE_Z";
tmp.icon = 0;
tmp.name = "Z Force";
tmp.description = "Z component of the force field";
RNA_enum_item_add(&item, &totitem, &tmp);
if (settings->type == FLUID_DOMAIN_TYPE_GAS) {
tmp.value = FLUID_DOMAIN_FIELD_COLOR_R;
tmp.identifier = "COLOR_R";
tmp.icon = 0;
tmp.name = "Red";
tmp.description = "Red component of the color field";
RNA_enum_item_add(&item, &totitem, &tmp);
tmp.value = FLUID_DOMAIN_FIELD_COLOR_G;
tmp.identifier = "COLOR_G";
tmp.icon = 0;
tmp.name = "Green";
tmp.description = "Green component of the color field";
RNA_enum_item_add(&item, &totitem, &tmp);
tmp.value = FLUID_DOMAIN_FIELD_COLOR_B;
tmp.identifier = "COLOR_B";
tmp.icon = 0;
tmp.name = "Blue";
tmp.description = "Blue component of the color field";
RNA_enum_item_add(&item, &totitem, &tmp);
tmp.value = FLUID_DOMAIN_FIELD_DENSITY;
tmp.identifier = "DENSITY";
tmp.icon = 0;
tmp.name = "Density";
tmp.description = "Quantity of soot in the fluid";
RNA_enum_item_add(&item, &totitem, &tmp);
tmp.value = FLUID_DOMAIN_FIELD_FLAME;
tmp.identifier = "FLAME";
tmp.icon = 0;
tmp.name = "Flame";
tmp.description = "Flame field";
RNA_enum_item_add(&item, &totitem, &tmp);
tmp.value = FLUID_DOMAIN_FIELD_FUEL;
tmp.identifier = "FUEL";
tmp.icon = 0;
tmp.name = "Fuel";
tmp.description = "Fuel field";
RNA_enum_item_add(&item, &totitem, &tmp);
tmp.value = FLUID_DOMAIN_FIELD_HEAT;
tmp.identifier = "HEAT";
tmp.icon = 0;
tmp.name = "Heat";
tmp.description = "Temperature of the fluid";
RNA_enum_item_add(&item, &totitem, &tmp);
}
else if (settings->type == FLUID_DOMAIN_TYPE_LIQUID) {
tmp.value = FLUID_DOMAIN_FIELD_PHI;
tmp.identifier = "PHI";
tmp.icon = 0;
tmp.name = "Fluid Levelset";
tmp.description = "Levelset representation of the fluid";
RNA_enum_item_add(&item, &totitem, &tmp);
tmp.value = FLUID_DOMAIN_FIELD_PHI_IN;
tmp.identifier = "PHI_IN";
tmp.icon = 0;
tmp.name = "Inflow Levelset";
tmp.description = "Levelset representation of the inflow";
RNA_enum_item_add(&item, &totitem, &tmp);
tmp.value = FLUID_DOMAIN_FIELD_PHI_OUT;
tmp.identifier = "PHI_OUT";
tmp.icon = 0;
tmp.name = "Outflow Levelset";
tmp.description = "Levelset representation of the outflow";
RNA_enum_item_add(&item, &totitem, &tmp);
tmp.value = FLUID_DOMAIN_FIELD_PHI_OBSTACLE;
tmp.identifier = "PHI_OBSTACLE";
tmp.icon = 0;
tmp.name = "Obstacle Levelset";
tmp.description = "Levelset representation of the obstacles";
RNA_enum_item_add(&item, &totitem, &tmp);
}
RNA_enum_item_end(&item, &totitem);
*r_free = true;
return item;
}
static const EnumPropertyItem *rna_Fluid_data_depth_itemf(bContext *UNUSED(C),
PointerRNA *ptr,
PropertyRNA *UNUSED(prop),
bool *r_free)
{
FluidDomainSettings *settings = (FluidDomainSettings *)ptr->data;
EnumPropertyItem *item = NULL;
EnumPropertyItem tmp = {0, "", 0, "", ""};
int totitem = 0;
tmp.value = VDB_PRECISION_FULL_FLOAT;
tmp.identifier = "32";
tmp.icon = 0;
tmp.name = "Full";
tmp.description = "Full float (Use 32 bit for all data)";
RNA_enum_item_add(&item, &totitem, &tmp);
tmp.value = VDB_PRECISION_HALF_FLOAT;
tmp.identifier = "16";
tmp.icon = 0;
tmp.name = "Half";
tmp.description = "Half float (Use 16 bit for all data)";
RNA_enum_item_add(&item, &totitem, &tmp);
if (settings->type == FLUID_DOMAIN_TYPE_LIQUID) {
tmp.value = VDB_PRECISION_MINI_FLOAT;
tmp.identifier = "8";
tmp.icon = 0;
tmp.name = "Mini";
tmp.description = "Mini float (Use 8 bit where possible, otherwise use 16 bit)";
RNA_enum_item_add(&item, &totitem, &tmp);
}
RNA_enum_item_end(&item, &totitem);
*r_free = true;
return item;
}
static void rna_Fluid_domaintype_set(struct PointerRNA *ptr, int value)
{
FluidDomainSettings *settings = (FluidDomainSettings *)ptr->data;
Object *ob = (Object *)ptr->owner_id;
BKE_fluid_domain_type_set(ob, settings, value);
BKE_fluid_coba_field_sanitize(settings);
BKE_fluid_fields_sanitize(settings);
}
static char *rna_FluidDomainSettings_path(PointerRNA *ptr)
@ -1042,159 +1235,6 @@ static void rna_Fluid_flowtype_set(struct PointerRNA *ptr, int value)
}
}
static const EnumPropertyItem *rna_Fluid_cobafield_itemf(bContext *UNUSED(C),
PointerRNA *ptr,
PropertyRNA *UNUSED(prop),
bool *r_free)
{
FluidDomainSettings *settings = (FluidDomainSettings *)ptr->data;
EnumPropertyItem *item = NULL;
EnumPropertyItem tmp = {0, "", 0, "", ""};
int totitem = 0;
tmp.value = FLUID_DOMAIN_FIELD_FLAGS;
tmp.identifier = "FLAGS";
tmp.icon = 0;
tmp.name = "Flags";
tmp.description = "Flag grid of the fluid domain";
RNA_enum_item_add(&item, &totitem, &tmp);
tmp.value = FLUID_DOMAIN_FIELD_PRESSURE;
tmp.identifier = "PRESSURE";
tmp.icon = 0;
tmp.name = "Pressure";
tmp.description = "Pressure field of the fluid domain";
RNA_enum_item_add(&item, &totitem, &tmp);
tmp.value = FLUID_DOMAIN_FIELD_VELOCITY_X;
tmp.identifier = "VELOCITY_X";
tmp.icon = 0;
tmp.name = "X Velocity";
tmp.description = "X component of the velocity field";
RNA_enum_item_add(&item, &totitem, &tmp);
tmp.value = FLUID_DOMAIN_FIELD_VELOCITY_Y;
tmp.identifier = "VELOCITY_Y";
tmp.icon = 0;
tmp.name = "Y Velocity";
tmp.description = "Y component of the velocity field";
RNA_enum_item_add(&item, &totitem, &tmp);
tmp.value = FLUID_DOMAIN_FIELD_VELOCITY_Z;
tmp.identifier = "VELOCITY_Z";
tmp.icon = 0;
tmp.name = "Z Velocity";
tmp.description = "Z component of the velocity field";
RNA_enum_item_add(&item, &totitem, &tmp);
tmp.value = FLUID_DOMAIN_FIELD_FORCE_X;
tmp.identifier = "FORCE_X";
tmp.icon = 0;
tmp.name = "X Force";
tmp.description = "X component of the force field";
RNA_enum_item_add(&item, &totitem, &tmp);
tmp.value = FLUID_DOMAIN_FIELD_FORCE_Y;
tmp.identifier = "FORCE_Y";
tmp.icon = 0;
tmp.name = "Y Force";
tmp.description = "Y component of the force field";
RNA_enum_item_add(&item, &totitem, &tmp);
tmp.value = FLUID_DOMAIN_FIELD_FORCE_Z;
tmp.identifier = "FORCE_Z";
tmp.icon = 0;
tmp.name = "Z Force";
tmp.description = "Z component of the force field";
RNA_enum_item_add(&item, &totitem, &tmp);
if (settings->type == FLUID_DOMAIN_TYPE_GAS) {
tmp.value = FLUID_DOMAIN_FIELD_COLOR_R;
tmp.identifier = "COLOR_R";
tmp.icon = 0;
tmp.name = "Red";
tmp.description = "Red component of the color field";
RNA_enum_item_add(&item, &totitem, &tmp);
tmp.value = FLUID_DOMAIN_FIELD_COLOR_G;
tmp.identifier = "COLOR_G";
tmp.icon = 0;
tmp.name = "Green";
tmp.description = "Green component of the color field";
RNA_enum_item_add(&item, &totitem, &tmp);
tmp.value = FLUID_DOMAIN_FIELD_COLOR_B;
tmp.identifier = "COLOR_B";
tmp.icon = 0;
tmp.name = "Blue";
tmp.description = "Blue component of the color field";
RNA_enum_item_add(&item, &totitem, &tmp);
tmp.value = FLUID_DOMAIN_FIELD_DENSITY;
tmp.identifier = "DENSITY";
tmp.icon = 0;
tmp.name = "Density";
tmp.description = "Quantity of soot in the fluid";
RNA_enum_item_add(&item, &totitem, &tmp);
tmp.value = FLUID_DOMAIN_FIELD_FLAME;
tmp.identifier = "FLAME";
tmp.icon = 0;
tmp.name = "Flame";
tmp.description = "Flame field";
RNA_enum_item_add(&item, &totitem, &tmp);
tmp.value = FLUID_DOMAIN_FIELD_FUEL;
tmp.identifier = "FUEL";
tmp.icon = 0;
tmp.name = "Fuel";
tmp.description = "Fuel field";
RNA_enum_item_add(&item, &totitem, &tmp);
tmp.value = FLUID_DOMAIN_FIELD_HEAT;
tmp.identifier = "HEAT";
tmp.icon = 0;
tmp.name = "Heat";
tmp.description = "Temperature of the fluid";
RNA_enum_item_add(&item, &totitem, &tmp);
}
else if (settings->type == FLUID_DOMAIN_TYPE_LIQUID) {
tmp.value = FLUID_DOMAIN_FIELD_PHI;
tmp.identifier = "PHI";
tmp.icon = 0;
tmp.name = "Fluid Levelset";
tmp.description = "Levelset representation of the fluid";
RNA_enum_item_add(&item, &totitem, &tmp);
tmp.value = FLUID_DOMAIN_FIELD_PHI_IN;
tmp.identifier = "PHI_IN";
tmp.icon = 0;
tmp.name = "Inflow Levelset";
tmp.description = "Levelset representation of the inflow";
RNA_enum_item_add(&item, &totitem, &tmp);
tmp.value = FLUID_DOMAIN_FIELD_PHI_OUT;
tmp.identifier = "PHI_OUT";
tmp.icon = 0;
tmp.name = "Outflow Levelset";
tmp.description = "Levelset representation of the outflow";
RNA_enum_item_add(&item, &totitem, &tmp);
tmp.value = FLUID_DOMAIN_FIELD_PHI_OBSTACLE;
tmp.identifier = "PHI_OBSTACLE";
tmp.icon = 0;
tmp.name = "Obstacle Levelset";
tmp.description = "Levelset representation of the obstacles";
RNA_enum_item_add(&item, &totitem, &tmp);
}
RNA_enum_item_end(&item, &totitem);
*r_free = true;
return item;
}
#else
static void rna_def_fluid_mesh_vertices(BlenderRNA *brna)
@ -1240,12 +1280,6 @@ static void rna_def_fluid_domain_settings(BlenderRNA *brna)
{VDB_COMPRESSION_NONE, "NONE", 0, "None", "Do not use any compression"},
{0, NULL, 0, NULL, NULL}};
static const EnumPropertyItem cache_comp_items[] = {
{SM_CACHE_LIGHT, "CACHELIGHT", 0, "Lite", "Fast but not so effective compression"},
{SM_CACHE_HEAVY, "CACHEHEAVY", 0, "Heavy", "Effective but slow compression"},
{0, NULL, 0, NULL, NULL},
};
static const EnumPropertyItem smoke_highres_sampling_items[] = {
{SM_HRES_FULLSAMPLE, "FULLSAMPLE", 0, "Full Sample", ""},
{SM_HRES_LINEAR, "LINEAR", 0, "Linear", ""},
@ -1263,14 +1297,9 @@ static void rna_def_fluid_domain_settings(BlenderRNA *brna)
{FLUID_DOMAIN_CACHE_ALL, "ALL", 0, "All", "Bake all simulation settings at once"},
{0, NULL, 0, NULL, NULL}};
static const EnumPropertyItem fluid_data_depth_items[] = {
{VDB_PRECISION_MINI_FLOAT,
"8",
0,
"Mini",
"Mini float (Use 8 bit where possible, otherwise 16 bit)"},
{VDB_PRECISION_HALF_FLOAT, "16", 0, "Half", "Half float (Use 16 bit for all data)"},
{VDB_PRECISION_FULL_FLOAT, "32", 0, "Full", "Full float (Use 32 bit for all data)"},
/* OpenVDB data depth - generated dynamically based on domain type */
static EnumPropertyItem fluid_data_depth_items[] = {
{0, "NONE", 0, "", ""},
{0, NULL, 0, NULL, NULL},
};
@ -2227,7 +2256,7 @@ static void rna_def_fluid_domain_settings(BlenderRNA *brna)
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
RNA_def_property_update(prop, NC_OBJECT | ND_MODIFIER, "rna_Fluid_guidingcache_reset");
/* cache options */
/* cache options */
prop = RNA_def_property(srna, "cache_frame_start", PROP_INT, PROP_TIME);
RNA_def_property_int_sdna(prop, NULL, "cache_frame_start");
@ -2400,6 +2429,22 @@ static void rna_def_fluid_domain_settings(BlenderRNA *brna)
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
RNA_def_property_update(prop, NC_OBJECT | ND_MODIFIER, "rna_Fluid_domain_data_reset");
prop = RNA_def_property(srna, "openvdb_cache_compress_type", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "openvdb_compression");
RNA_def_property_enum_items(prop, prop_compression_items);
RNA_def_property_ui_text(prop, "Compression", "Compression method to be used");
RNA_def_property_update(prop, NC_OBJECT | ND_MODIFIER, "rna_Fluid_domain_data_reset");
prop = RNA_def_property(srna, "openvdb_data_depth", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "openvdb_data_depth");
RNA_def_property_enum_items(prop, fluid_data_depth_items);
RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_Fluid_data_depth_itemf");
RNA_def_property_ui_text(
prop,
"Data Depth",
"Bit depth for fluid particles and grids (lower bit values reduce file size)");
RNA_def_property_update(prop, NC_OBJECT | ND_MODIFIER, "rna_Fluid_domain_data_reset");
/* time options */
prop = RNA_def_property(srna, "time_scale", PROP_FLOAT, PROP_NONE);
@ -2607,37 +2652,6 @@ static void rna_def_fluid_domain_settings(BlenderRNA *brna)
RNA_def_property_enum_items(prop, gridlines_cell_filter_items);
RNA_def_property_ui_text(prop, "Cell Type", "Cell type to be highlighted");
RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
/* -- Deprecated / unsed options (below)-- */
/* pointcache options */
prop = RNA_def_property(srna, "point_cache", PROP_POINTER, PROP_NONE);
RNA_def_property_flag(prop, PROP_NEVER_NULL);
RNA_def_property_pointer_sdna(prop, NULL, "point_cache[0]");
RNA_def_property_struct_type(prop, "PointCache");
RNA_def_property_ui_text(prop, "Point Cache", "");
prop = RNA_def_property(srna, "point_cache_compress_type", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "cache_comp");
RNA_def_property_enum_items(prop, cache_comp_items);
RNA_def_property_ui_text(prop, "Cache Compression", "Compression method to be used");
/* OpenVDB options */
prop = RNA_def_property(srna, "openvdb_cache_compress_type", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "openvdb_compression");
RNA_def_property_enum_items(prop, prop_compression_items);
RNA_def_property_ui_text(prop, "Compression", "Compression method to be used");
prop = RNA_def_property(srna, "openvdb_data_depth", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_bitflag_sdna(prop, NULL, "openvdb_data_depth");
RNA_def_property_enum_items(prop, fluid_data_depth_items);
RNA_def_property_ui_text(
prop,
"Data Depth",
"Bit depth for fluid particles and grids (lower bit values reduce file size)");
RNA_def_property_update(prop, NC_OBJECT | ND_MODIFIER, NULL);
}
static void rna_def_fluid_flow_settings(BlenderRNA *brna)