svn merge ^/trunk/blender -r40644:40720
[blender.git] / source / blender / modifiers / intern / MOD_fluidsim_util.c
index eb556e31aba1f83dca450773e1b5f6c6d791a037..a42e8475e8d1c23becf1a0be4ad7758db2375519 100644 (file)
 *
 */
 
+/** \file blender/modifiers/intern/MOD_fluidsim_util.c
+ *  \ingroup modifiers
+ */
+
+
 #include <stddef.h>
 #include <zlib.h>
 
 #include "BLI_utildefines.h"
 
 #include "BKE_main.h"
+#include "BKE_fluidsim.h" /* ensure definitions here match */
 #include "BKE_cdderivedmesh.h"
 #include "BKE_mesh.h"
 #include "BKE_utildefines.h"
 #include "BKE_global.h" /* G.main->name only */
 
+#include "MOD_fluidsim_util.h"
 #include "MOD_modifiertypes.h"
 
 #include "MEM_guardedalloc.h"
@@ -83,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
@@ -104,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;
@@ -132,8 +139,7 @@ void fluidsim_init(FluidsimModifierData *fluidmd)
                fluid_get_bb(mesh->mvert, mesh->totvert, ob->obmat, fss->bbStart, fss->bbSize); 
                */
                
-               // (ab)used to store velocities
-               fss->meshSurfNormals = NULL;
+               fss->meshVelocities = NULL;
                
                fss->lastgoodframe = -1;
                
@@ -151,10 +157,10 @@ void fluidsim_free(FluidsimModifierData *fluidmd)
 #ifndef DISABLE_ELBEEM
        if(fluidmd)
        {
-               if(fluidmd->fss->meshSurfNormals)
+               if(fluidmd->fss->meshVelocities)
                {
-                       MEM_freeN(fluidmd->fss->meshSurfNormals);
-                       fluidmd->fss->meshSurfNormals = NULL;
+                       MEM_freeN(fluidmd->fss->meshVelocities);
+                       fluidmd->fss->meshVelocities = NULL;
                }
                MEM_freeN(fluidmd->fss);
        }
@@ -167,7 +173,7 @@ void fluidsim_free(FluidsimModifierData *fluidmd)
 
 #ifndef DISABLE_ELBEEM
 /* read .bobj.gz file into a fluidsimDerivedMesh struct */
-DerivedMesh *fluidsim_read_obj(char *filename)
+static DerivedMesh *fluidsim_read_obj(const char *filename)
 {
        int wri = 0,i;
        int gotBytes;
@@ -220,7 +226,7 @@ DerivedMesh *fluidsim_read_obj(char *filename)
                return NULL;
        }
 
-       dm = CDDM_new(numverts, 0, numfaces);
+       dm = CDDM_new(numverts, 0, numfaces, 0, 0);
 
        if(!dm)
        {
@@ -276,7 +282,7 @@ DerivedMesh *fluidsim_read_obj(char *filename)
        }
 
        // read triangles from file
