diff --git a/intern/smoke/intern/smoke_API.cpp b/intern/smoke/intern/smoke_API.cpp index 6011de0bddb..67f1ea29533 100644 --- a/intern/smoke/intern/smoke_API.cpp +++ b/intern/smoke/intern/smoke_API.cpp @@ -172,17 +172,25 @@ extern "C" void smoke_export(FLUID_3D *fluid, float *dt, float *dx, float **dens float **heatold, float **vx, float **vy, float **vz, float **r, float **g, float **b, unsigned char **obstacles) { *dens = fluid->_density; - *fuel = fluid->_fuel; - *react = fluid->_react; - *flame = fluid->_flame; - *heat = fluid->_heat; - *heatold = fluid->_heatOld; + if(fuel) + *fuel = fluid->_fuel; + if(react) + *react = fluid->_react; + if(flame) + *flame = fluid->_flame; + if(heat) + *heat = fluid->_heat; + if(heatold) + *heatold = fluid->_heatOld; *vx = fluid->_xVelocity; *vy = fluid->_yVelocity; *vz = fluid->_zVelocity; - *r = fluid->_color_r; - *g = fluid->_color_g; - *b = fluid->_color_b; + if(r) + *r = fluid->_color_r; + if(g) + *g = fluid->_color_g; + if(b) + *b = fluid->_color_b; *obstacles = fluid->_obstacles; *dt = fluid->_dt; *dx = fluid->_dx; @@ -195,12 +203,18 @@ extern "C" void smoke_turbulence_export(WTURBULENCE *wt, float **dens, float **r return; *dens = wt->_densityBig; - *fuel = wt->_fuelBig; - *react = wt->_reactBig; - *flame = wt->_flameBig; - *r = wt->_color_rBig; - *g = wt->_color_gBig; - *b = wt->_color_bBig; + if(fuel) + *fuel = wt->_fuelBig; + if(react) + *react = wt->_reactBig; + if(flame) + *flame = wt->_flameBig; + if(r) + *r = wt->_color_rBig; + if(g) + *g = wt->_color_gBig; + if(b) + *b = wt->_color_bBig; *tcu = wt->_tcU; *tcv = wt->_tcV; *tcw = wt->_tcW; 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<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));