From 5745f99deed89e547da87235f934c477675dd747 Mon Sep 17 00:00:00 2001 From: Daniel Genrich Date: Sun, 12 Jun 2011 23:51:30 +0000 Subject: [PATCH] =?UTF-8?q?Elbeem=20/=20Fluidsim=20update:=20a)=20Enable?= =?UTF-8?q?=20the=20possibility=20to=20remove=20the=20"air=20bubble"=20aro?= =?UTF-8?q?und=20submerged=20collision=20object.=20This=20feature=20is=20e?= =?UTF-8?q?nabled=20as=20standard=20for=20new=20files.=20The=20code=20was?= =?UTF-8?q?=20found=20in=20elbeem=20by=20nudelZ,=20coded=20and=20provided?= =?UTF-8?q?=20by=20Nils=20Th=C3=BCrey=20(thanks!)=20b)=20Old=20baked=20fil?= =?UTF-8?q?es=20gets=20deleted=20if=20a=20new=20bake=20gets=20started=20(w?= =?UTF-8?q?ere=20overwritten=20before=20and=20resulted=20in=20weird=20old?= =?UTF-8?q?=20bake=20+=20new=20bake=20mixture)=20(idea=20by=20nudelZ)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- intern/elbeem/extern/elbeem.h | 8 ++- intern/elbeem/intern/simulation_object.cpp | 3 + intern/elbeem/intern/solver_class.h | 3 + intern/elbeem/intern/solver_init.cpp | 9 +++ intern/elbeem/intern/solver_interface.h | 3 + .../startup/bl_ui/properties_physics_fluid.py | 1 + .../blender/editors/physics/physics_fluid.c | 55 ++++++++++++++++++- source/blender/makesdna/DNA_object_fluidsim.h | 5 +- source/blender/makesrna/intern/rna_fluidsim.c | 8 ++- .../modifiers/intern/MOD_fluidsim_util.c | 10 ++-- 10 files changed, 94 insertions(+), 11 deletions(-) diff --git a/intern/elbeem/extern/elbeem.h b/intern/elbeem/extern/elbeem.h index f5538df8805..6df08ccebd2 100644 --- a/intern/elbeem/extern/elbeem.h +++ b/intern/elbeem/extern/elbeem.h @@ -77,6 +77,10 @@ typedef struct elbeemSimulationSettings { /* boundary types and settings for domain walls */ short domainobsType; float domainobsPartslip; + + /* what surfaces to generate */ + int mFsSurfGenSetting; + /* generate speed vectors for vertices (e.g. for image based motion blur)*/ short generateVertexVectors; /* strength of surface smoothing */ @@ -108,10 +112,12 @@ typedef struct elbeemSimulationSettings { #define OB_FLUIDSIM_PARTICLE 64 #define OB_FLUIDSIM_CONTROL 128 -// defines for elbeemMesh->obstacleType below +// defines for elbeemMesh->obstacleType below (low bits) high bits (>=64) are reserved for mFsSurfGenSetting flags which are defined in solver_class.h #define FLUIDSIM_OBSTACLE_NOSLIP 1 #define FLUIDSIM_OBSTACLE_PARTSLIP 2 #define FLUIDSIM_OBSTACLE_FREESLIP 3 +#define FLUIDSIM_FSSG_NOOBS 64 + #define OB_VOLUMEINIT_VOLUME 1 #define OB_VOLUMEINIT_SHELL 2 diff --git a/intern/elbeem/intern/simulation_object.cpp b/intern/elbeem/intern/simulation_object.cpp index 2544b8fe29c..87828b26088 100644 --- a/intern/elbeem/intern/simulation_object.cpp +++ b/intern/elbeem/intern/simulation_object.cpp @@ -181,6 +181,9 @@ int SimulationObject::initializeLbmSimulation(ntlRenderGlobals *glob) mpLbm->setGenerateParticles(mpElbeemSettings->generateParticles); // set initial particles mpParts->setNumInitialParticles(mpElbeemSettings->numTracerParticles); + + // surface generation flag + mpLbm->setSurfGenSettings(mpElbeemSettings->mFsSurfGenSetting); string dinitType = string("no"); if (mpElbeemSettings->domainobsType==FLUIDSIM_OBSTACLE_PARTSLIP) dinitType = string("part"); diff --git a/intern/elbeem/intern/solver_class.h b/intern/elbeem/intern/solver_class.h index 8662ac3f12a..1548aaa19bc 100644 --- a/intern/elbeem/intern/solver_class.h +++ b/intern/elbeem/intern/solver_class.h @@ -308,6 +308,9 @@ class LbmFsgrSolver : //! for raytracing, preprocess void prepareVisualization( void ); + /* surface generation settings */ + virtual void setSurfGenSettings(short value); + protected: //! internal quick print function (for debugging) diff --git a/intern/elbeem/intern/solver_init.cpp b/intern/elbeem/intern/solver_init.cpp index 899b1e0ecbc..7e9f5e7f420 100644 --- a/intern/elbeem/intern/solver_init.cpp +++ b/intern/elbeem/intern/solver_init.cpp @@ -538,6 +538,15 @@ void LbmFsgrSolver::parseAttrList() } +/****************************************************************************** + * (part of enabling chapter 6 of "Free Surface Flows with Moving and Deforming Objects for LBM") + *****************************************************************************/ +void LbmFsgrSolver::setSurfGenSettings(short value) +{ + mFsSurfGenSetting = value; +} + + /****************************************************************************** * Initialize omegas and forces on all levels (for init/timestep change) *****************************************************************************/ diff --git a/intern/elbeem/intern/solver_interface.h b/intern/elbeem/intern/solver_interface.h index 71b347d683d..8f3181a307d 100644 --- a/intern/elbeem/intern/solver_interface.h +++ b/intern/elbeem/intern/solver_interface.h @@ -271,6 +271,9 @@ class LbmSolverInterface /*! debug object display */ virtual vector getDebugObjects() { vector empty(0); return empty; } + /* surface generation settings */ + virtual void setSurfGenSettings(short value) = 0; + #if LBM_USE_GUI==1 /*! show simulation info */ virtual void debugDisplay(int) = 0; diff --git a/release/scripts/startup/bl_ui/properties_physics_fluid.py b/release/scripts/startup/bl_ui/properties_physics_fluid.py index 5da89d0090a..c7e3a9e7220 100644 --- a/release/scripts/startup/bl_ui/properties_physics_fluid.py +++ b/release/scripts/startup/bl_ui/properties_physics_fluid.py @@ -257,6 +257,7 @@ class PHYSICS_PT_domain_boundary(PhysicButtonsPanel, bpy.types.Panel): col.prop(fluid, "slip_type", text="") if fluid.slip_type == 'PARTIALSLIP': col.prop(fluid, "partial_slip_factor", slider=True, text="Amount") + col.prop(fluid, "surface_noobs") col = split.column() col.label(text="Surface:") diff --git a/source/blender/editors/physics/physics_fluid.c b/source/blender/editors/physics/physics_fluid.c index 4aa9b942cf3..d54048546fe 100644 --- a/source/blender/editors/physics/physics_fluid.c +++ b/source/blender/editors/physics/physics_fluid.c @@ -56,6 +56,7 @@ #include "DNA_object_fluidsim.h" #include "BLI_blenlib.h" +#include "BLI_fileops.h" #include "BLI_threads.h" #include "BLI_math.h" #include "BLI_utildefines.h" @@ -125,7 +126,7 @@ static void get_fluid_gravity(float *gravity, Scene *scene, FluidsimSettings *fs if (scene->physics_settings.flag & PHYS_GLOBAL_GRAVITY) { copy_v3_v3(gravity, scene->physics_settings.gravity); } else { - copy_v3_v3(gravity, &fss->gravx); + copy_v3_v3(gravity, fss->grav); } } @@ -442,8 +443,8 @@ static void fluid_init_all_channels(bContext *C, Object *UNUSED(fsDomain), Fluid for (fobj=fobjects->first; fobj; fobj=fobj->next) { Object *ob = fobj->object; FluidsimModifierData *fluidmd = (FluidsimModifierData *)modifiers_findByType(ob, eModifierType_Fluidsim); - float active= (float)(fluidmd->fss->flag & OB_FLUIDSIM_ACTIVE); - float rot_d[3], old_rot[3] = {0.f, 0.f, 0.f}; + float active= (float)(fluidmd->fss->flag && OB_FLUIDSIM_ACTIVE); + float rot_d[3] = {0.f, 0.f, 0.f}, old_rot[3] = {0.f, 0.f, 0.f}; if (ELEM(fluidmd->fss->type, OB_FLUIDSIM_DOMAIN, OB_FLUIDSIM_PARTICLE)) continue; @@ -809,6 +810,44 @@ static void fluidbake_free_data(FluidAnimChannels *channels, ListBase *fobjects, } } +/* copied from rna_fluidsim.c: fluidsim_find_lastframe() */ +static void fluidsim_delete_until_lastframe(FluidsimSettings *fss) +{ + char targetDir[FILE_MAXFILE+FILE_MAXDIR], targetFile[FILE_MAXFILE+FILE_MAXDIR]; + char targetDirVel[FILE_MAXFILE+FILE_MAXDIR], targetFileVel[FILE_MAXFILE+FILE_MAXDIR]; + char previewDir[FILE_MAXFILE+FILE_MAXDIR], previewFile[FILE_MAXFILE+FILE_MAXDIR]; + int curFrame = 1, exists = 0; + + BLI_snprintf(targetDir, sizeof(targetDir), "%sfluidsurface_final_####.bobj.gz", fss->surfdataPath); + BLI_snprintf(targetDirVel, sizeof(targetDir), "%sfluidsurface_final_####.bvel.gz", fss->surfdataPath); + BLI_snprintf(previewDir, sizeof(targetDir), "%sfluidsurface_preview_####.bobj.gz", fss->surfdataPath); + + BLI_path_abs(targetDir, G.main->name); + BLI_path_abs(targetDirVel, G.main->name); + BLI_path_abs(previewDir, G.main->name); + + do { + BLI_strncpy(targetFile, targetDir, sizeof(targetFile)); + BLI_strncpy(targetFileVel, targetDirVel, sizeof(targetFileVel)); + BLI_strncpy(previewFile, previewDir, sizeof(previewFile)); + + BLI_path_frame(targetFile, curFrame, 0); + BLI_path_frame(targetFileVel, curFrame, 0); + BLI_path_frame(previewFile, curFrame, 0); + + curFrame++; + + if(exists = BLI_exist(targetFile)) + { + BLI_delete(targetFile, 0, 0); + BLI_delete(targetFileVel, 0, 0); + BLI_delete(previewFile, 0, 0); + } + } while(exists); + + return; +} + static int fluidsimBake(bContext *C, ReportList *reports, Object *fsDomain) { Scene *scene= CTX_data_scene(C); @@ -878,6 +917,9 @@ static int fluidsimBake(bContext *C, ReportList *reports, Object *fsDomain) // reset last valid frame domainSettings->lastgoodframe = -1; + + /* delete old baked files */ + fluidsim_delete_until_lastframe(domainSettings); /* rough check of settings... */ if(domainSettings->previewresxyz > domainSettings->resolutionxyz) { @@ -1018,6 +1060,13 @@ static int fluidsimBake(bContext *C, ReportList *reports, Object *fsDomain) else if (domainSettings->typeFlags&OB_FSBND_PARTSLIP) fsset->domainobsType = FLUIDSIM_OBSTACLE_PARTSLIP; else if (domainSettings->typeFlags&OB_FSBND_FREESLIP) fsset->domainobsType = FLUIDSIM_OBSTACLE_FREESLIP; fsset->domainobsPartslip = domainSettings->partSlipValue; + + /* use domainobsType also for surface generation flag (bit: >=64) */ + if(domainSettings->typeFlags & OB_FSSG_NOOBS) + fsset->mFsSurfGenSetting = FLUIDSIM_FSSG_NOOBS; + else + fsset->mFsSurfGenSetting = 0; // "normal" mode + fsset->generateVertexVectors = (domainSettings->domainNovecgen==0); // init blender domain transform matrix diff --git a/source/blender/makesdna/DNA_object_fluidsim.h b/source/blender/makesdna/DNA_object_fluidsim.h index 6f4c16cb7f3..578bf8dd415 100644 --- a/source/blender/makesdna/DNA_object_fluidsim.h +++ b/source/blender/makesdna/DNA_object_fluidsim.h @@ -69,7 +69,7 @@ typedef struct FluidsimSettings { short viscosityMode; short viscosityExponent; /* gravity strength */ - float gravx,gravy,gravz; + float grav[3]; /* anim start end time (in seconds) */ float animStart, animEnd; /* bake start end time (in blender frames) */ @@ -161,6 +161,9 @@ typedef struct FluidsimSettings { #define OB_FSBND_FREESLIP (1<<(OB_TYPEFLAG_START+4)) #define OB_FSINFLOW_LOCALCOORD (1<<(OB_TYPEFLAG_START+5)) +/* surface generation flag (part of enabling chapter 6 of "Free Surface Flows with Moving and Deforming Objects for LBM") */ +#define OB_FSSG_NOOBS (1<<(OB_TYPEFLAG_START+6)) + // guiDisplayMode particle flags #define OB_FSDOM_GEOM 1 #define OB_FSDOM_PREVIEW 2 diff --git a/source/blender/makesrna/intern/rna_fluidsim.c b/source/blender/makesrna/intern/rna_fluidsim.c index 7c93ae4168b..1ba2e32502f 100644 --- a/source/blender/makesrna/intern/rna_fluidsim.c +++ b/source/blender/makesrna/intern/rna_fluidsim.c @@ -312,7 +312,7 @@ static void rna_def_fluidsim_domain(BlenderRNA *brna) /* advanced settings */ prop= RNA_def_property(srna, "gravity", PROP_FLOAT, PROP_ACCELERATION); - RNA_def_property_float_sdna(prop, NULL, "gravx"); + RNA_def_property_float_sdna(prop, NULL, "grav"); RNA_def_property_array(prop, 3); RNA_def_property_range(prop, -1000.1, 1000.1); RNA_def_property_ui_text(prop, "Gravity", "Gravity in X, Y and Z direction"); @@ -384,6 +384,12 @@ static void rna_def_fluidsim_domain(BlenderRNA *brna) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); RNA_def_property_ui_text(prop, "Generate Speed Vectors", "Generate speed vectors for vector blur"); + /* no collision object surface */ + prop= RNA_def_property(srna, "surface_noobs", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "typeFlags", OB_FSSG_NOOBS); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); + RNA_def_property_ui_text(prop, "Hide fluid surface", ""); + /* particles */ prop= RNA_def_property(srna, "tracer_particles", PROP_INT, PROP_NONE); diff --git a/source/blender/modifiers/intern/MOD_fluidsim_util.c b/source/blender/modifiers/intern/MOD_fluidsim_util.c index 61345427d1c..277f0852f90 100644 --- a/source/blender/modifiers/intern/MOD_fluidsim_util.c +++ b/source/blender/modifiers/intern/MOD_fluidsim_util.c @@ -90,10 +90,10 @@ void fluidsim_init(FluidsimModifierData *fluidmd) fss->viscosityValue = 1.0; fss->viscosityExponent = 6; - // dg TODO: change this to [] - fss->gravx = 0.0; - fss->gravy = 0.0; - fss->gravz = -9.81; + fss->grav[0] = 0.0; + fss->grav[1] = 0.0; + fss->grav[2] = -9.81; + fss->animStart = 0.0; fss->animEnd = 4.0; fss->gstar = 0.005; // used as normgstar @@ -111,7 +111,7 @@ void fluidsim_init(FluidsimModifierData *fluidmd) // no bounding box needed // todo - reuse default init from elbeem! - fss->typeFlags = OB_FSBND_PARTSLIP; + fss->typeFlags = OB_FSBND_PARTSLIP | OB_FSSG_NOOBS; fss->domainNovecgen = 0; fss->volumeInitType = 1; // volume fss->partSlipValue = 0.2;