forked from bartvdbraak/blender
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
This commit is contained in:
parent
650a44595b
commit
7432924216
@ -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)
|
float **heatold, float **vx, float **vy, float **vz, float **r, float **g, float **b, unsigned char **obstacles)
|
||||||
{
|
{
|
||||||
*dens = fluid->_density;
|
*dens = fluid->_density;
|
||||||
*fuel = fluid->_fuel;
|
if(fuel)
|
||||||
*react = fluid->_react;
|
*fuel = fluid->_fuel;
|
||||||
*flame = fluid->_flame;
|
if(react)
|
||||||
*heat = fluid->_heat;
|
*react = fluid->_react;
|
||||||
*heatold = fluid->_heatOld;
|
if(flame)
|
||||||
|
*flame = fluid->_flame;
|
||||||
|
if(heat)
|
||||||
|
*heat = fluid->_heat;
|
||||||
|
if(heatold)
|
||||||
|
*heatold = fluid->_heatOld;
|
||||||
*vx = fluid->_xVelocity;
|
*vx = fluid->_xVelocity;
|
||||||
*vy = fluid->_yVelocity;
|
*vy = fluid->_yVelocity;
|
||||||
*vz = fluid->_zVelocity;
|
*vz = fluid->_zVelocity;
|
||||||
*r = fluid->_color_r;
|
if(r)
|
||||||
*g = fluid->_color_g;
|
*r = fluid->_color_r;
|
||||||
*b = fluid->_color_b;
|
if(g)
|
||||||
|
*g = fluid->_color_g;
|
||||||
|
if(b)
|
||||||
|
*b = fluid->_color_b;
|
||||||
*obstacles = fluid->_obstacles;
|
*obstacles = fluid->_obstacles;
|
||||||
*dt = fluid->_dt;
|
*dt = fluid->_dt;
|
||||||
*dx = fluid->_dx;
|
*dx = fluid->_dx;
|
||||||
@ -195,12 +203,18 @@ extern "C" void smoke_turbulence_export(WTURBULENCE *wt, float **dens, float **r
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
*dens = wt->_densityBig;
|
*dens = wt->_densityBig;
|
||||||
*fuel = wt->_fuelBig;
|
if(fuel)
|
||||||
*react = wt->_reactBig;
|
*fuel = wt->_fuelBig;
|
||||||
*flame = wt->_flameBig;
|
if(react)
|
||||||
*r = wt->_color_rBig;
|
*react = wt->_reactBig;
|
||||||
*g = wt->_color_gBig;
|
if(flame)
|
||||||
*b = wt->_color_bBig;
|
*flame = wt->_flameBig;
|
||||||
|
if(r)
|
||||||
|
*r = wt->_color_rBig;
|
||||||
|
if(g)
|
||||||
|
*g = wt->_color_gBig;
|
||||||
|
if(b)
|
||||||
|
*b = wt->_color_bBig;
|
||||||
*tcu = wt->_tcU;
|
*tcu = wt->_tcU;
|
||||||
*tcv = wt->_tcV;
|
*tcv = wt->_tcV;
|
||||||
*tcw = wt->_tcW;
|
*tcw = wt->_tcW;
|
||||||
|
@ -657,6 +657,85 @@ static int ptcache_smoke_write(PTCacheFile *pf, void *smoke_v)
|
|||||||
|
|
||||||
return ret;
|
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)
|
static int ptcache_smoke_read(PTCacheFile *pf, void *smoke_v)
|
||||||
{
|
{
|
||||||
SmokeModifierData *smd= (SmokeModifierData *)smoke_v;
|
SmokeModifierData *smd= (SmokeModifierData *)smoke_v;
|
||||||
@ -671,7 +750,13 @@ static int ptcache_smoke_read(PTCacheFile *pf, void *smoke_v)
|
|||||||
|
|
||||||
/* version header */
|
/* version header */
|
||||||
ptcache_file_read(pf, version, 4, sizeof(char));
|
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 */
|
/* fluid info */
|
||||||
ptcache_file_read(pf, &cache_fields, 1, sizeof(int));
|
ptcache_file_read(pf, &cache_fields, 1, sizeof(int));
|
||||||
ptcache_file_read(pf, &active_fields, 1, sizeof(int));
|
ptcache_file_read(pf, &active_fields, 1, sizeof(int));
|
||||||
|
Loading…
Reference in New Issue
Block a user