Revision: 15791
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15791
Author:   genscher
Date:     2008-07-27 01:53:44 +0200 (Sun, 27 Jul 2008)

Log Message:
-----------
Forgot some files in last commit, but simulation will crash anyway

Added Paths:
-----------
    branches/fluidcontrol/source/blender/blenkernel/BKE_fluidsim.h
    branches/fluidcontrol/source/blender/blenkernel/intern/fluidsim.c

Added: branches/fluidcontrol/source/blender/blenkernel/BKE_fluidsim.h
===================================================================
--- branches/fluidcontrol/source/blender/blenkernel/BKE_fluidsim.h              
                (rev 0)
+++ branches/fluidcontrol/source/blender/blenkernel/BKE_fluidsim.h      
2008-07-26 23:53:44 UTC (rev 15791)
@@ -0,0 +1,57 @@
+/**
+ * BKE_fluidsim.h
+ * 
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) Blender Foundation
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include "DNA_modifier_types.h"
+#include "DNA_object_fluidsim.h" // N_T
+#include "DNA_object_types.h"
+
+#include "BKE_DerivedMesh.h"
+
+/* old interface */
+FluidsimSettings *fluidsimSettingsNew(struct Object *srcob);
+
+
+void initElbeemMesh(Object *ob, int *numVertices, float **vertices, int 
*numTriangles, int **triangles, int useGlobalCoords);
+
+void loadFluidsimMesh(Object *srcob, int useRenderParams);
+
+
+/* new fluid-modifier interface */
+void fluidsim_init(FluidsimModifierData *fluidmd);
+void fluidsim_free(FluidsimModifierData *fluidmd);
+
+DerivedMesh *fluidsim_read_cache(Object *ob, FluidsimModifierData *fluidmd, 
int framenr, int useRenderParams);
+DerivedMesh *fluidsimModifier_do(FluidsimModifierData *fluidmd, Object *ob, 
DerivedMesh *dm, int useRenderParams, int isFinalCalc);
+
+void fluid_get_bb(MVert *mvert, int totvert, float obmat[][4],
+                /*RET*/ float start[3], /*RET*/ float size[3] );
+
+
+

Added: branches/fluidcontrol/source/blender/blenkernel/intern/fluidsim.c
===================================================================
--- branches/fluidcontrol/source/blender/blenkernel/intern/fluidsim.c           
                (rev 0)
