Elbeem / Fluidsim update:
authorDaniel Genrich <daniel.genrich@gmx.net>
Sun, 12 Jun 2011 23:51:30 +0000 (23:51 +0000)
committerDaniel Genrich <daniel.genrich@gmx.net>
Sun, 12 Jun 2011 23:51:30 +0000 (23:51 +0000)
a) Enable the possibility to remove the "air bubble" around submerged collision object. This feature is enabled as standard for new files. The code was found in elbeem by nudelZ, coded and provided by Nils Thürey (thanks!)
b) Old baked files gets deleted if a new bake gets started (were overwritten before and resulted in weird old bake + new bake mixture) (idea by nudelZ)

intern/elbeem/extern/elbeem.h
intern/elbeem/intern/simulation_object.cpp
intern/elbeem/intern/solver_class.h
intern/elbeem/intern/solver_init.cpp
intern/elbeem/intern/solver_interface.h
release/scripts/startup/bl_ui/properties_physics_fluid.py
source/blender/editors/physics/physics_fluid.c
source/blender/makesdna/DNA_object_fluidsim.h
source/blender/makesrna/intern/rna_fluidsim.c
source/blender/modifiers/intern/MOD_fluidsim_util.c

index f5538df88054d4588a68efd8a8c4898e7a026865..6df08ccebd2e44d7435304d3204a96d6161e6fdf 100644 (file)
@@ -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
index 2544b8fe29c6272e79324b1c802ff03ff0fc7526..87828b260888a075b2f7ffe0c92b7d649b4db064 100644 (file)
@@ -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"); 
index 8662ac3f12a1d6eb9cccbdd0baa929c2becc8f12..1548aaa19bc60d53cadb86c22f8361e5f91dae13 100644 (file)
@@ -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) 
index 899b1e0ecbc64f9b747b5f446edfd17355958852..7e9f5e7f4202e0d085d925623ecb05e74ceaae3b 100644 (file)
@@ -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)
  *****************************************************************************/
index 71b347d683dafc6305e726393fa497cd246ddb85..8f3181a307d314c58775367a2796e14e3586d466 100644 (file)
@@ -271,6 +271,9 @@ class LbmSolverInterface
                /*! debug object display */
                virtual vector<ntlGeometryObject*> getDebugObjects() { vector<ntlGeometryObject*> 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;
index 5da89d0090a59dbc1a51d0a1fbb26477687e1ad9..c7e3a9e722007efcf4150e305caeb3606dcc4ed7 100644 (file)
@@ -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:")
index 4aa9b942cf3421f838ba246e61e3618990292e93..d54048546fe01fe381fe60261871ec4af1aa555e 100644 (file)
@@ -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
index 6f4c16cb7f34b254fbb7cfede073a96d04438ca7..578bf8dd415788458ff126853d04d63b2bb0d9e2 100644 (file)
@@ -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
index 7c93ae4168bef222dfe28403f8caba1644ecd48f..1ba2e32502feee7c0e0f58889093c26a2eb12e37 100644 (file)
@@ -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);
index 61345427d1c9b2f3eca7c770a92486ad3332215e..277f0852f901985c31d8acd8ca3825360a075464 100644 (file)
@@ -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;