diff options
author | Daniel Genrich <daniel.genrich@gmx.net> | 2013-03-19 01:33:48 +0400 |
---|---|---|
committer | Daniel Genrich <daniel.genrich@gmx.net> | 2013-03-19 01:33:48 +0400 |
commit | 743292421640c012f7a029ae2e0d9a312b01895f (patch) | |
tree | d06449fdfe0e0f69cd8c62e2f0208e9d0f67cca8 /source/blender | |
parent | 650a44595b134e7451f52e1b250e52196373b8da (diff) |
Smoke Bugfix /enhancement: Load pre 2.65 pointcaches.
Warning: Just make sure that you DON'T free the cache at any point. This patch can only display existing pointcaches from e.g. 2.64
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/intern/pointcache.c | 87 |
1 files changed, 86 insertions, 1 deletions
diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c index 968e9fe3206..8034c4d1de9 100644 --- a/source/blender/blenkernel/intern/pointcache.c +++ b/source/blender/blenkernel/intern/pointcache.c @@ -657,6 +657,85 @@ static int ptcache_smoke_write(PTCacheFile *pf, void *smoke_v) return ret; } + +/* read old smoke cache from 2.64 */ +static int ptcache_smoke_read_old(PTCacheFile *pf, void *smoke_v) +{ + SmokeModifierData *smd= (SmokeModifierData *)smoke_v; + SmokeDomainSettings *sds = smd->domain; + + if (sds->fluid) { + size_t res = sds->res[0]*sds->res[1]*sds->res[2]; + float dt, dx, *dens, *heat, *heatold, *vx, *vy, *vz; + unsigned char *obstacles; + unsigned int out_len = (unsigned int)res * sizeof(float); + float *tmp_array = MEM_callocN(out_len, "Smoke old cache tmp"); + + int fluid_fields = smoke_get_data_flags(sds); + + /* Part part of the new cache header */ + sds->active_color[0] = 0.7f; + sds->active_color[1] = 0.7f; + sds->active_color[2] = 0.7f; + + smoke_export(sds->fluid, &dt, &dx, &dens, NULL, NULL, NULL, &heat, &heatold, &vx, &vy, &vz, NULL, NULL, NULL, &obstacles); + + ptcache_file_compressed_read(pf, (unsigned char *)sds->shadow, out_len); + ptcache_file_compressed_read(pf, (unsigned char*)dens, out_len); + ptcache_file_compressed_read(pf, (unsigned char*)tmp_array, out_len); + + if (fluid_fields & SM_ACTIVE_HEAT) + { + ptcache_file_compressed_read(pf, (unsigned char*)heat, out_len); + ptcache_file_compressed_read(pf, (unsigned char*)heatold, out_len); + } + else + { + ptcache_file_compressed_read(pf, (unsigned char*)tmp_array, out_len); + ptcache_file_compressed_read(pf, (unsigned char*)tmp_array, out_len); + } + ptcache_file_compressed_read(pf, (unsigned char*)vx, out_len); + ptcache_file_compressed_read(pf, (unsigned char*)vy, out_len); + ptcache_file_compressed_read(pf, (unsigned char*)vz, out_len); + ptcache_file_compressed_read(pf, (unsigned char*)tmp_array, out_len); + ptcache_file_compressed_read(pf, (unsigned char*)tmp_array, out_len); + ptcache_file_compressed_read(pf, (unsigned char*)tmp_array, out_len); + ptcache_file_compressed_read(pf, (unsigned char*)obstacles, (unsigned int)res); + ptcache_file_read(pf, &dt, 1, sizeof(float)); + ptcache_file_read(pf, &dx, 1, sizeof(float)); + + MEM_freeN(tmp_array); + + 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, *tcu, *tcv, *tcw; + unsigned int out_len = sizeof(float)*(unsigned int)res; + unsigned int out_len_big; + unsigned char *tmp_array_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; + + tmp_array_big = MEM_callocN(out_len_big, "Smoke old cache tmp"); + + smoke_turbulence_export(sds->wt, &dens, NULL, NULL, NULL, NULL, NULL, NULL, &tcu, &tcv, &tcw); + + ptcache_file_compressed_read(pf, (unsigned char*)dens, out_len_big); + ptcache_file_compressed_read(pf, (unsigned char*)tmp_array_big, out_len_big); + + ptcache_file_compressed_read(pf, (unsigned char*)tcu, out_len); + ptcache_file_compressed_read(pf, (unsigned char*)tcv, out_len); + ptcache_file_compressed_read(pf, (unsigned char*)tcw, out_len); + + MEM_freeN(tmp_array_big); + } + } + + return 1; +} + static int ptcache_smoke_read(PTCacheFile *pf, void *smoke_v) { SmokeModifierData *smd= (SmokeModifierData *)smoke_v; @@ -671,7 +750,13 @@ static int ptcache_smoke_read(PTCacheFile *pf, void *smoke_v) /* version header */ ptcache_file_read(pf, version, 4, sizeof(char)); - if (strncmp(version, SMOKE_CACHE_VERSION, 4)) return 0; + if (strncmp(version, SMOKE_CACHE_VERSION, 4)) + { + /* reset file pointer */ + fseek(pf->fp, -4, SEEK_CUR); + return ptcache_smoke_read_old(pf, smoke_v); + } + /* fluid info */ ptcache_file_read(pf, &cache_fields, 1, sizeof(int)); ptcache_file_read(pf, &active_fields, 1, sizeof(int)); |