diff options
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/pointcache.c | 175 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/smoke.c | 102 |
2 files changed, 123 insertions, 154 deletions
diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c index 4d22b22ae31..440a3136108 100644 --- a/source/blender/blenkernel/intern/pointcache.c +++ b/source/blender/blenkernel/intern/pointcache.c @@ -725,6 +725,7 @@ static int ptcache_write_smoke(PTCacheFile *pf, void *smoke_v) { SmokeModifierData *smd= (SmokeModifierData *)smoke_v; SmokeDomainSettings *sds = smd->domain; + int ret = 0; if(sds->fluid) { size_t res = sds->res[0]*sds->res[1]*sds->res[2]; @@ -755,16 +756,9 @@ static int ptcache_write_smoke(PTCacheFile *pf, void *smoke_v) MEM_freeN(out); - return 1; + ret = 1; } - return 0; -} -static int ptcache_write_smoke_turbulence(PTCacheFile *pf, void *smoke_v) -{ - SmokeModifierData *smd= (SmokeModifierData *)smoke_v; - SmokeDomainSettings *sds = smd->domain; - if(sds->wt) { int res_big_array[3]; int res_big; @@ -796,11 +790,13 @@ static int ptcache_write_smoke_turbulence(PTCacheFile *pf, void *smoke_v) ptcache_compress_write(pf, (unsigned char *)tcw, in_len, out, mode); MEM_freeN(out); - return 1; + ret = 1; } - return 0; + + return ret; } + // forward decleration static int ptcache_file_read(PTCacheFile *pf, void *f, size_t tot, int size); @@ -877,33 +873,27 @@ static void ptcache_read_smoke(PTCacheFile *pf, void *smoke_v) ptcache_compress_read(pf, (unsigned char*)obstacles, (unsigned int)res); ptcache_file_read(pf, &dt, 1, sizeof(float)); ptcache_file_read(pf, &dx, 1, sizeof(float)); - } -} -static void ptcache_read_smoke_turbulence(PTCacheFile *pf, void *smoke_v) -{ - SmokeModifierData *smd= (SmokeModifierData *)smoke_v; - SmokeDomainSettings *sds = smd->domain; - - if(sds->fluid) { - int res = sds->res[0]*sds->res[1]*sds->res[2]; - int res_big, res_big_array[3]; - float *dens, *densold, *tcu, *tcv, *tcw; - unsigned int out_len = sizeof(float)*(unsigned int)res; - unsigned int out_len_big; + if(pf->data_types & (1<<BPHYS_DATA_SMOKE_HIGH) && sds->wt) { + int res = sds->res[0]*sds->res[1]*sds->res[2]; + int res_big, res_big_array[3]; + float *dens, *densold, *tcu, *tcv, *tcw; + unsigned int out_len = sizeof(float)*(unsigned int)res; + unsigned int out_len_big; - smoke_turbulence_get_res(sds->wt, res_big_array); - res_big = res_big_array[0]*res_big_array[1]*res_big_array[2]; - out_len_big = sizeof(float) * (unsigned int)res_big; + smoke_turbulence_get_res(sds->wt, res_big_array); + res_big = res_big_array[0]*res_big_array[1]*res_big_array[2]; + out_len_big = sizeof(float) * (unsigned int)res_big; - smoke_turbulence_export(sds->wt, &dens, &densold, &tcu, &tcv, &tcw); + smoke_turbulence_export(sds->wt, &dens, &densold, &tcu, &tcv, &tcw); - ptcache_compress_read(pf, (unsigned char*)dens, out_len_big); - ptcache_compress_read(pf, (unsigned char*)densold, out_len_big); + ptcache_compress_read(pf, (unsigned char*)dens, out_len_big); + ptcache_compress_read(pf, (unsigned char*)densold, out_len_big); - ptcache_compress_read(pf, (unsigned char*)tcu, out_len); - ptcache_compress_read(pf, (unsigned char*)tcv, out_len); - ptcache_compress_read(pf, (unsigned char*)tcw, out_len); + ptcache_compress_read(pf, (unsigned char*)tcu, out_len); + ptcache_compress_read(pf, (unsigned char*)tcv, out_len); + ptcache_compress_read(pf, (unsigned char*)tcw, out_len); + } } } @@ -936,41 +926,13 @@ void BKE_ptcache_id_from_smoke(PTCacheID *pid, struct Object *ob, struct SmokeMo pid->write_header= ptcache_write_basic_header; pid->read_header= ptcache_read_basic_header; - pid->data_types= (1<<BPHYS_DATA_LOCATION); // bogus values to make pointcache happy + pid->data_types= 0; pid->info_types= 0; -} -void BKE_ptcache_id_from_smoke_turbulence(PTCacheID *pid, struct Object *ob, struct SmokeModifierData *smd) -{ - SmokeDomainSettings *sds = smd->domain; - - memset(pid, 0, sizeof(PTCacheID)); - - pid->ob= ob; - pid->calldata= smd; - - pid->type= PTCACHE_TYPE_SMOKE_HIGHRES; - pid->stack_index= sds->point_cache[1]->index; - - pid->cache= sds->point_cache[1]; - pid->cache_ptr= &sds->point_cache[1]; - pid->ptcaches= &sds->ptcaches[1]; - - pid->totpoint= pid->totwrite= ptcache_totpoint_smoke_turbulence; - - pid->write_elem= NULL; - pid->read_elem= NULL; - - pid->read_stream = ptcache_read_smoke_turbulence; - pid->write_stream = ptcache_write_smoke_turbulence; - - pid->interpolate_elem= NULL; - - pid->write_header= ptcache_write_basic_header; - pid->read_header= ptcache_read_basic_header; - - pid->data_types= (1<<BPHYS_DATA_LOCATION); // bogus values tot make pointcache happy - pid->info_types= 0; + if(sds->fluid) + pid->data_types |= (1<<BPHYS_DATA_SMOKE_LOW); + if(sds->wt) + pid->data_types |= (1<<BPHYS_DATA_SMOKE_HIGH); } void BKE_ptcache_id_from_cloth(PTCacheID *pid, Object *ob, ClothModifierData *clmd) @@ -1046,10 +1008,6 @@ void BKE_ptcache_ids_from_object(ListBase *lb, Object *ob, Scene *scene, int dup pid= MEM_callocN(sizeof(PTCacheID), "PTCacheID"); BKE_ptcache_id_from_smoke(pid, ob, (SmokeModifierData*)md); BLI_addtail(lb, pid); - - pid= MEM_callocN(sizeof(PTCacheID), "PTCacheID"); - BKE_ptcache_id_from_smoke_turbulence(pid, ob, (SmokeModifierData*)md); - BLI_addtail(lb, pid); } } } @@ -2289,9 +2247,6 @@ int BKE_ptcache_object_reset(Scene *scene, Object *ob, int mode) { BKE_ptcache_id_from_smoke(&pid, ob, (SmokeModifierData*)md); reset |= BKE_ptcache_id_reset(scene, &pid, mode); - - BKE_ptcache_id_from_smoke_turbulence(&pid, ob, (SmokeModifierData*)md); - reset |= BKE_ptcache_id_reset(scene, &pid, mode); } } } @@ -2841,6 +2796,61 @@ void BKE_ptcache_toggle_disk_cache(PTCacheID *pid) BKE_ptcache_update_info(pid); } +void BKE_ptcache_disk_cache_rename(PTCacheID *pid, char *from, char *to) +{ + char old_name[80]; + int len; /* store the length of the string */ + /* mode is same as fopen's modes */ + DIR *dir; + struct dirent *de; + char path[MAX_PTCACHE_PATH]; + char old_filename[MAX_PTCACHE_FILE]; + char new_path_full[MAX_PTCACHE_FILE]; + char old_path_full[MAX_PTCACHE_FILE]; + char ext[MAX_PTCACHE_PATH]; + + /* save old name */ + strcpy(old_name, pid->cache->name); + + /* get "from" filename */ + strcpy(pid->cache->name, from); + + len = BKE_ptcache_id_filename(pid, old_filename, 0, 0, 0); /* no path */ + + ptcache_path(pid, path); + dir = opendir(path); + if(dir==NULL) { + strcpy(pid->cache->name, old_name); + return; + } + + snprintf(ext, sizeof(ext), "_%02d"PTCACHE_EXT, pid->stack_index); + + /* put new name into cache */ + strcpy(pid->cache->name, to); + + while ((de = readdir(dir)) != NULL) { + if (strstr(de->d_name, ext)) { /* do we have the right extension?*/ + if (strncmp(old_filename, de->d_name, len ) == 0) { /* do we have the right prefix */ + /* read the number of the file */ + int frame, len2 = (int)strlen(de->d_name); + char num[7]; + + if (len2 > 15) { /* could crash if trying to copy a string out of this range*/ + BLI_strncpy(num, de->d_name + (strlen(de->d_name) - 15), sizeof(num)); + frame = atoi(num); + + BLI_join_dirfile(old_path_full, path, de->d_name); + BKE_ptcache_id_filename(pid, new_path_full, frame, 1, 1); + BLI_rename(old_path_full, new_path_full); + } + } + } + } + + strcpy(pid->cache->name, old_name); +} + void BKE_ptcache_load_external(PTCacheID *pid) { /*todo*/ @@ -2965,14 +2975,25 @@ void BKE_ptcache_update_info(PTCacheID *pid) } if(cache->flag & PTCACHE_DISK_CACHE) { - int cfra = cache->startframe; + if(pid->type == PTCACHE_TYPE_SMOKE_DOMAIN) + { + int totpoint = pid->totpoint(pid->calldata, 0); - for(; cfra<=cache->endframe; cfra++) { - if(BKE_ptcache_id_exist(pid, cfra)) - totframes++; + if(cache->totpoint > totpoint) + sprintf(mem_info, "%i cells + High Resolution cached", totpoint); + else + sprintf(mem_info, "%i cells cached"); } + else { + int cfra = cache->startframe; - sprintf(mem_info, "%i frames on disk", totframes); + for(; cfra<=cache->endframe; cfra++) { + if(BKE_ptcache_id_exist(pid, cfra)) + totframes++; + } + + sprintf(mem_info, "%i frames on disk", totframes); + } } else { PTCacheMem *pm = cache->mem_cache.first; diff --git a/source/blender/blenkernel/intern/smoke.c b/source/blender/blenkernel/intern/smoke.c index 8822d0cb4c9..8fd9c48cc61 100644 --- a/source/blender/blenkernel/intern/smoke.c +++ b/source/blender/blenkernel/intern/smoke.c @@ -554,8 +554,6 @@ static void smokeModifier_freeDomain(SmokeModifierData *smd) BKE_ptcache_free_list(&(smd->domain->ptcaches[0])); smd->domain->point_cache[0] = NULL; - BKE_ptcache_free_list(&(smd->domain->ptcaches[1])); - smd->domain->point_cache[1] = NULL; MEM_freeN(smd->domain); smd->domain = NULL; @@ -695,10 +693,9 @@ void smokeModifier_createType(struct SmokeModifierData *smd) smd->domain->point_cache[0]->flag |= PTCACHE_DISK_CACHE; smd->domain->point_cache[0]->step = 1; - smd->domain->point_cache[1] = BKE_ptcache_add(&(smd->domain->ptcaches[1])); - smd->domain->point_cache[1]->flag |= PTCACHE_DISK_CACHE; - smd->domain->point_cache[1]->step = 1; - + /* Deprecated */ + smd->domain->point_cache[1] = NULL; + smd->domain->ptcaches[1].first = smd->domain->ptcaches[1].last = NULL; /* set some standard values */ smd->domain->fluid = NULL; smd->domain->wt = NULL; @@ -1323,35 +1320,22 @@ void smokeModifier_do(SmokeModifierData *smd, Scene *scene, Object *ob, DerivedM float light[3]; PointCache *cache = NULL; PTCacheID pid; - PointCache *cache_wt = NULL; - PTCacheID pid_wt; int startframe, endframe, framenr; float timescale; - int cache_result = 0, cache_result_wt = 0; - int did_init = 0; framenr = scene->r.cfra; - printf("time: %d\n", scene->r.cfra); + //printf("time: %d\n", scene->r.cfra); cache = sds->point_cache[0]; BKE_ptcache_id_from_smoke(&pid, ob, smd); BKE_ptcache_id_time(&pid, scene, framenr, &startframe, &endframe, ×cale); - cache_wt = sds->point_cache[1]; - BKE_ptcache_id_from_smoke_turbulence(&pid_wt, ob, smd); - if(!smd->domain->fluid || framenr == startframe) { BKE_ptcache_id_reset(scene, &pid, PTCACHE_RESET_OUTDATED); BKE_ptcache_validate(cache, framenr); cache->flag &= ~PTCACHE_REDO_NEEDED; - - BKE_ptcache_id_reset(scene, &pid_wt, PTCACHE_RESET_OUTDATED); - if(cache_wt) { - BKE_ptcache_validate(cache_wt, framenr); - cache_wt->flag &= ~PTCACHE_REDO_NEEDED; - } } if(!smd->domain->fluid && (framenr != startframe) && (smd->domain->flags & MOD_SMOKE_FILE_LOAD)==0 && (cache->flag & PTCACHE_BAKED)==0) @@ -1359,11 +1343,7 @@ void smokeModifier_do(SmokeModifierData *smd, Scene *scene, Object *ob, DerivedM smd->domain->flags &= ~MOD_SMOKE_FILE_LOAD; - if(framenr < startframe) - framenr = startframe; - - if(framenr > endframe) - framenr = endframe; + CLAMP(framenr, startframe, endframe); /* If already viewing a pre/after frame, no need to reload */ if ((smd->time == framenr) && (framenr != scene->r.cfra)) @@ -1371,42 +1351,21 @@ void smokeModifier_do(SmokeModifierData *smd, Scene *scene, Object *ob, DerivedM // printf("startframe: %d, framenr: %d\n", startframe, framenr); - if(!(did_init = smokeModifier_init(smd, ob, scene, dm))) + if(smokeModifier_init(smd, ob, scene, dm)==0) { printf("bad smokeModifier_init\n"); return; } /* try to read from cache */ - cache_result = BKE_ptcache_read_cache(&pid, (float)framenr, scene->r.frs_sec); - // printf("cache_result: %d\n", cache_result); - - if(cache_result == PTCACHE_READ_EXACT) - { + if(BKE_ptcache_read_cache(&pid, (float)framenr, scene->r.frs_sec) == PTCACHE_READ_EXACT) { BKE_ptcache_validate(cache, framenr); smd->time = framenr; - - if(sds->wt) - { - cache_result_wt = BKE_ptcache_read_cache(&pid_wt, (float)framenr, scene->r.frs_sec); - - if(cache_result_wt == PTCACHE_READ_EXACT) - { - BKE_ptcache_validate(cache_wt, framenr); - - return; - } - else - { - ; /* don't return in the case we only got low res cache but no high res cache */ - /* we still need to calculate the high res cache */ - } - } - else - return; + return; } + /* only calculate something when we advanced a single frame */ - else if(framenr != (int)smd->time+1) + if(framenr != (int)smd->time+1) return; /* don't simulate if viewing start frame, but scene frame is not real start frame */ @@ -1418,15 +1377,19 @@ void smokeModifier_do(SmokeModifierData *smd, Scene *scene, Object *ob, DerivedM smoke_calc_domain(scene, ob, smd); /* if on second frame, write cache for first frame */ - /* this needs to be done for smoke too so that pointcache works properly */ if((int)smd->time == startframe && (cache->flag & PTCACHE_OUTDATED || cache->last_exact==0)) { // create shadows straight after domain initialization so we get nice shadows for startframe, too if(get_lamp(scene, light)) smoke_calc_transparency(sds->shadow, smoke_get_density(sds->fluid), sds->p0, sds->p1, sds->res, sds->dx, light, calc_voxel_transp, -7.0*sds->dx); - BKE_ptcache_write_cache(&pid, startframe); if(sds->wt) - BKE_ptcache_write_cache(&pid_wt, startframe); + { + if(sds->flags & MOD_SMOKE_DISSOLVE) + smoke_dissolve_wavelet(sds->wt, sds->diss_speed, sds->flags & MOD_SMOKE_DISSOLVE_LOG); + smoke_turbulence_step(sds->wt, sds->fluid); + } + + BKE_ptcache_write_cache(&pid, startframe); } // set new time @@ -1444,39 +1407,24 @@ void smokeModifier_do(SmokeModifierData *smd, Scene *scene, Object *ob, DerivedM smoke_dissolve(sds->fluid, sds->diss_speed, sds->flags & MOD_SMOKE_DISSOLVE_LOG); smoke_step(sds->fluid, smd->time, scene->r.frs_sec / scene->r.frs_sec_base); } - else - { - /* Smoke did not load cache and was not reset but we're on startframe */ - /* So now reinit the smoke since it was not done yet */ - if(did_init == 2) - { - smokeModifier_reset(smd); - smokeModifier_init(smd, ob, scene, dm); - } - } // create shadows before writing cache so they get stored if(get_lamp(scene, light)) smoke_calc_transparency(sds->shadow, smoke_get_density(sds->fluid), sds->p0, sds->p1, sds->res, sds->dx, light, calc_voxel_transp, -7.0*sds->dx); - - BKE_ptcache_validate(cache, framenr); - BKE_ptcache_write_cache(&pid, framenr); if(sds->wt) { - if(framenr!=startframe) - { - if(sds->flags & MOD_SMOKE_DISSOLVE) - smoke_dissolve_wavelet(sds->wt, sds->diss_speed, sds->flags & MOD_SMOKE_DISSOLVE_LOG); - smoke_turbulence_step(sds->wt, sds->fluid); - } - - BKE_ptcache_validate(cache_wt, framenr); - BKE_ptcache_write_cache(&pid_wt, framenr); + if(sds->flags & MOD_SMOKE_DISSOLVE) + smoke_dissolve_wavelet(sds->wt, sds->diss_speed, sds->flags & MOD_SMOKE_DISSOLVE_LOG); + smoke_turbulence_step(sds->wt, sds->fluid); } + + BKE_ptcache_validate(cache, framenr); + if(framenr != startframe) + BKE_ptcache_write_cache(&pid, framenr); tend(); - printf ( "Frame: %d, Time: %f\n", (int)smd->time, ( float ) tval() ); + //printf ( "Frame: %d, Time: %f\n", (int)smd->time, ( float ) tval() ); } } |