-       mf = CDDM_get_faces(dm);
+       mf = CDDM_get_tessfaces(dm);
        for(i=numfaces; i>0; i--, mf++)
        {
                int face[3];
@@ -379,7 +385,7 @@ void fluid_estimate_memory(Object *ob, FluidsimSettings *fss, char *value)
 
 
 /* read zipped fluidsim velocities into the co's of the fluidsimsettings normals struct */
-void fluidsim_read_vel_cache(FluidsimModifierData *fluidmd, DerivedMesh *dm, char *filename)
+static void fluidsim_read_vel_cache(FluidsimModifierData *fluidmd, DerivedMesh *dm, char *filename)
 {
        int wri, i, j;
        float wrf;
@@ -387,12 +393,12 @@ void fluidsim_read_vel_cache(FluidsimModifierData *fluidmd, DerivedMesh *dm, cha
        FluidsimSettings *fss = fluidmd->fss;
        int len = strlen(filename);
        int totvert = dm->getNumVerts(dm);
-       float *velarray = NULL;
+       FluidVertexVelocity *velarray = NULL;
 
        // mesh and vverts have to be valid from loading...
 
-       if(fss->meshSurfNormals)
-               MEM_freeN(fss->meshSurfNormals);
+       if(fss->meshVelocities)
+               MEM_freeN(fss->meshVelocities);
 
        if(len<7)
        {
@@ -401,12 +407,10 @@ void fluidsim_read_vel_cache(FluidsimModifierData *fluidmd, DerivedMesh *dm, cha
 
        if(fss->domainNovecgen>0) return;
 
-       // abusing pointer to hold an array of 3d-velocities
-       fss->meshSurfNormals = MEM_callocN(sizeof(float)*3*dm->getNumVerts(dm), "Fluidsim_velocities");
-       // abusing pointer to hold an INT
-       fss->meshSurface = SET_INT_IN_POINTER(totvert);
+       fss->meshVelocities = MEM_callocN(sizeof(FluidVertexVelocity)*dm->getNumVerts(dm), "Fluidsim_velocities");
+       fss->totvert = totvert;
 
-       velarray = (float *)fss->meshSurfNormals;
+       velarray = fss->meshVelocities;
 
        // .bobj.gz , correct filename
        // 87654321
@@ -417,16 +421,16 @@ void fluidsim_read_vel_cache(FluidsimModifierData *fluidmd, DerivedMesh *dm, cha
        gzf = gzopen(filename, "rb");
        if (!gzf)
        {
-               MEM_freeN(fss->meshSurfNormals);
-               fss->meshSurfNormals = NULL;
+               MEM_freeN(fss->meshVelocities);
+               fss->meshVelocities = NULL;
                return;
        }
 
        gzread(gzf, &wri, sizeof( wri ));
        if(wri != totvert)
        {
-               MEM_freeN(fss->meshSurfNormals);
-               fss->meshSurfNormals = NULL;
+               MEM_freeN(fss->meshVelocities);
+               fss->meshVelocities = NULL;
                return;
        }
 
@@ -435,14 +439,14 @@ void fluidsim_read_vel_cache(FluidsimModifierData *fluidmd, DerivedMesh *dm, cha
                for(j=0; j<3; j++)
                {
                        gzread(gzf, &wrf, sizeof( wrf ));
-                       velarray[3*i + j] = wrf;
+                       velarray[i].vel[j] = wrf;
                }
        }
 
        gzclose(gzf);
 }
 
-DerivedMesh *fluidsim_read_cache(DerivedMesh *orgdm, FluidsimModifierData *fluidmd, int framenr, int useRenderParams)
+static DerivedMesh *fluidsim_read_cache(DerivedMesh *orgdm, FluidsimModifierData *fluidmd, int framenr, int useRenderParams)
 {
        int displaymode = 0;
        int curFrame = framenr - 1 /*scene->r.sfra*/; /* start with 0 at start frame */
@@ -459,7 +463,7 @@ DerivedMesh *fluidsim_read_cache(DerivedMesh *orgdm, FluidsimModifierData *fluid
                displaymode = fss->renderDisplayMode;
        }
 
-       strncpy(targetDir, fss->surfdataPath, FILE_MAXDIR);
+       BLI_strncpy(targetDir, fss->surfdataPath, sizeof(targetDir));
 
        // use preview or final mesh?
        if(displaymode==1)
@@ -479,8 +483,7 @@ DerivedMesh *fluidsim_read_cache(DerivedMesh *orgdm, FluidsimModifierData *fluid
        BLI_path_abs(targetDir, G.main->name);
        BLI_path_frame(targetDir, curFrame, 0); // fixed #frame-no
 
-       strcpy(targetFile,targetDir);
-       strcat(targetFile, ".bobj.gz");
+       BLI_snprintf(targetFile, sizeof(targetFile), "%s.bobj.gz", targetDir);
 
        dm = fluidsim_read_obj(targetFile);
 
@@ -504,12 +507,12 @@ DerivedMesh *fluidsim_read_cache(DerivedMesh *orgdm, FluidsimModifierData *fluid
        }
 
        // assign material + flags to new dm
-       mface = orgdm->getFaceArray(orgdm);
+       mface = orgdm->getTessFaceArray(orgdm);
        mat_nr = mface[0].mat_nr;
        flag = mface[0].flag;
 
-       mface = dm->getFaceArray(dm);
-       numfaces = dm->getNumFaces(dm);
+       mface = dm->getTessFaceArray(dm);
+       numfaces = dm->getNumTessFaces(dm);
        for(i=0; i<numfaces; i++)
        {
                mface[i].mat_nr = mat_nr;
@@ -525,10 +528,10 @@ DerivedMesh *fluidsim_read_cache(DerivedMesh *orgdm, FluidsimModifierData *fluid
        }
        else
        {
-               if(fss->meshSurfNormals)
-                       MEM_freeN(fss->meshSurfNormals);
+               if(fss->meshVelocities)
+                       MEM_freeN(fss->meshVelocities);
 
-               fss->meshSurfNormals = NULL;
+               fss->meshVelocities = NULL;
        }
 
        return dm;
@@ -538,7 +541,7 @@ DerivedMesh *fluidsim_read_cache(DerivedMesh *orgdm, FluidsimModifierData *fluid
 DerivedMesh *fluidsimModifier_do(FluidsimModifierData *fluidmd, Scene *scene,
                                                Object *UNUSED(ob),
                                                DerivedMesh *dm,
-                                               int useRenderParams)
+                                               int useRenderParams, int UNUSED(isFinalCalc))
 {
 #ifndef DISABLE_ELBEEM
        DerivedMesh *result = NULL;