Fluid Simulation:
* Replaced the hard coded viscosity presets with Python ones. * Added version check, so older files load fine. Loading new files into 2.62 also works fine.
This commit is contained in:
3
release/scripts/presets/fluid/honey.py
Normal file
3
release/scripts/presets/fluid/honey.py
Normal file
@@ -0,0 +1,3 @@
|
||||
import bpy
|
||||
bpy.context.fluid.settings.viscosity_base = 2.0
|
||||
bpy.context.fluid.settings.viscosity_exponent = 3
|
||||
3
release/scripts/presets/fluid/oil.py
Normal file
3
release/scripts/presets/fluid/oil.py
Normal file
@@ -0,0 +1,3 @@
|
||||
import bpy
|
||||
bpy.context.fluid.settings.viscosity_base = 5.0
|
||||
bpy.context.fluid.settings.viscosity_exponent = 5
|
||||
3
release/scripts/presets/fluid/water.py
Normal file
3
release/scripts/presets/fluid/water.py
Normal file
@@ -0,0 +1,3 @@
|
||||
import bpy
|
||||
bpy.context.fluid.settings.viscosity_base = 1.0
|
||||
bpy.context.fluid.settings.viscosity_exponent = 6
|
||||
@@ -294,6 +294,23 @@ class AddPresetCloth(AddPresetBase, Operator):
|
||||
|
||||
preset_subdir = "cloth"
|
||||
|
||||
class AddPresetFluid(AddPresetBase, Operator):
|
||||
'''Add a Fluid Preset'''
|
||||
bl_idname = "fluid.preset_add"
|
||||
bl_label = "Add Fluid Preset"
|
||||
preset_menu = "FLUID_MT_presets"
|
||||
|
||||
preset_defines = [
|
||||
"fluid = bpy.context.fluid"
|
||||
]
|
||||
|
||||
preset_values = [
|
||||
"fluid.settings.viscosity_base",
|
||||
"fluid.settings.viscosity_exponent",
|
||||
]
|
||||
|
||||
preset_subdir = "fluid"
|
||||
|
||||
|
||||
class AddPresetSunSky(AddPresetBase, Operator):
|
||||
'''Add a Sky & Atmosphere Preset'''
|
||||
|
||||
@@ -18,7 +18,13 @@
|
||||
|
||||
# <pep8 compliant>
|
||||
import bpy
|
||||
from bpy.types import Panel
|
||||
from bpy.types import Panel, Menu
|
||||
|
||||
class FLUID_MT_presets(Menu):
|
||||
bl_label = "Fluid Presets"
|
||||
preset_subdir = "fluid"
|
||||
preset_operator = "script.execute_preset"
|
||||
draw = Menu.draw_preset
|
||||
|
||||
|
||||
class PhysicButtonsPanel():
|
||||
@@ -222,16 +228,14 @@ class PHYSICS_PT_domain_gravity(PhysicButtonsPanel, Panel):
|
||||
|
||||
col = split.column()
|
||||
col.label(text="Viscosity Presets:")
|
||||
sub = col.column(align=True)
|
||||
sub.prop(fluid, "viscosity_preset", text="")
|
||||
|
||||
if fluid.viscosity_preset == 'MANUAL':
|
||||
sub.prop(fluid, "viscosity_base", text="Base")
|
||||
sub.prop(fluid, "viscosity_exponent", text="Exponent", slider=True)
|
||||
else:
|
||||
# just for padding to prevent jumping around
|
||||
sub.separator()
|
||||
sub.separator()
|
||||
sub = col.row(align=True)
|
||||
sub.menu("FLUID_MT_presets", text=bpy.types.FLUID_MT_presets.bl_label)
|
||||
sub.operator("fluid.preset_add", text="", icon='ZOOMIN')
|
||||
sub.operator("fluid.preset_add", text="", icon='ZOOMOUT').remove_active = True
|
||||
|
||||
subsub = col.column(align=True)
|
||||
subsub.prop(fluid, "viscosity_base", text="Base")
|
||||
subsub.prop(fluid, "viscosity_exponent", text="Exponent", slider=True)
|
||||
|
||||
col.label(text="Optimization:")
|
||||
col.prop(fluid, "grid_levels", slider=True)
|
||||
|
||||
@@ -42,7 +42,7 @@ extern "C" {
|
||||
* and keep comment above the defines.
|
||||
* Use STRINGIFY() rather than defining with quotes */
|
||||
#define BLENDER_VERSION 262
|
||||
#define BLENDER_SUBVERSION 3
|
||||
#define BLENDER_SUBVERSION 4
|
||||
|
||||
#define BLENDER_MINVERSION 250
|
||||
#define BLENDER_MINSUBVERSION 0
|
||||
|
||||
@@ -13323,6 +13323,30 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
|
||||
}
|
||||
}
|
||||
|
||||
if (main->versionfile < 262 || (main->versionfile == 262 && main->subversionfile < 4))
|
||||
{
|
||||
/* Read Viscosity presets from older files */
|
||||
Object *ob;
|
||||
|
||||
for (ob = main->object.first; ob; ob = ob->id.next) {
|
||||
ModifierData *md;
|
||||
for (md = ob->modifiers.first; md; md = md->next) {
|
||||
if (md->type == eModifierType_Fluidsim) {
|
||||
FluidsimModifierData *fmd = (FluidsimModifierData *)md;
|
||||
if(fmd->fss->viscosityMode == 3) {
|
||||
fmd->fss->viscosityValue = 5.0;
|
||||
fmd->fss->viscosityExponent = 5;
|
||||
}
|
||||
else if(fmd->fss->viscosityMode == 4) {
|
||||
fmd->fss->viscosityValue = 2.0;
|
||||
fmd->fss->viscosityExponent = 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
{
|
||||
/* Default for old files is to save particle rotations to pointcache */
|
||||
|
||||
@@ -98,19 +98,7 @@
|
||||
|
||||
static float get_fluid_viscosity(FluidsimSettings *settings)
|
||||
{
|
||||
switch (settings->viscosityMode) {
|
||||
case 0: /* unused */
|
||||
return -1.0;
|
||||
case 2: /* water */
|
||||
return 1.0e-6;
|
||||
case 3: /* some (thick) oil */
|
||||
return 5.0e-5;
|
||||
case 4: /* ca. honey */
|
||||
return 2.0e-3;
|
||||
case 1: /* manual */
|
||||
default:
|
||||
return (1.0f/powf(10.0f, settings->viscosityExponent)) * settings->viscosityValue;
|
||||
}
|
||||
return (1.0f/powf(10.0f, settings->viscosityExponent)) * settings->viscosityValue;
|
||||
}
|
||||
|
||||
static float get_fluid_rate(FluidsimSettings *settings)
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#define __DNA_OBJECT_FLUIDSIM_H__
|
||||
|
||||
#include "DNA_ID.h"
|
||||
#include "DNA_defs.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -66,7 +67,7 @@ typedef struct FluidsimSettings {
|
||||
|
||||
/* fluid properties */
|
||||
float viscosityValue;
|
||||
short viscosityMode;
|
||||
short viscosityMode DNA_DEPRECATED;
|
||||
short viscosityExponent;
|
||||
/* gravity strength */
|
||||
float grav[3];
|
||||
|
||||
@@ -269,13 +269,6 @@ static void rna_def_fluidsim_domain(BlenderRNA *brna)
|
||||
{OB_FSDOM_FINAL, "FINAL", 0, "Final", "Display final quality results"},
|
||||
{0, NULL, 0, NULL, NULL}};
|
||||
|
||||
static EnumPropertyItem viscosity_items[] = {
|
||||
{1, "MANUAL", 0, "Manual", "Manual viscosity settings"},
|
||||
{2, "WATER", 0, "Water", "Viscosity of 1.0 * 10^-6"},
|
||||
{3, "OIL", 0, "Oil", "Viscosity of 5.0 * 10^-5"},
|
||||
{4, "HONEY", 0, "Honey", "Viscosity of 2.0 * 10^-3"},
|
||||
{0, NULL, 0, NULL, NULL}};
|
||||
|
||||
srna = RNA_def_struct(brna, "DomainFluidSettings", "FluidSettings");
|
||||
RNA_def_struct_sdna(srna, "FluidsimSettings");
|
||||
RNA_def_struct_ui_text(srna, "Domain Fluid Simulation Settings",
|
||||
@@ -360,12 +353,6 @@ static void rna_def_fluidsim_domain(BlenderRNA *brna)
|
||||
RNA_def_property_float_sdna(prop, NULL, "animRate");
|
||||
RNA_def_property_range(prop, 0.0, 100.0);
|
||||
RNA_def_property_ui_text(prop, "Simulation Speed", "Fluid motion rate (0 = stationary, 1 = normal speed)");
|
||||
|
||||
prop = RNA_def_property(srna, "viscosity_preset", PROP_ENUM, PROP_NONE);
|
||||
RNA_def_property_enum_sdna(prop, NULL, "viscosityMode");
|
||||
RNA_def_property_enum_items(prop, viscosity_items);
|
||||
RNA_def_property_ui_text(prop, "Viscosity Preset",
|
||||
"Set viscosity of the fluid to a preset value, or use manual input");
|
||||
|
||||
prop = RNA_def_property(srna, "viscosity_base", PROP_FLOAT, PROP_NONE);
|
||||
RNA_def_property_float_sdna(prop, NULL, "viscosityValue");
|
||||
|
||||
@@ -85,7 +85,6 @@ void fluidsim_init(FluidsimModifierData *fluidmd)
|
||||
fss->guiDisplayMode = 2; // preview
|
||||
fss->renderDisplayMode = 3; // render
|
||||
|
||||
fss->viscosityMode = 2; // default to water
|
||||
fss->viscosityValue = 1.0;
|
||||
fss->viscosityExponent = 6;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user