From 1708ac07231cd222f269d3c0ddb9e22aba7aeec4 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 9 Mar 2010 17:36:23 +0000 Subject: rename some functions to use easier to understand names. 'BLI_makestringcode' --> 'BLI_path_rel' 'BLI_convertstringcwd' --> 'BLI_path_cwd' 'BLI_convertstringframe' --> 'BLI_path_frame' 'BLI_convertstringframe_range' --> 'BLI_path_frame_range' 'BLI_make_cwdpath' --> 'BLI_path_cwd' --- source/blender/blenkernel/intern/fluidsim.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source/blender/blenkernel/intern/fluidsim.c') diff --git a/source/blender/blenkernel/intern/fluidsim.c b/source/blender/blenkernel/intern/fluidsim.c index 7d1f0510d71..22eb0578f72 100644 --- a/source/blender/blenkernel/intern/fluidsim.c +++ b/source/blender/blenkernel/intern/fluidsim.c @@ -431,8 +431,8 @@ DerivedMesh *fluidsim_read_cache(Object *ob, DerivedMesh *orgdm, FluidsimModifie strcat(targetDir,"fluidsurface_final_####"); } - BLI_convertstringcode(targetDir, G.sce); - BLI_convertstringframe(targetDir, curFrame, 0); // fixed #frame-no + BLI_path_abs(targetDir, G.sce); + BLI_path_frame(targetDir, curFrame, 0); // fixed #frame-no strcpy(targetFile,targetDir); strcat(targetFile, ".bobj.gz"); -- cgit v1.2.3 From 1e9bf0cfdb6c925b28af6f0330467e7d9d798c05 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 22 Mar 2010 09:30:00 +0000 Subject: spaces -> tabs, (4 spaces == 1 tab, only for white space preceding text) --- source/blender/blenkernel/intern/fluidsim.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source/blender/blenkernel/intern/fluidsim.c') diff --git a/source/blender/blenkernel/intern/fluidsim.c b/source/blender/blenkernel/intern/fluidsim.c index 22eb0578f72..fe0f52e9b00 100644 --- a/source/blender/blenkernel/intern/fluidsim.c +++ b/source/blender/blenkernel/intern/fluidsim.c @@ -609,9 +609,9 @@ void fluid_get_bb(MVert *mvert, int totvert, float obmat[][4], //------------------------------------------------------------------------------- void initElbeemMesh(struct Scene *scene, struct Object *ob, - int *numVertices, float **vertices, - int *numTriangles, int **triangles, - int useGlobalCoords, int modifierIndex) + int *numVertices, float **vertices, + int *numTriangles, int **triangles, + int useGlobalCoords, int modifierIndex) { DerivedMesh *dm = NULL; MVert *mvert; -- cgit v1.2.3 From 33f880e8666e9bb0ed954fccb82bc23255a97868 Mon Sep 17 00:00:00 2001 From: Matt Ebb Date: Thu, 25 Mar 2010 06:27:25 +0000 Subject: Restored Fluid Sim baking This commit restores fluid sim baking functionality in 2.5, it's been on the todo for a while, and was previously almost completely non-functional. The old code was quite complicated and specific to the 2.4 animation system, so I've pretty much rewritten most of it. This includes: * Animated variables work again - just key them in the UI. Non-animateable values should be already set non-animateable in RNA, hopefully I got them all. Available are: Domain Gravity / Domain Viscosity / Object loc/rot/scale / Object initial velocity / Deforming meshes / Fluid control Attract strength / Fluid control Attract radius / Fluid control Velocity strength / Fluid control Velocity radius / Object Active status (checkbox next to fluid type) The Domain time scale is still not yet implemented. * Fluid sim now use global scene units data by default - when enabled, the scene's global gravity value is used and when units are set (metric/imperial) the simulation real world size is taken from the object's actual measurements. * The baking process is now done in the background, using the nifty threaded Jobs system. It's non-blocking and your domain object will show the simulated fluid as it becomes available for that frame. A nice extra thing for the future would be to improve the visualisation of the object's state while baking, and also the jobs system/ui could do with some touchups - currently it has to share a bit from the 'render' job, and appears as 'Render' in the header. Progress bars for jobs in the header would be great too. --- source/blender/blenkernel/intern/fluidsim.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender/blenkernel/intern/fluidsim.c') diff --git a/source/blender/blenkernel/intern/fluidsim.c b/source/blender/blenkernel/intern/fluidsim.c index fe0f52e9b00..118a44507c9 100644 --- a/source/blender/blenkernel/intern/fluidsim.c +++ b/source/blender/blenkernel/intern/fluidsim.c @@ -148,7 +148,7 @@ void fluidsim_init(FluidsimModifierData *fluidmd) fss->lastgoodframe = -1; - fss->flag = 0; + fss->flag |= OB_FLUIDSIM_ACTIVE; } #endif -- cgit v1.2.3 From 3fdaf5cecc9c7c521c4db514f916f083b17881a6 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 11 Apr 2010 22:12:30 +0000 Subject: [#14437] Modifier Stack Refactor patch by Ben Batt (artificer) Updated patch for 6 or so modifiers added since the patch was written. - tested with CMake and SCons - fixed one error were flags were being added to the fluids type. - remove BKE_simple_deform.h, simple_deform.c, move functions into MOD_simpledeform.c since there were problems with circular deps. - moved some fluid and boolean functions used by modifiers too. --- source/blender/blenkernel/intern/fluidsim.c | 579 +--------------------------- 1 file changed, 10 insertions(+), 569 deletions(-) (limited to 'source/blender/blenkernel/intern/fluidsim.c') diff --git a/source/blender/blenkernel/intern/fluidsim.c b/source/blender/blenkernel/intern/fluidsim.c index 118a44507c9..8a6f0af87d1 100644 --- a/source/blender/blenkernel/intern/fluidsim.c +++ b/source/blender/blenkernel/intern/fluidsim.c @@ -62,556 +62,15 @@ /* ************************* fluidsim bobj file handling **************************** */ -// ----------------------------------------- -// forward decleration -// ----------------------------------------- - -// ----------------------------------------- - -void fluidsim_init(FluidsimModifierData *fluidmd) -{ -#ifndef DISABLE_ELBEEM - if(fluidmd) - { - FluidsimSettings *fss = MEM_callocN(sizeof(FluidsimSettings), "fluidsimsettings"); - - fluidmd->fss = fss; - - if(!fss) - return; - - fss->fmd = fluidmd; - fss->type = OB_FLUIDSIM_ENABLE; - fss->show_advancedoptions = 0; - - fss->resolutionxyz = 65; - fss->previewresxyz = 45; - fss->realsize = 0.5; - 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 = 4.0; - 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 = OB_FSBND_PARTSLIP; - fss->domainNovecgen = 0; - fss->volumeInitType = 1; // volume - fss->partSlipValue = 0.2; - - fss->generateTracers = 0; - fss->generateParticles = 0.0; - fss->surfaceSmoothing = 1.0; - fss->surfaceSubdivs = 0.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); - */ - - // (ab)used to store velocities - fss->meshSurfNormals = NULL; - - fss->lastgoodframe = -1; - - fss->flag |= OB_FLUIDSIM_ACTIVE; - - } -#endif - return; -} - -void fluidsim_free(FluidsimModifierData *fluidmd) -{ -#ifndef DISABLE_ELBEEM - if(fluidmd) - { - if(fluidmd->fss->meshSurfNormals) - { - MEM_freeN(fluidmd->fss->meshSurfNormals); - fluidmd->fss->meshSurfNormals = NULL; - } - MEM_freeN(fluidmd->fss); - } -#endif - return; -} - -DerivedMesh *fluidsimModifier_do(FluidsimModifierData *fluidmd, Scene *scene, Object *ob, DerivedMesh *dm, int useRenderParams, int isFinalCalc) -{ -#ifndef DISABLE_ELBEEM - DerivedMesh *result = NULL; - int framenr; - FluidsimSettings *fss = NULL; - - framenr= (int)scene->r.cfra; - - // only handle fluidsim domains - if(fluidmd && fluidmd->fss && (fluidmd->fss->type != OB_FLUIDSIM_DOMAIN)) - return dm; - - // sanity check - if(!fluidmd || (fluidmd && !fluidmd->fss)) - return dm; - - fss = fluidmd->fss; - - // timescale not supported yet - // clmd->sim_parms->timescale= timescale; - - // support reversing of baked fluid frames here - if((fss->flag & OB_FLUIDSIM_REVERSE) && (fss->lastgoodframe >= 0)) - { - framenr = fss->lastgoodframe - framenr + 1; - CLAMP(framenr, 1, fss->lastgoodframe); - } - - /* try to read from cache */ - if(((fss->lastgoodframe >= framenr) || (fss->lastgoodframe < 0)) && (result = fluidsim_read_cache(ob, dm, fluidmd, framenr, useRenderParams))) - { - // fss->lastgoodframe = framenr; // set also in src/fluidsim.c - return result; - } - else - { - // display last known good frame - if(fss->lastgoodframe >= 0) - { - if((result = fluidsim_read_cache(ob, dm, fluidmd, fss->lastgoodframe, useRenderParams))) - { - return result; - } - - // it was supposed to be a valid frame but it isn't! - fss->lastgoodframe = framenr - 1; - - - // this could be likely the case when you load an old fluidsim - if((result = fluidsim_read_cache(ob, dm, fluidmd, fss->lastgoodframe, useRenderParams))) - { - return result; - } - } - - result = CDDM_copy(dm); - - if(result) - { - return result; - } - } - - return dm; -#else - return NULL; -#endif -} - -#ifndef DISABLE_ELBEEM -/* 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; - 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; ico[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; iv1 = face[0]; - mf->v2 = face[1]; - mf->v3 = face[2]; - } - else - { - mf->v1 = face[1]; - mf->v2 = face[2]; - mf->v3 = face[0]; - } - mf->v4 = face[3]; - - test_index_face(mf, NULL, 0, 3); - } - - gzclose( gzf ); - - CDDM_calc_edges(dm); - - CDDM_apply_vert_normals(dm, (short (*)[3])normals); - MEM_freeN(normals); - - // CDDM_calc_normals(result); - - return dm; -} - -DerivedMesh *fluidsim_read_cache(Object *ob, DerivedMesh *orgdm, FluidsimModifierData *fluidmd, int framenr, int useRenderParams) -{ - int displaymode = 0; - int curFrame = framenr - 1 /*scene->r.sfra*/; /* start with 0 at start frame */ - char targetDir[FILE_MAXFILE+FILE_MAXDIR], targetFile[FILE_MAXFILE+FILE_MAXDIR]; - FluidsimSettings *fss = fluidmd->fss; - DerivedMesh *dm = NULL; - MFace *mface; - int numfaces; - int mat_nr, flag, i; - - if(!useRenderParams) { - displaymode = fss->guiDisplayMode; - } else { - displaymode = fss->renderDisplayMode; - } - - strncpy(targetDir, fss->surfdataPath, FILE_MAXDIR); - - // use preview or final mesh? - if(displaymode==1) - { - // just display original object - return NULL; - } - else if(displaymode==2) - { - strcat(targetDir,"fluidsurface_preview_####"); - } - else - { // 3 - strcat(targetDir,"fluidsurface_final_####"); - } - - BLI_path_abs(targetDir, G.sce); - BLI_path_frame(targetDir, curFrame, 0); // fixed #frame-no - - strcpy(targetFile,targetDir); - strcat(targetFile, ".bobj.gz"); - - dm = fluidsim_read_obj(targetFile); - - if(!dm) - { - // switch, abort background rendering when fluidsim mesh is missing - const char *strEnvName2 = "BLENDER_ELBEEMBOBJABORT"; // from blendercall.cpp - - if(G.background==1) { - if(getenv(strEnvName2)) { - int elevel = atoi(getenv(strEnvName2)); - if(elevel>0) { - printf("Env. var %s set, fluid sim mesh '%s' not found, aborting render...\n",strEnvName2, targetFile); - exit(1); - } - } - } - - // display org. object upon failure which is in dm - return NULL; - } - - // assign material + flags to new dm - mface = orgdm->getFaceArray(orgdm); - mat_nr = mface[0].mat_nr; - flag = mface[0].flag; - - mface = dm->getFaceArray(dm); - numfaces = dm->getNumFaces(dm); - for(i=0; imeshSurfNormals) - MEM_freeN(fss->meshSurfNormals); - - fss->meshSurfNormals = NULL; - } - - return dm; -} - - -/* read zipped fluidsim velocities into the co's of the fluidsimsettings normals struct */ -void fluidsim_read_vel_cache(FluidsimModifierData *fluidmd, DerivedMesh *dm, char *filename) -{ - int wri, i, j; - float wrf; - gzFile gzf; - FluidsimSettings *fss = fluidmd->fss; - int len = strlen(filename); - int totvert = dm->getNumVerts(dm); - float *velarray = NULL; - - // mesh and vverts have to be valid from loading... - - if(fss->meshSurfNormals) - MEM_freeN(fss->meshSurfNormals); - - if(len<7) - { - return; - } - - 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); - - velarray = (float *)fss->meshSurfNormals; - - // .bobj.gz , correct filename - // 87654321 - filename[len-6] = 'v'; - filename[len-5] = 'e'; - filename[len-4] = 'l'; - - gzf = gzopen(filename, "rb"); - if (!gzf) - { - MEM_freeN(fss->meshSurfNormals); - fss->meshSurfNormals = NULL; - return; - } - - gzread(gzf, &wri, sizeof( wri )); - if(wri != totvert) - { - MEM_freeN(fss->meshSurfNormals); - fss->meshSurfNormals = NULL; - return; - } - - for(i=0; i bbex){ bbex= vec[0]; } - if(vec[1] > bbey){ bbey= vec[1]; } - if(vec[2] > bbez){ bbez= vec[2]; } - } - - // return values... - if(start) { - start[0] = bbsx; - start[1] = bbsy; - start[2] = bbsz; - } - if(size) { - size[0] = bbex-bbsx; - size[1] = bbey-bbsy; - size[2] = bbez-bbsz; - } -} - -//------------------------------------------------------------------------------- -// old interface -//------------------------------------------------------------------------------- - - //------------------------------------------------------------------------------- // file handling //------------------------------------------------------------------------------- -void initElbeemMesh(struct Scene *scene, struct Object *ob, - int *numVertices, float **vertices, +void initElbeemMesh(struct Scene *scene, struct Object *ob, + int *numVertices, float **vertices, int *numTriangles, int **triangles, - int useGlobalCoords, int modifierIndex) + int useGlobalCoords, int modifierIndex) { DerivedMesh *dm = NULL; MVert *mvert; @@ -650,14 +109,14 @@ void initElbeemMesh(struct Scene *scene, struct Object *ob, face[2] = mface[i].v3; face[3] = mface[i].v4; - tris[countTris*3+0] = face[0]; - tris[countTris*3+1] = face[1]; - tris[countTris*3+2] = face[2]; + tris[countTris*3+0] = face[0]; + tris[countTris*3+1] = face[1]; + tris[countTris*3+2] = face[2]; countTris++; - if(face[3]) { - tris[countTris*3+0] = face[0]; - tris[countTris*3+1] = face[2]; - tris[countTris*3+2] = face[3]; + if(face[3]) { + tris[countTris*3+0] = face[0]; + tris[countTris*3+1] = face[2]; + tris[countTris*3+2] = face[3]; countTris++; } } @@ -665,21 +124,3 @@ void initElbeemMesh(struct Scene *scene, struct Object *ob, dm->release(dm); } - -void fluid_estimate_memory(Object *ob, FluidsimSettings *fss, char *value) -{ - Mesh *mesh; - - value[0]= '\0'; - - if(ob->type == OB_MESH) { - /* use mesh bounding box and object scaling */ - mesh= ob->data; - - fluid_get_bb(mesh->mvert, mesh->totvert, ob->obmat, fss->bbStart, fss->bbSize); - elbeemEstimateMemreq(fss->resolutionxyz, fss->bbSize[0],fss->bbSize[1],fss->bbSize[2], fss->maxRefine, value); - } -} - -#endif // DISABLE_ELBEEM - -- cgit v1.2.3