+++ branches/fluidcontrol/source/blender/blenkernel/intern/fluidsim.c   
2008-07-26 23:53:44 UTC (rev 15791)
@@ -0,0 +1,702 @@
+/**
+ * fluidsim.c
+ * 
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) Blender Foundation
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
+#include "DNA_object_force.h" // for pointcache 
+#include "DNA_particle_types.h"
+#include "DNA_scene_types.h" // N_T
+
+#include "BLI_arithb.h"
+#include "BLI_blenlib.h"
+
+#include "BKE_cdderivedmesh.h"
+#include "BKE_customdata.h"
+#include "BKE_DerivedMesh.h"
+#include "BKE_fluidsim.h"
+#include "BKE_global.h"
+#include "BKE_modifier.h"
+#include "BKE_mesh.h"
+#include "BKE_pointcache.h"
+#include "BKE_utildefines.h"
+
+// headers for fluidsim bobj meshes
+#include <stdlib.h>
+#include "LBM_fluidsim.h"
+#include "elbeem.h"
+#include <zlib.h>
+#include <string.h>
+#include <stdio.h>
+
+/* ************************* fluidsim bobj file handling 
**************************** */
+
+#ifndef DISABLE_ELBEEM
+
+// -----------------------------------------
+// forward decleration
+// -----------------------------------------
+
+// -----------------------------------------
+
+void fluidsim_init(FluidsimModifierData *fluidmd)
+{
+       if(fluidmd)
+       {
+               FluidsimSettings *fss = MEM_callocN(sizeof(FluidsimSettings), 
"fluidsimsettings");
+               
+               fluidmd->fss = fss;
+               
+               if(!fss)
+                       return;
+               
+               fss->type = 0;
+               fss->show_advancedoptions = 0;
+
+               fss->resolutionxyz = 50;
+               fss->previewresxyz = 25;
+               fss->realsize = 0.03;
+               fss->guiDisplayMode = 2; // preview
+               fss->renderDisplayMode = 3; // render
+
+               fss->viscosityMode = 2; // default to water
+               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->animStart = 0.0; 
+               fss->animEnd = 0.30;
+               fss->gstar = 0.005; // used as normgstar
+               fss->maxRefine = -1;
+               // maxRefine is set according to resolutionxyz during bake
+
+               // fluid/inflow settings
+               // fss->iniVel --> automatically set to 0
+
+               /*  elubie: changed this to default to the same dir as the 
render output
+               to prevent saving to C:\ on Windows */
+               BLI_strncpy(fss->surfdataPath, btempdir, FILE_MAX);
+
+               // first init of bounding box
+               // no bounding box needed
+               
+               // todo - reuse default init from elbeem!
+               fss->typeFlags = 0;
+               fss->domainNovecgen = 0;
+               fss->volumeInitType = 1; // volume
+               fss->partSlipValue = 0.0;
+
+               fss->generateTracers = 0;
+               fss->generateParticles = 0.0;
+               fss->surfaceSmoothing = 1.0;
+               fss->surfaceSubdivs = 1.0;
+               fss->particleInfSize = 0.0;
+               fss->particleInfAlpha = 0.0;
+       
+               // init fluid control settings
+               fss->attractforceStrength = 0.2;
+               fss->attractforceRadius = 0.75;
+               fss->velocityforceStrength = 0.2;
+               fss->velocityforceRadius = 0.75;
+               fss->cpsTimeStart = fss->animStart;
+               fss->cpsTimeEnd = fss->animEnd;
+               fss->cpsQuality = 10.0; // 1.0 / 10.0 => means 0.1 width
+               
+               /*
+               BAD TODO: this is done in buttons_object.c in the moment 
+               Mesh *mesh = ob->data;
+               // calculate bounding box
+               fluid_get_bb(mesh->mvert, mesh->totvert, ob->obmat, 
fss->bbStart, fss->bbSize); 
+               */
+               
+               fss->lastgoodframe = -1;
+
+       }
+       
+       return;
+}
+
+void fluidsim_free(FluidsimModifierData *fluidmd)
+{
+       if(fluidmd)
+       {
+               MEM_freeN(fluidmd->fss);
+       }
+       
+       return;
+}
+
+DerivedMesh *fluidsimModifier_do(FluidsimModifierData *fluidmd, Object *ob, 
DerivedMesh *dm, int useRenderParams, int isFinalCalc)
+{
+       DerivedMesh *result = NULL;
+       int framenr;
+       FluidsimSettings *fss;
+
+       framenr= (int)G.scene->r.cfra;
+       
+       // only handle fluidsim domains
+       if(fluidmd && fluidmd->fss && (fluidmd->fss->type != 
OB_FLUIDSIM_DOMAIN))
+               return dm;
+       
+       // timescale not supported yet
+       // clmd->sim_parms->timescale= timescale;
+       
+       /* try to read from cache */
+       if((result = fluidsim_read_cache(ob, fluidmd, framenr, 
useRenderParams))) {
+               fss->lastgoodframe = framenr;
+               return result;
+       }
+       else
+       {
+               // display last known good frame
+               if(fss->lastgoodframe >= 0)
+               {
+                       if((result = fluidsim_read_cache(ob, fluidmd, framenr, 
useRenderParams))) {
+                               return result;
+                       }
+               }
+               
+               result = CDDM_copy(dm);
+
+               if(!result) {
+                       return dm;
+               }
+       }
+
+       return result;
+}
+
+/* read .bobj.gz file into a fluidsimDerivedMesh struct */
+static DerivedMesh *fluidsim_read_obj(char *filename)
+{
+       int wri,i,j;
+       float wrf;
+       int gotBytes;
+       gzFile gzf;
+       int numverts = 0, numfaces = 0, numedges = 0;
+       DerivedMesh *dm = NULL;
+       MFace *mface;
+       MVert *mvert;
+       short *normals;
+               
+       // ------------------------------------------------
+       // get numverts + numfaces first
+       // ------------------------------------------------
+       gzf = gzopen(filename, "rb");
+       if (!gzf) 
+       {
+               return NULL;
+       }
+
+       // read numverts
+       gotBytes = gzread(gzf, &wri, sizeof(wri));
+       numverts = wri;
+       
+       // skip verts
+       for(i=0; i<numverts*3; i++) 
+       {       
+               gotBytes = gzread(gzf, &wrf, sizeof( wrf )); 
+       }
+       
+       // read number of normals
+       gotBytes = gzread(gzf, &wri, sizeof(wri));
+       
+       // skip normals
+       for(i=0; i<numverts*3; i++) 
+       {       
+               gotBytes = gzread(gzf, &wrf, sizeof( wrf )); 
+       }
+       
+       /* get no. of triangles */
+       gotBytes = gzread(gzf, &wri, sizeof(wri));
+       numfaces = wri;
+       
+       gzclose( gzf );
+       // ------------------------------------------------
+       
+       
+       // dg - TODO: check for numfaces / numverts = 0
+       if(!numfaces || !numverts)
+               return NULL;
+       
+       gzf = gzopen(filename, "rb");
+       if (!gzf) 
+       {
+               return NULL;
+       }
+       
+       dm = CDDM_new(numverts, 0, numfaces);
+       
+       if(!dm)
+       {
+               gzclose( gzf );
+               return NULL;
+       }
+       
+       // read numverts
+       gotBytes = gzread(gzf, &wri, sizeof(wri));
+
+       // read vertex position from file
+       mvert = CDDM_get_verts(dm);
+       for(i=0; i<numverts; i++) 
+       {
+               MVert *mv = &mvert[i];
+               
+               for(j=0; j<3; j++) 
+               {
+                       gotBytes = gzread(gzf, &wrf, sizeof( wrf )); 
+                       mv->co[j] = wrf;
+               }
+       }
+
+       // should be the same as numverts
+       gotBytes = gzread(gzf, &wri, sizeof(wri));
+       if(wri != numverts) 
+       {
+               if(dm)
+                       dm->release(dm);
+               gzclose( gzf );
+               return NULL;
+       }
+       /*
+       normals = MEM_callocN(sizeof(short) * numverts * 3, "fluid_tmp_normals" 
);      
+       if(!normals)
+       {
+               if(dm)
+                       dm->release(dm);
+               gzclose( gzf );
+               return NULL;
+       }       
+       */
+       // read normals from file (but don't save them yet)
+       for(i=0; i<numverts*3;i++) 
+       { 
+               gotBytes = gzread(gzf, &wrf, sizeof( wrf )); 
+               // normals[i] = (short)(wrf*32767.0f);
+       }
+       
+       
+       /* read no. of triangles */
+       gotBytes = gzread(gzf, &wri, sizeof(wri));
+       
+       if(wri!=numfaces)
+               printf("Fluidsim: error in reading data from file.\n");
+       
+       // read triangles from file
+       mface = CDDM_get_faces(dm);
+       for(i=0; i<numfaces; i++) 
+       {
+               int face[4];
+               MFace *mf = &mface[i];
+
+               gotBytes = gzread(gzf, &(face[0]), sizeof( face[0] )); 
+               gotBytes = gzread(gzf, &(face[1]), sizeof( face[1] )); 
+               gotBytes = gzread(gzf, &(face[2]), sizeof( face[2] )); 
+               face[3] = 0;
+
+               // check if 3rd vertex has index 0 (not allowed in blender)
+               if(face[2])
+               {
+                       mf->v1 = face[0];
+                       mf->v2 = face[1];
+                       mf->v3 = face[2];
+               }
+               else
+               {

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to