diff options
author | Nils Thuerey <nils@thuerey.de> | 2005-11-09 10:56:26 +0300 |
---|---|---|
committer | Nils Thuerey <nils@thuerey.de> | 2005-11-09 10:56:26 +0300 |
commit | e3f681da67989ed87a270a2c07849265d44bb7da (patch) | |
tree | 0f08613c0a39187dd7dbb84df7ff45f39936c36f /source | |
parent | 564b62901346ba0f40032616c51ac7da1c703a54 (diff) |
- popup menu now aborts by default
- changed directory/prefix input (only 1 string instead of two, more similar to render output settings now)
- changed reading/writing of surface files
- slightly enhanced surface smoothness
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/intern/DerivedMesh.c | 277 | ||||
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 2 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_object_fluidsim.h | 7 | ||||
-rw-r--r-- | source/blender/src/buttons_object.c | 52 | ||||
-rw-r--r-- | source/blender/src/fluidsim.c | 145 |
5 files changed, 232 insertions, 251 deletions
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index d06ff068deb..a620ce2fd1e 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -1958,136 +1958,7 @@ DerivedMesh *editmesh_get_derived_base(void) } -/* ***************************** fluidsim derived mesh ***************************** */ - -typedef struct { - MeshDerivedMesh mdm; - - /* release whole mesh? */ - char freeMesh; -} FluidsimDerivedMesh; - -#ifdef WIN32 -#ifndef snprintf -#define snprintf _snprintf -#endif -#endif - - -static void fluidsimDM_release(DerivedMesh *dm) -{ - FluidsimDerivedMesh *fsdm = (FluidsimDerivedMesh*) dm; - if(fsdm->freeMesh) { - // similar to free_mesh(fsdm->mdm.me) , but no things like unlink... - if(fsdm->mdm.me->mvert) MEM_freeN(fsdm->mdm.me->mvert); - if(fsdm->mdm.me->medge) MEM_freeN(fsdm->mdm.me->medge); - if(fsdm->mdm.me->mface) MEM_freeN(fsdm->mdm.me->mface); - MEM_freeN(fsdm->mdm.me); - } - - if (fsdm->mdm.freeNors) MEM_freeN(fsdm->mdm.nors); - if (fsdm->mdm.freeVerts) MEM_freeN(fsdm->mdm.verts); - MEM_freeN(fsdm); -} - -DerivedMesh *getFluidsimDerivedMesh(Object *srcob, int useRenderParams, float *extverts, float *nors) { - int i; - Mesh *mesh = NULL; // srcob->ata; - FluidsimDerivedMesh *fsdm; - MeshDerivedMesh *mdm = NULL; - float (*vertCos)[3]; - int displaymode = 0; - int curFrame = G.scene->r.cfra - 1; /* start with 0 */ - char filename[FILE_MAXFILE],filepath[FILE_MAXFILE+FILE_MAXDIR]; - char curWd[FILE_MAXDIR]; - char debugStrBuffer[256]; - //snprintf(debugStrBuffer,256,"getFluidsimDerivedMesh call (obid '%s', rp %d)\n", srcob->id.name, useRenderParams); // debug - - if(!useRenderParams) { - displaymode = srcob->fluidsimSettings->guiDisplayMode; - } else { - displaymode = srcob->fluidsimSettings->renderDisplayMode; - } - - snprintf(debugStrBuffer,256,"getFluidsimDerivedMesh call (obid '%s', rp %d, dm %d)\n", srcob->id.name, useRenderParams, displaymode); // debug - elbeemDebugOut(debugStrBuffer); // debug - - if((displaymode==1) || (G.obedit==srcob)) { - mesh = srcob->data; - return getMeshDerivedMesh(mesh , srcob, NULL); - } - - // init preview frame - if(displaymode==2) { - // use preview - snprintf(filename,FILE_MAXFILE,"%s_surface_preview_%04d.bobj.gz", srcob->fluidsimSettings->surfdataPrefix, curFrame); - } else { - // load final mesh - snprintf(filename,FILE_MAXFILE,"%s_surface_final_%04d.bobj.gz", srcob->fluidsimSettings->surfdataPrefix, curFrame); - } - BLI_getwdN(curWd); - BLI_make_file_string(G.sce, filepath, srcob->fluidsimSettings->surfdataDir, filename); - - //snprintf(debugStrBuffer,256,"getFluidsimDerivedMesh call (obid '%s', rp %d, dm %d) %s \n", srcob->id.name, useRenderParams, displaymode, filepath); // debug - mesh = readBobjgz(filepath, (Mesh*)(srcob->data) ); - if(!mesh) { - // display org. object upon failure - mesh = srcob->data; - return getMeshDerivedMesh(mesh , srcob, NULL); - } - - if((mesh)&&(mesh->totvert>0)) { - make_edges(mesh, 0); // 0 = make all edges draw - // force all edge draw - for(i=0;i<mesh->totedge;i++) { - //mesh->medge[i].flag = ME_EDGEDRAW; - //snprintf(debugStrBuffer,256,"me %d = %d\n",i,mesh->medge[i].flag); - } - } - - // WARNING copied from getMeshDerivedMesh - fsdm = MEM_callocN(sizeof(*fsdm), "getFluidsimDerivedMesh_fsdm"); - fsdm->freeMesh = 1; - mdm = &fsdm->mdm; - vertCos = NULL; - - mdm->dm.getMinMax = meshDM_getMinMax; - mdm->dm.convertToDispListMesh = meshDM_convertToDispListMesh; - mdm->dm.getNumVerts = meshDM_getNumVerts; - mdm->dm.getNumFaces = meshDM_getNumFaces; - mdm->dm.getVertCos = meshDM_getVertCos; - mdm->dm.getVertCo = meshDM_getVertCo; - mdm->dm.getVertNo = meshDM_getVertNo; - mdm->dm.drawVerts = meshDM_drawVerts; - mdm->dm.drawUVEdges = meshDM_drawUVEdges; - mdm->dm.drawEdges = meshDM_drawEdges; - mdm->dm.drawLooseEdges = meshDM_drawLooseEdges; - mdm->dm.drawFacesSolid = meshDM_drawFacesSolid; - mdm->dm.drawFacesColored = meshDM_drawFacesColored; - mdm->dm.drawFacesTex = meshDM_drawFacesTex; - mdm->dm.drawMappedFaces = meshDM_drawMappedFaces; - mdm->dm.drawMappedEdges = meshDM_drawMappedEdges; - mdm->dm.drawMappedFaces = meshDM_drawMappedFaces; - - // use own release function - mdm->dm.release = fluidsimDM_release; - - mdm->ob = srcob; - mdm->me = mesh; - mdm->verts = mesh->mvert; - mdm->nors = NULL; - mdm->freeNors = 0; - mdm->freeVerts = 0; - - /* if (vertCos) { not needed for fluid meshes... */ - // XXX this is kinda ... see getMeshDerivedMesh - mesh_calc_normals(mdm->verts, mdm->me->totvert, mdm->me->mface, mdm->me->totface, &mdm->nors); - mdm->freeNors = 1; - return (DerivedMesh*) mdm; -} - - -/* ***************************** bobj file handling ***************************** */ +/* ************************* fluidsim bobj file handling **************************** */ /* write .bobj.gz file for a mesh object */ @@ -2179,13 +2050,13 @@ void writeBobjgz(char *filename, struct Object *ob) gzwrite(gzf, &(face[3]), sizeof( face[3] )); } } + + snprintf(debugStrBuffer,256,"Done. #Vertices: %d, #Triangles: %d\n", dlm->totvert, dlm->totface ); + elbeemDebugOut(debugStrBuffer); gzclose( gzf ); if(dlm) displistmesh_free(dlm); dm->release(dm); - - snprintf(debugStrBuffer,256,"done. #Vertices: %d, #Triangles: %d\n", dlm->totvert, dlm->totface ); - elbeemDebugOut(debugStrBuffer); } /* read .bobj.gz file into a fluidsimDerivedMesh struct */ @@ -2195,16 +2066,19 @@ Mesh* readBobjgz(char *filename, Mesh *orgmesh) //, fluidsimDerivedMesh *fsdm) char debugStrBuffer[256]; float wrf; Mesh *newmesh; - const int debugBobjRead = 0; + const int debugBobjRead = 1; // init data from old mesh (materials,flags) MFace *origMFace = &((MFace*) orgmesh->mface)[0]; - int mat_nr = origMFace->mat_nr; - int flag = origMFace->flag; + int mat_nr = -1; + int flag = -1; MFace *fsface = NULL; int gotBytes; gzFile gzf; if(!orgmesh) return NULL; + if(!origMFace) return NULL; + mat_nr = origMFace->mat_nr; + flag = origMFace->flag; // similar to copy_mesh newmesh = MEM_dupallocN(orgmesh); @@ -2291,10 +2165,6 @@ Mesh* readBobjgz(char *filename, Mesh *orgmesh) //, fluidsimDerivedMesh *fsdm) fsface[i].v4 = face[3]; } - /*if(debugBobjRead) { - for(i=0; i<newmesh->totvert; i++) { snprintf(debugStrBuffer,256,"V %d = %f,%f,%f \n",i, newmesh->mvert[i].co[0],newmesh->mvert[i].co[1],newmesh->mvert[i].co[2] ); } - for(i=0; i<newmesh->totface; i++) { snprintf(debugStrBuffer,256,"F %d = %d,%d,%d,%d \n",i, fsface[i].v1,fsface[i].v2,fsface[i].v3,fsface[i].v4); } - } // debug */ // correct triangles with v3==0 for blender, cycle verts for(i=0; i<newmesh->totface; i++) { if(!fsface[i].v3) { @@ -2317,3 +2187,130 @@ Mesh* readBobjgz(char *filename, Mesh *orgmesh) //, fluidsimDerivedMesh *fsdm) return newmesh; } + +/* ***************************** fluidsim derived mesh ***************************** */ + +typedef struct { + MeshDerivedMesh mdm; + + /* release whole mesh? */ + char freeMesh; +} FluidsimDerivedMesh; + +#ifdef WIN32 +#ifndef snprintf +#define snprintf _snprintf +#endif +#endif + + +static void fluidsimDM_release(DerivedMesh *dm) +{ + FluidsimDerivedMesh *fsdm = (FluidsimDerivedMesh*) dm; + if(fsdm->freeMesh) { + // similar to free_mesh(fsdm->mdm.me) , but no things like unlink... + if(fsdm->mdm.me->mvert) MEM_freeN(fsdm->mdm.me->mvert); + if(fsdm->mdm.me->medge) MEM_freeN(fsdm->mdm.me->medge); + if(fsdm->mdm.me->mface) MEM_freeN(fsdm->mdm.me->mface); + MEM_freeN(fsdm->mdm.me); + } + + if (fsdm->mdm.freeNors) MEM_freeN(fsdm->mdm.nors); + if (fsdm->mdm.freeVerts) MEM_freeN(fsdm->mdm.verts); + MEM_freeN(fsdm); +} + +DerivedMesh *getFluidsimDerivedMesh(Object *srcob, int useRenderParams, float *extverts, float *nors) { + int i; + Mesh *mesh = NULL; + FluidsimDerivedMesh *fsdm; + MeshDerivedMesh *mdm = NULL; + float (*vertCos)[3]; + int displaymode = 0; + int curFrame = G.scene->r.cfra - 1; /* start with 0 */ + char targetDir[FILE_MAXFILE+FILE_MAXDIR], targetFile[FILE_MAXFILE+FILE_MAXDIR]; + char curWd[FILE_MAXDIR]; + char debugStrBuffer[256]; + //snprintf(debugStrBuffer,256,"getFluidsimDerivedMesh call (obid '%s', rp %d)\n", srcob->id.name, useRenderParams); // debug + + if((!srcob)||(!srcob->fluidsimSettings)) { + fprintf(stderr,"??? DEBUG, strange getFluidsimDerivedMesh call!\n\n"); return NULL; + } + + if(!useRenderParams) { + displaymode = srcob->fluidsimSettings->guiDisplayMode; + } else { + displaymode = srcob->fluidsimSettings->renderDisplayMode; + } + + snprintf(debugStrBuffer,256,"getFluidsimDerivedMesh call (obid '%s', rp %d, dm %d)\n", srcob->id.name, useRenderParams, displaymode); // debug + elbeemDebugOut(debugStrBuffer); // debug + + strncpy(targetDir, srcob->fluidsimSettings->surfdataPath, FILE_MAXDIR); + // use preview or final mesh? + if(displaymode==2) { + strcat(targetDir,"fluidsurface_preview_#"); + } else { + strcat(targetDir,"fluidsurface_final_#"); + } + BLI_convertstringcode(targetDir, G.sce, curFrame); // fixed #frame-no + strcpy(targetFile,targetDir); + strcat(targetFile, ".bobj.gz"); + //fprintf(stderr,"getFluidsimDerivedMesh call (obid '', rp %d, dm %d) '%s' \n", useRenderParams, displaymode, targetFile); // debug + + snprintf(debugStrBuffer,256,"getFluidsimDerivedMesh call (obid '%s', rp %d, dm %d) '%s' \n", srcob->id.name, useRenderParams, displaymode, targetFile); // debug + elbeemDebugOut(debugStrBuffer); // debug + + mesh = readBobjgz(targetFile, (Mesh*)(srcob->data) ); + if(!mesh) { + // display org. object upon failure + mesh = srcob->data; + return getMeshDerivedMesh(mesh , srcob, NULL); + } + + if((mesh)&&(mesh->totvert>0)) { + make_edges(mesh, 0); // 0 = make all edges draw + } + + // WARNING copied from getMeshDerivedMesh + fsdm = MEM_callocN(sizeof(*fsdm), "getFluidsimDerivedMesh_fsdm"); + fsdm->freeMesh = 1; + mdm = &fsdm->mdm; + vertCos = NULL; + + mdm->dm.getMinMax = meshDM_getMinMax; + mdm->dm.convertToDispListMesh = meshDM_convertToDispListMesh; + mdm->dm.getNumVerts = meshDM_getNumVerts; + mdm->dm.getNumFaces = meshDM_getNumFaces; + mdm->dm.getVertCos = meshDM_getVertCos; + mdm->dm.getVertCo = meshDM_getVertCo; + mdm->dm.getVertNo = meshDM_getVertNo; + mdm->dm.drawVerts = meshDM_drawVerts; + mdm->dm.drawUVEdges = meshDM_drawUVEdges; + mdm->dm.drawEdges = meshDM_drawEdges; + mdm->dm.drawLooseEdges = meshDM_drawLooseEdges; + mdm->dm.drawFacesSolid = meshDM_drawFacesSolid; + mdm->dm.drawFacesColored = meshDM_drawFacesColored; + mdm->dm.drawFacesTex = meshDM_drawFacesTex; + mdm->dm.drawMappedFaces = meshDM_drawMappedFaces; + mdm->dm.drawMappedEdges = meshDM_drawMappedEdges; + mdm->dm.drawMappedFaces = meshDM_drawMappedFaces; + + // use own release function + mdm->dm.release = fluidsimDM_release; + + mdm->ob = srcob; + mdm->me = mesh; + mdm->verts = mesh->mvert; + mdm->nors = NULL; + mdm->freeNors = 0; + mdm->freeVerts = 0; + + // if (vertCos) { not needed for fluid meshes... + // this is kinda ... see getMeshDerivedMesh + mesh_calc_normals(mdm->verts, mdm->me->totvert, mdm->me->mface, mdm->me->totface, &mdm->nors); + mdm->freeNors = 1; + return (DerivedMesh*) mdm; +} + + diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 86a5bb5d635..ab7352e4a5f 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -2400,7 +2400,7 @@ static void direct_link_object(FileData *fd, Object *ob) } ob->fluidsimSettings= newdataadr(fd, ob->fluidsimSettings); /* NT */ if(ob->fluidsimSettings) { - // not much to do for now... fprintf(stderr, "FLUIDSIMT newdataadr\n"); + // not much to do for now... ob->fluidsimSettings->orgMesh = NULL; } diff --git a/source/blender/makesdna/DNA_object_fluidsim.h b/source/blender/makesdna/DNA_object_fluidsim.h index e98f0b8a8e9..6a02680d694 100644 --- a/source/blender/makesdna/DNA_object_fluidsim.h +++ b/source/blender/makesdna/DNA_object_fluidsim.h @@ -68,9 +68,6 @@ typedef struct FluidsimSettings { float gstar; /* activate refinement? */ int maxRefine; - /* store output path, and file prefix for baked fluid surface */ - /* strlens; 80= FILE_MAXFILE, 160= FILE_MAXDIR */ - char surfdataDir[160], surfdataPrefix[80]; /* fluid object type settings */ /* gravity strength */ @@ -78,6 +75,10 @@ typedef struct FluidsimSettings { /* store pointer to original mesh (for replacing the current one) */ struct Mesh *orgMesh; + + /* store output path, and file prefix for baked fluid surface */ + /* strlens; 80= FILE_MAXFILE, 160= FILE_MAXDIR */ + char surfdataPath[160+80]; } FluidsimSettings; /* ob->fluidsimSettings defines */ diff --git a/source/blender/src/buttons_object.c b/source/blender/src/buttons_object.c index 82494c0f37f..43897b2f0bd 100644 --- a/source/blender/src/buttons_object.c +++ b/source/blender/src/buttons_object.c @@ -1256,18 +1256,19 @@ static void softbody_bake(Object *ob) void fluidsimFilesel(char *selection) { Object *ob = OBACT; - char srcDir[FILE_MAXDIR], srcFile[FILE_MAXFILE]; + char srcDir[FILE_MAXDIR+FILE_MAXFILE], srcFile[FILE_MAXFILE]; char prefix[FILE_MAXFILE]; char *srch, *srchSub, *srchExt, *lastFound; int isElbeemSurf = 0; + // check cfg? + // make prefix strcpy(srcDir, selection); BLI_splitdirstring(srcDir, srcFile); - - // make prefix strcpy(prefix, srcFile); // check if this is a previously generated surface mesh file - srch = strstr(prefix, "_surface_"); + srch = strstr(prefix, "fluidsurface_"); + // TODO search from back... if(srch) { srchSub = strstr(prefix,"_preview_"); if(!srchSub) srchSub = strstr(prefix,"_final_"); @@ -1294,10 +1295,17 @@ void fluidsimFilesel(char *selection) } } - // TODO check srcDir for file path from sce? - strcpy(ob->fluidsimSettings->surfdataDir, srcDir); - strcpy(ob->fluidsimSettings->surfdataPrefix, prefix); - //fprintf(stderr,"fluidsimFilesel: Using surfdata path '%s', prefix '%s' \n", ob->fluidsimSettings->surfdataDir,ob->fluidsimSettings->surfdataPrefix); // DEBUG + if(ob->fluidsimSettings) { + //strcpy(ob->fluidsimSettings->surfdataPath, selection); + strcpy(ob->fluidsimSettings->surfdataPath, srcDir); + //not necessary? strcat(ob->fluidsimSettings->surfdataPath, "/"); + strcat(ob->fluidsimSettings->surfdataPath, prefix); + + // redraw view & buttons... + allqueue(REDRAWBUTSOBJECT, 0); + allqueue(REDRAWVIEW3D, 0); + DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA); + } } void do_object_panels(unsigned short event) @@ -1386,22 +1394,18 @@ void do_object_panels(unsigned short event) /* write config files (currently no simulation) */ fluidsimBake(ob); break; - case B_FLUIDSIM_SELDIR: - { - char str[FILE_MAXDIR+FILE_MAXFILE]; - ScrArea *sa = closest_bigger_area(); - strcpy(str,"//"); - ob= OBACT; - /* choose dir for surface files */ - areawinset(sa->win); - activate_fileselect(FILE_SPECIAL, "Select Directory", str, fluidsimFilesel); - } - /* continue with redraw... so no brake here! */ + case B_FLUIDSIM_SELDIR: { + ScrArea *sa = closest_bigger_area(); + ob= OBACT; + /* choose dir for surface files */ + areawinset(sa->win); + activate_fileselect(FILE_SPECIAL, "Select Directory", ob->fluidsimSettings->surfdataPath, fluidsimFilesel); + } + break; case B_FLUIDSIM_FORCEREDRAW: /* force redraw */ - allqueue(REDRAWBUTSEDIT, 0); + allqueue(REDRAWBUTSOBJECT, 0); allqueue(REDRAWVIEW3D, 0); - countall(); DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA); break; @@ -2015,9 +2019,8 @@ static void object_panel_fluidsim(Object *ob) yline -= lineHeight; yline -= 1*separateHeight; - uiDefIconBut(block, BUT, B_FLUIDSIM_SELDIR, ICON_FILESEL, 0, yline, 20, objHeight, 0, 0, 0, 0, 0, "Select Directory (and/or filenames) to store baked fluid simulation files in"); - uiDefBut(block, TEX, B_FLUIDSIM_FORCEREDRAW,"", 20, yline, 200, objHeight,fss->surfdataDir, 0.0,79.0, 0, 0, "Enter Directory to store baked fluid simulation files in"); - uiDefBut(block, TEX, B_FLUIDSIM_FORCEREDRAW,"", 220, yline, 80, objHeight,fss->surfdataPrefix, 0.0,79.0, 0, 0, "Enter Filename-Prefix to store baked fluid simulation files with"); + uiDefIconBut(block, BUT, B_FLUIDSIM_SELDIR, ICON_FILESEL, 0, yline, 20, objHeight, 0, 0, 0, 0, 0, "Select Directory (and/or filename prefix) to store baked fluid simulation files in"); + uiDefBut(block, TEX, B_FLUIDSIM_FORCEREDRAW,"", 20, yline, 280, objHeight, fss->surfdataPath, 0.0,79.0, 0, 0, "Enter Directory (and/or filename prefix) to store baked fluid simulation files in"); // FIXME what is the 79.0 above? } else { // advanced options @@ -2027,7 +2030,6 @@ static void object_panel_fluidsim(Object *ob) uiDefButF(block, NUM, B_DIFF, "Y:", 160, yline, 70,objHeight, &fss->gravy, -1000.1, 1000.1, 10, 0, "Gravity in Y direction"); uiDefButF(block, NUM, B_DIFF, "Z:", 230, yline, 70,objHeight, &fss->gravz, -1000.1, 1000.1, 10, 0, "Gravity in Z direction"); uiBlockEndAlign(block); - //yline -= lineHeight; yline -= separateHeight; yline -= lineHeight; yline -= 1*separateHeight; diff --git a/source/blender/src/fluidsim.c b/source/blender/src/fluidsim.c index c0ab26b7733..546613821f0 100644 --- a/source/blender/src/fluidsim.c +++ b/source/blender/src/fluidsim.c @@ -162,18 +162,12 @@ FluidsimSettings *fluidsimSettingsNew(struct Object *srcob) fss->maxRefine = -1; // maxRefine is set according to resolutionxyz during bake - // fluid settings + // fluid/inflow settings fss->iniVelx = fss->iniVely = fss->iniVelz = 0.0; - strcpy(fss->surfdataDir,"//"); // current dir - // fss->surfdataPrefix take from .blend filename - //strcpy(blendDir, G.sce); - //BLI_splitdirstring(blendDir, blendFile); - //snprintf(fss->surfdataPrefix,FILE_MAXFILE,"%s_%s", blendFile, srcob->id.name); - strcpy(fss->surfdataPrefix,""); // init upon first bake - + strcpy(fss->surfdataPath,""); // leave blank, init upon first bake fss->orgMesh = (Mesh *)srcob->data; return fss; } @@ -186,8 +180,9 @@ void fluidsimSettingsFree(FluidsimSettings *fss) /* helper function */ -void getGeometryObjFilename(struct Object *ob, char *dst, char *srcname) { - snprintf(dst,FILE_MAXFILE, "%s_cfgdata_%s.bobj.gz", srcname, ob->id.name); +void getGeometryObjFilename(struct Object *ob, char *dst) { //, char *srcname) { + //snprintf(dst,FILE_MAXFILE, "%s_cfgdata_%s.bobj.gz", srcname, ob->id.name); + snprintf(dst,FILE_MAXFILE, "fluidcfgdata_%s.bobj.gz", ob->id.name); } @@ -220,7 +215,6 @@ void simulateThreadIncreaseFrame(void) { /* ********************** write fluidsim config to file ************************* */ void fluidsimBake(struct Object *ob) { - char fnameCfg[FILE_MAXFILE], fnameCfgPath[FILE_MAXFILE+FILE_MAXDIR]; FILE *fileCfg; struct Object *fsDomain = NULL; FluidsimSettings *fssDomain; @@ -233,16 +227,18 @@ void fluidsimBake(struct Object *ob) const int maxRes = 200; int gridlevels = 0; - char outDir[FILE_MAXDIR], outPrefix[FILE_MAXFILE]; // store & modify output settings - int outStringsChanged = 0; // modified? copy back before baking - int haveSomeFluid = 0; // check if any fluid objects are set + char *suffixConfig = "fluidsim.cfg"; + char *suffixSurface = "fluidsurface"; + char targetDir[FILE_MAXDIR+FILE_MAXFILE]; // store & modify output settings + char targetFile[FILE_MAXDIR+FILE_MAXFILE]; // temp. store filename from targetDir for access + int outStringsChanged = 0; // modified? copy back before baking + int haveSomeFluid = 0; // check if any fluid objects are set const char *strEnvName = "BLENDER_ELBEEMDEBUG"; // from blendercall.cpp if(getenv(strEnvName)) { int dlevel = atoi(getenv(strEnvName)); elbeemSetDebugLevel(dlevel); - //if((dlevel>0) && (dlevel<=10)) debugBake = 1; snprintf(debugStrBuffer,256,"fluidsimBake::msg: Debug messages activated due to envvar '%s'\n",strEnvName); elbeemDebugOut(debugStrBuffer); } @@ -308,45 +304,32 @@ void fluidsimBake(struct Object *ob) } // prepare names... - strcpy(curWd, G.sce); - BLI_splitdirstring(curWd, blendFile); - if(strlen(curWd)<1) { - BLI_getwdN(curWd); - } - // work on these vars here... copy back later - strncpy(outDir, fsDomain->fluidsimSettings->surfdataDir, FILE_MAXDIR); - strncpy(outPrefix, fsDomain->fluidsimSettings->surfdataPrefix, FILE_MAXFILE); - if(strlen(outPrefix)<1) { - // make new from current .blend filename , and domain object name - strcpy(blendDir, G.sce); - BLI_splitdirstring(blendDir, blendFile); - // todo... strip .blend - snprintf(outPrefix,FILE_MAXFILE,"%s_%s", blendFile, fsDomain->id.name); - snprintf(debugStrBuffer,256,"fluidsimBake::error - warning resetting output prefix to '%s'\n", outPrefix); - elbeemDebugOut(debugStrBuffer); - outStringsChanged=1; - } + strncpy(targetDir, fsDomain->fluidsimSettings->surfdataPath, FILE_MAXDIR); + BLI_convertstringcode(targetDir, G.sce, 0); // fixed #frame-no + strcpy(targetFile, targetDir); + strcat(targetFile, suffixConfig); // check selected directory -#ifdef WIN32 - // windows workaroung because stat seems to be broken... - // simply try to open cfg file for writing - snprintf(fnameCfg,FILE_MAXFILE,"%s.cfg", outPrefix); - BLI_make_file_string(curWd, fnameCfgPath, outDir, fnameCfg); - fileCfg = fopen(fnameCfgPath, "w"); - if(fileCfg) { - dirExist = 1; - fclose(fileCfg); - } -#else // WIN32 - BLI_make_file_string(curWd, fnameCfgPath, outDir, ""); - if(S_ISDIR(BLI_exist(fnameCfgPath))) dirExist = 1; -#endif // WIN32 + // simply try to open cfg file for writing to test validity of settings + fileCfg = fopen(targetFile, "w"); + if(fileCfg) { dirExist = 1; fclose(fileCfg); } - if((strlen(outDir)<1) || (!dirExist)) { - // invalid dir, reset to current - strcpy(outDir, "//"); - snprintf(debugStrBuffer,256,"fluidsimBake::error - warning resetting output dir to '%s'\n", outDir); + if((strlen(targetDir)<1) || (!dirExist)) { + char blendDir[FILE_MAXDIR+FILE_MAXFILE], blendFile[FILE_MAXDIR+FILE_MAXFILE]; + // invalid dir, reset to current/previous + strcpy(blendDir, G.sce); + BLI_splitdirstring(blendDir, blendFile); + if(strlen(blendFile)>6){ + int len = strlen(blendFile); + if( (blendFile[len-6]=='.')&& (blendFile[len-5]=='b')&& (blendFile[len-4]=='l')&& + (blendFile[len-3]=='e')&& (blendFile[len-2]=='n')&& (blendFile[len-1]=='d') ){ + blendFile[len-6] = '\0'; + } + } + // todo... strip .blend ? + snprintf(targetDir,FILE_MAXFILE+FILE_MAXDIR,"//%s_%s_", blendFile, fsDomain->id.name); + + snprintf(debugStrBuffer,256,"fluidsimBake::error - warning resetting output dir to '%s'\n", targetDir); elbeemDebugOut(debugStrBuffer); outStringsChanged=1; } @@ -356,38 +339,35 @@ void fluidsimBake(struct Object *ob) char dispmsg[FILE_MAXDIR+FILE_MAXFILE+256]; int selection=0; strcpy(dispmsg,"Output settings set to: '"); - strcat(dispmsg, outDir); - if(dispmsg[ strlen(dispmsg)-1 ]!='/') strcat(dispmsg,"/"); - strcat(dispmsg, outPrefix); - //snprintf(dispmsg, FILE_MAXDIR+FILE_MAXFILE+10, "%s '%s'", changeMsg, fnameCfgPath); + strcat(dispmsg, targetDir); strcat(dispmsg, "'%t|Continue with changed settings%x1|Discard and abort%x0"); // ask user if thats what he/she wants... selection = pupmenu(dispmsg); - if(selection==0) return; + if(selection<1) return; // 0 from menu, or -1 aborted + BLI_convertstringcode(targetDir, G.sce, 0); // fixed #frame-no } // dump data for frame 0 G.scene->r.cfra = 0; scene_update_for_newframe(G.scene, G.scene->lay); - snprintf(fnameCfg,FILE_MAXFILE,"%s.cfg", outPrefix); - BLI_make_file_string(curWd, fnameCfgPath, outDir, fnameCfg); - // start writing - fileCfg = fopen(fnameCfgPath, "w"); + strcpy(targetFile, targetDir); + strcat(targetFile, suffixConfig); + fileCfg = fopen(targetFile, "w"); if(!fileCfg) { - snprintf(debugStrBuffer,256,"fluidsimBake::error - Unable to open file for writing '%s'\n", fnameCfgPath); + snprintf(debugStrBuffer,256,"fluidsimBake::error - Unable to open file for writing '%s'\n", targetFile); elbeemDebugOut(debugStrBuffer); pupmenu("Fluidsim Bake Error%t|Unable to output files... Aborted%x0"); return; } - fprintf(fileCfg, "# Blender ElBeem File , Source %s , Frame %d, to %s \n\n\n", G.sce, -1, fnameCfg ); - // valid settings -> store - strncpy(fsDomain->fluidsimSettings->surfdataDir, outDir, FILE_MAXDIR); - strncpy(fsDomain->fluidsimSettings->surfdataPrefix, outPrefix, FILE_MAXFILE); + fprintf(fileCfg, "# Blender ElBeem File , Source %s , Frame %d, to %s \n\n\n", G.sce, -1, targetFile ); + // file open -> valid settings -> store + strncpy(fsDomain->fluidsimSettings->surfdataPath, targetDir, FILE_MAXDIR); + //strncpy(fsDomain->fluidsimSettings->urfdataPrefix, outPrefix, FILE_MAXFILE); // FIXME set aniframetime from no. frames and duration /* output simulation settings */ @@ -484,7 +464,7 @@ void fluidsimBake(struct Object *ob) " antialias 1; \n" " ambientlight (1, 1, 1); \n" " maxRayDepth 6; \n" - " treeMaxDepth 25; \n" + " treeMaxDepth 25; \n" " treeMaxTriangles 8; \n" " background (0.08, 0.08, 0.20); \n" " eyepoint= (" "%f %f %f"/*4,5,6 eyep*/ "); #cfgset \n" @@ -509,11 +489,9 @@ void fluidsimBake(struct Object *ob) int resx = 200, resy=200; float lookatx=0.0, lookaty=0.0, lookatz=0.0; float fov = 45.0; - char fnamePreview[FILE_MAXFILE]; - char fnamePreviewPath[FILE_MAXFILE+FILE_MAXDIR]; - snprintf(fnamePreview,FILE_MAXFILE,"%s_surface", outPrefix ); - BLI_make_file_string(curWd, fnamePreviewPath, outDir, fnamePreview); + strcpy(targetFile, targetDir); + strcat(targetFile, suffixSurface); resx = G.scene->r.xsch; resy = G.scene->r.ysch; if((cam) && (cam->type == OB_CAMERA)) { @@ -530,7 +508,7 @@ void fluidsimBake(struct Object *ob) } fprintf(fileCfg, rayString, - noFrames, fnamePreviewPath, resx,resy, + noFrames, targetFile, resx,resy, eyex, eyey, eyez , lookatx, lookaty, lookatz, fov @@ -611,7 +589,6 @@ void fluidsimBake(struct Object *ob) " } \n" "\n" ; char fnameObjdat[FILE_MAXFILE]; - char bobjPath[FILE_MAXFILE+FILE_MAXDIR]; for(obit= G.main->object.first; obit; obit= obit->id.next) { //{ snprintf(debugStrBuffer,256,"DEBUG object name=%s, type=%d ...\n", obit->id.name, obit->type); elbeemDebugOut(debugStrBuffer); } // DEBUG @@ -619,26 +596,27 @@ void fluidsimBake(struct Object *ob) (obit->type==OB_MESH) && (obit->fluidsimSettings->type != OB_FLUIDSIM_DOMAIN) ) { - getGeometryObjFilename(obit, fnameObjdat, outPrefix); - BLI_make_file_string(curWd, bobjPath, outDir, fnameObjdat); + getGeometryObjFilename(obit, fnameObjdat); //, outPrefix); + strcpy(targetFile, targetDir); + strcat(targetFile, fnameObjdat); fprintf(fileCfg, objectStringStart, obit->id.name ); // abs path if(obit->fluidsimSettings->type == OB_FLUIDSIM_FLUID) { - fprintf(fileCfg, fluidString, "fluid", bobjPath, // do use absolute paths? + fprintf(fileCfg, fluidString, "fluid", targetFile, // do use absolute paths? (double)obit->fluidsimSettings->iniVelx, (double)obit->fluidsimSettings->iniVely, (double)obit->fluidsimSettings->iniVelz ); } if(obit->fluidsimSettings->type == OB_FLUIDSIM_INFLOW) { - fprintf(fileCfg, fluidString, "inflow", bobjPath, // do use absolute paths? + fprintf(fileCfg, fluidString, "inflow", targetFile, // do use absolute paths? (double)obit->fluidsimSettings->iniVelx, (double)obit->fluidsimSettings->iniVely, (double)obit->fluidsimSettings->iniVelz ); } if(obit->fluidsimSettings->type == OB_FLUIDSIM_OUTFLOW) { - fprintf(fileCfg, fluidString, "outflow", bobjPath, // do use absolute paths? + fprintf(fileCfg, fluidString, "outflow", targetFile, // do use absolute paths? (double)obit->fluidsimSettings->iniVelx, (double)obit->fluidsimSettings->iniVely, (double)obit->fluidsimSettings->iniVelz ); } if(obit->fluidsimSettings->type == OB_FLUIDSIM_OBSTACLE) { - fprintf(fileCfg, obstacleString, "bnd_no" , bobjPath); // abs path + fprintf(fileCfg, obstacleString, "bnd_no" , targetFile); // abs path } fprintf(fileCfg, objectStringEnd ); // abs path - writeBobjgz(bobjPath, obit); + writeBobjgz(targetFile, obit); } } } @@ -657,7 +635,7 @@ void fluidsimBake(struct Object *ob) fprintf(fileCfg, "} // end raytracing\n"); fclose(fileCfg); - snprintf(debugStrBuffer,256,"fluidsimBake::msg: Wrote %s\n", fnameCfg); + snprintf(debugStrBuffer,256,"fluidsimBake::msg: Wrote %s\n", targetFile); elbeemDebugOut(debugStrBuffer); // perform simulation @@ -666,7 +644,9 @@ void fluidsimBake(struct Object *ob) globalBakeLock = SDL_CreateMutex(); globalBakeState = 0; globalBakeFrame = 1; - simthr = SDL_CreateThread(simulateThread, fnameCfgPath); + strcpy(targetFile, targetDir); + strcat(targetFile, suffixConfig); + simthr = SDL_CreateThread(simulateThread, targetFile); #ifndef WIN32 // DEBUG for win32 debugging, dont use threads... #endif // WIN32 @@ -674,7 +654,7 @@ void fluidsimBake(struct Object *ob) snprintf(debugStrBuffer,256,"fluidsimBake::error: Unable to create thread... running without one.\n"); elbeemDebugOut(debugStrBuffer); set_timecursor(0); - performElbeemSimulation(fnameCfgPath); + performElbeemSimulation(targetFile); } else { int done = 0; unsigned short event=0; @@ -733,6 +713,7 @@ void fluidsimBake(struct Object *ob) globalBakeLock = NULL; } // thread creation + // TODO cleanup sim files? // go back to "current" blender time waitcursor(0); G.scene->r.cfra = origFrame; |