Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Genrich <daniel.genrich@gmx.net>2009-08-14 21:39:27 +0400
committerDaniel Genrich <daniel.genrich@gmx.net>2009-08-14 21:39:27 +0400
commit52485190e898858f97da64d0eaf4307d46542a08 (patch)
tree889c1359c40aa54aab37f09db3f1d253e8bff588 /source/blender/blenkernel
parenteef09b9cba900c15d9908615539728e028d77d03 (diff)
Pointcache:
* prepare pointcache for smoke (smoke doesn't use it yet, commit follows later)
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r--source/blender/blenkernel/BKE_pointcache.h13
-rw-r--r--source/blender/blenkernel/intern/pointcache.c285
2 files changed, 244 insertions, 54 deletions
diff --git a/source/blender/blenkernel/BKE_pointcache.h b/source/blender/blenkernel/BKE_pointcache.h
index c8a7a1cbf90..55afec7c6f1 100644
--- a/source/blender/blenkernel/BKE_pointcache.h
+++ b/source/blender/blenkernel/BKE_pointcache.h
@@ -57,9 +57,11 @@
#define PTCACHE_FILE_WRITE 1
/* PTCacheID types */
-#define PTCACHE_TYPE_SOFTBODY 0
-#define PTCACHE_TYPE_PARTICLES 1
-#define PTCACHE_TYPE_CLOTH 2
+#define PTCACHE_TYPE_SOFTBODY 0
+#define PTCACHE_TYPE_PARTICLES 1
+#define PTCACHE_TYPE_CLOTH 2
+#define PTCACHE_TYPE_SMOKE_DOMAIN_LOW 3
+#define PTCACHE_TYPE_SMOKE_DOMAIN_HIGH 4
/* PTCache read return code */
#define PTCACHE_READ_EXACT 1
@@ -112,8 +114,12 @@ typedef struct PTCacheID {
/* copies point data to cache data */
int (*write_elem)(int index, void *calldata, void **data);
+ /* copies point data to cache data */
+ int (*write_stream)(PTCacheFile *pf, void *calldata);
/* copies cache cata to point data */
void (*read_elem)(int index, void *calldata, void **data, float frs_sec, float cfra, float *old_data);
+ /* copies cache cata to point data */
+ void (*read_stream)(PTCacheFile *pf, void *calldata);
/* interpolated between previously read point data and cache data */
void (*interpolate_elem)(int index, void *calldata, void **data, float frs_sec, float cfra, float cfra1, float cfra2, float *old_data);
@@ -151,6 +157,7 @@ void BKE_ptcache_make_particle_key(struct ParticleKey *key, int index, void **da
void BKE_ptcache_id_from_softbody(PTCacheID *pid, struct Object *ob, struct SoftBody *sb);
void BKE_ptcache_id_from_particles(PTCacheID *pid, struct Object *ob, struct ParticleSystem *psys);
void BKE_ptcache_id_from_cloth(PTCacheID *pid, struct Object *ob, struct ClothModifierData *clmd);
+void BKE_ptcache_id_from_smoke(PTCacheID *pid, struct Object *ob, struct SmokeModifierData *smd, int num);
void BKE_ptcache_ids_from_object(struct ListBase *lb, struct Object *ob);
diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c
index 59e2c3f6d72..cbbc09679c5 100644
--- a/source/blender/blenkernel/intern/pointcache.c
+++ b/source/blender/blenkernel/intern/pointcache.c
@@ -39,6 +39,7 @@
#include "DNA_object_force.h"
#include "DNA_particle_types.h"
#include "DNA_scene_types.h"
+#include "DNA_smoke_types.h"
#include "BLI_blenlib.h"
@@ -52,11 +53,14 @@
#include "BKE_particle.h"
#include "BKE_pointcache.h"
#include "BKE_scene.h"
+#include "BKE_smoke.h"
#include "BKE_softbody.h"
#include "BKE_utildefines.h"
#include "BLI_blenlib.h"
+#include "smoke_API.h"
+
/* needed for directory lookup */
#ifndef WIN32
#include <dirent.h>
@@ -305,6 +309,7 @@ static int ptcache_totwrite_particle(void *psys_v)
return totwrite;
}
+
/* Cloth functions */
static int ptcache_write_cloth(int index, void *cloth_v, void **data)
{
@@ -376,6 +381,7 @@ static int ptcache_totpoint_cloth(void *cloth_v)
ClothModifierData *clmd= cloth_v;
return clmd->clothObject->numverts;
}
+
/* Creating ID's */
void BKE_ptcache_id_from_softbody(PTCacheID *pid, Object *ob, SoftBody *sb)
{
@@ -394,6 +400,8 @@ void BKE_ptcache_id_from_softbody(PTCacheID *pid, Object *ob, SoftBody *sb)
pid->totpoint= pid->totwrite= ptcache_totpoint_softbody;
pid->write_elem= ptcache_write_softbody;
+ pid->write_stream = NULL;
+ pid->read_stream = NULL;
pid->read_elem= ptcache_read_softbody;
pid->interpolate_elem= ptcache_interpolate_softbody;
@@ -432,6 +440,8 @@ void BKE_ptcache_id_from_particles(PTCacheID *pid, Object *ob, ParticleSystem *p
pid->ptcaches= &psys->ptcaches;
pid->write_elem= ptcache_write_particle;
+ pid->write_stream = NULL;
+ pid->read_stream = NULL;
pid->read_elem= ptcache_read_particle;
pid->interpolate_elem= ptcache_interpolate_particle;
@@ -459,6 +469,110 @@ void BKE_ptcache_id_from_particles(PTCacheID *pid, Object *ob, ParticleSystem *p
pid->info_types= (1<<BPHYS_DATA_TIMES);
}
+/* Smoke functions */
+static int ptcache_totpoint_smoke(void *smoke_v)
+{
+ SmokeModifierData *smd= (SmokeModifierData *)smoke_v;
+ SmokeDomainSettings *sds = smd->domain;
+
+ if(sds->fluid)
+ {
+ return sds->res[0]*sds->res[1]*sds->res[2];
+ }
+ else
+ return 0;
+}
+
+// forward decleration
+static int ptcache_file_write(PTCacheFile *pf, void *f, size_t tot, int size);
+
+static int ptcache_write_smoke(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 *dens, *densold, *heat, *heatold, *vx, *vy, *vz;
+
+ smoke_export(sds->fluid, &dens, &densold, &heat, &heatold, &vx, &vy, &vz);
+
+ ptcache_file_write(pf, dens, res, sizeof(float));
+ ptcache_file_write(pf, densold, res, sizeof(float));
+ ptcache_file_write(pf, heat, res, sizeof(float));
+ ptcache_file_write(pf, heatold, res, sizeof(float));
+ ptcache_file_write(pf, vx, res, sizeof(float));
+ ptcache_file_write(pf, vy, res, sizeof(float));
+ ptcache_file_write(pf, vz, res, sizeof(float));
+
+ return 1;
+ }
+
+ return 0;
+}
+
+// forward decleration
+static int ptcache_file_read(PTCacheFile *pf, void *f, size_t tot, int size);
+
+static void ptcache_read_smoke(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 *dens, *densold, *heat, *heatold, *vx, *vy, *vz;
+
+ smoke_export(sds->fluid, &dens, &densold, &heat, &heatold, &vx, &vy, &vz);
+
+ ptcache_file_read(pf, dens, res, sizeof(float));
+ ptcache_file_read(pf, densold, res, sizeof(float));
+ ptcache_file_read(pf, heat, res, sizeof(float));
+ ptcache_file_read(pf, heatold, res, sizeof(float));
+ ptcache_file_read(pf, vx, res, sizeof(float));
+ ptcache_file_read(pf, vy, res, sizeof(float));
+ ptcache_file_read(pf, vz, res, sizeof(float));
+
+ }
+}
+void BKE_ptcache_id_from_smoke(PTCacheID *pid, struct Object *ob, struct SmokeModifierData *smd, int num)
+{
+ SmokeDomainSettings *sds = smd->domain;
+
+ memset(pid, 0, sizeof(PTCacheID));
+
+ pid->ob= ob;
+ pid->calldata= smd;
+
+ // if(num == 0)
+ pid->type= PTCACHE_TYPE_SMOKE_DOMAIN_LOW;
+ // else if(num == 1)
+ // pid->type= PTCACHE_TYPE_SMOKE_DOMAIN_HIGH;
+
+ pid->stack_index= modifiers_indexInObject(ob, (ModifierData *)smd);
+
+ pid->cache= sds->point_cache;
+ pid->cache_ptr= &sds->point_cache;
+ pid->ptcaches= &sds->ptcaches;
+
+
+ pid->totpoint= pid->totwrite= ptcache_totpoint_smoke;
+
+ pid->write_elem= NULL;
+ pid->read_elem= NULL;
+ pid->read_stream = ptcache_read_smoke;
+ pid->write_stream = ptcache_write_smoke;
+ 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;
+}
+
void BKE_ptcache_id_from_cloth(PTCacheID *pid, Object *ob, ClothModifierData *clmd)
{
memset(pid, 0, sizeof(PTCacheID));
@@ -473,6 +587,8 @@ void BKE_ptcache_id_from_cloth(PTCacheID *pid, Object *ob, ClothModifierData *cl
pid->totpoint= pid->totwrite= ptcache_totpoint_cloth;
pid->write_elem= ptcache_write_cloth;
+ pid->write_stream = NULL;
+ pid->read_stream = NULL;
pid->read_elem= ptcache_read_cloth;
pid->interpolate_elem= ptcache_interpolate_cloth;
@@ -515,6 +631,18 @@ void BKE_ptcache_ids_from_object(ListBase *lb, Object *ob)
BKE_ptcache_id_from_cloth(pid, ob, (ClothModifierData*)md);
BLI_addtail(lb, pid);
}
+ /*
+ // enabled on next commit
+ if(md->type == eModifierType_Smoke) {
+ SmokeModifierData *smd = (SmokeModifierData *)md;
+ if(smd->type & MOD_SMOKE_TYPE_DOMAIN)
+ {
+ pid= MEM_callocN(sizeof(PTCacheID), "PTCacheID");
+ BKE_ptcache_id_from_smoke(pid, ob, (SmokeModifierData*)md, 0);
+ BLI_addtail(lb, pid);
+ }
+ }
+ */
}
}
@@ -533,7 +661,7 @@ void BKE_ptcache_ids_from_object(ListBase *lb, Object *ob)
static int ptcache_path(PTCacheID *pid, char *filename)
{
Library *lib;
- int i;
+ size_t i;
lib= (pid)? pid->ob->id.lib: NULL;
@@ -591,7 +719,7 @@ static int BKE_ptcache_id_filename(PTCacheID *pid, char *filename, int cfra, sho
}
}
else {
- int temp = strlen(pid->cache->name);
+ int temp = (int)strlen(pid->cache->name);
strcpy(newname, pid->cache->name);
newname+=temp;
len += temp;
@@ -653,11 +781,11 @@ static void ptcache_file_close(PTCacheFile *pf)
MEM_freeN(pf);
}
-static int ptcache_file_read(PTCacheFile *pf, void *f, int tot, int size)
+static int ptcache_file_read(PTCacheFile *pf, void *f, size_t tot, int size)
{
return (fread(f, size, tot, pf->fp) == tot);
}
-static int ptcache_file_write(PTCacheFile *pf, void *f, int tot, int size)
+static int ptcache_file_write(PTCacheFile *pf, void *f, size_t tot, int size)
{
return (fwrite(f, size, tot, pf->fp) == tot);
}
@@ -988,56 +1116,93 @@ int BKE_ptcache_read_cache(PTCacheID *pid, float cfra, float frs_sec)
if(cfra1 && cfra1==cfra2)
error = 1;
- totpoint = MIN2(totpoint, pid->totpoint(pid->calldata));
- totpoint2 = MIN2(totpoint2, pid->totpoint(pid->calldata));
-
- if(!error) for(i=0; i<totpoint; i++) {
- /* read old cache file format */
- if(use_old) {
- if(ptcache_file_read(pf, (void*)old_data1, 1, old_elemsize))
- pid->read_elem(i, pid->calldata, NULL, frs_sec, cfra, old_data1);
+ if(!error)
+ {
+ if(pf && pid->read_stream) {
+ if(totpoint != pid->totpoint(pid->calldata))
+ error = 1;
else
- { error = 1; break; }
+ {
+ // we have stream writing here
+ pid->read_stream(pf, pid->calldata);
+ }
}
- else {
- if(pm || ptcache_file_read_data(pf))
- pid->read_elem(*index, pid->calldata, pm ? pm->cur : pf->cur, frs_sec, cfra1 ? (float)cfra1 : (float)cfrai, NULL);
- else
- { error = 1; break; }
+ }
+
+ totpoint = MIN2(totpoint, pid->totpoint(pid->calldata));
+
+ if(!error)
+ {
+ for(i=0; i<totpoint; i++) {
+ /* read old cache file format */
+ if(use_old) {
+ if(pid->read_elem && ptcache_file_read(pf, (void*)old_data1, 1, old_elemsize))
+ pid->read_elem(i, pid->calldata, NULL, frs_sec, cfra, old_data1);
+ else
+ { error = 1; break; }
+ }
+ else {
+ if(pid->read_elem && (pm || ptcache_file_read_data(pf)))
+ pid->read_elem(*index, pid->calldata, pm ? pm->cur : pf->cur, frs_sec, cfra1 ? (float)cfra1 : (float)cfrai, NULL);
+ else
+ { error = 1; break; }
+ }
+
+ if(pm) {
+ ptcache_mem_incr_pointers(pm);
+ index = pm->data_types & (1<<BPHYS_DATA_INDEX) ? pm->cur[BPHYS_DATA_INDEX] : &i;
+ }
}
+ }
- if(pm) {
- ptcache_mem_incr_pointers(pm);
- index = pm->data_types & (1<<BPHYS_DATA_INDEX) ? pm->cur[BPHYS_DATA_INDEX] : &i;
+ if(!error)
+ {
+ if(pf2 && pid->read_stream) {
+ if(totpoint2 != pid->totpoint(pid->calldata))
+ error = 1;
+ else
+ {
+ // we have stream writing here
+ pid->read_stream(pf2, pid->calldata);
+ }
}
}
- if(!error) for(i=0; i<totpoint2; i++) {
- /* read old cache file format */
- if(use_old) {
- if(ptcache_file_read(pf2, (void*)old_data2, 1, old_elemsize)) {
- if(!pf && pf2)
- pid->read_elem(i, pid->calldata, NULL, frs_sec, (float)cfra2, old_data2);
+ totpoint2 = MIN2(totpoint2, pid->totpoint(pid->calldata));
+
+ if(!error)
+ {
+ for(i=0; i<totpoint2; i++) {
+ /* read old cache file format */
+ if(use_old) {
+ if(pid->read_elem && ptcache_file_read(pf2, (void*)old_data2, 1, old_elemsize)) {
+ if(!pf && pf2)
+ pid->read_elem(i, pid->calldata, NULL, frs_sec, (float)cfra2, old_data2);
+ else if(pid->interpolate_elem)
+ pid->interpolate_elem(i, pid->calldata, NULL, frs_sec, cfra, (float)cfra1, (float)cfra2, old_data2);
+ else
+ { error = 1; break; }
+ }
else
- pid->interpolate_elem(i, pid->calldata, NULL, frs_sec, cfra, (float)cfra1, (float)cfra2, old_data2);
+ { error = 1; break; }
}
- else
- { error = 1; break; }
- }
- else {
- if(pm2 || ptcache_file_read_data(pf2)) {
- if((!pf && pf2) || (!pm && pm2))
- pid->read_elem(*index2, pid->calldata, pm2 ? pm2->cur : pf2->cur, frs_sec, (float)cfra2, NULL);
+ else {
+ if(pid->read_elem && (pm2 || ptcache_file_read_data(pf2))) {
+ if((!pf && pf2) || (!pm && pm2))
+ pid->read_elem(*index2, pid->calldata, pm2 ? pm2->cur : pf2->cur, frs_sec, (float)cfra2, NULL);
+ else if(pid->interpolate_elem)
+ pid->interpolate_elem(*index2, pid->calldata, pm2 ? pm2->cur : pf2->cur, frs_sec, cfra, (float)cfra1, (float)cfra2, NULL);
+ else
+ { error = 1; break; }
+ }
else
- pid->interpolate_elem(*index2, pid->calldata, pm2 ? pm2->cur : pf2->cur, frs_sec, cfra, (float)cfra1, (float)cfra2, NULL);
+ { error = 1; break; }
}
- else
- { error = 1; break; }
- }
- if(pm2) {
- ptcache_mem_incr_pointers(pm2);
- index2 = pm2->data_types & (1<<BPHYS_DATA_INDEX) ? pm2->cur[BPHYS_DATA_INDEX] : &i;
+ if(pm2) {
+ ptcache_mem_incr_pointers(pm2);
+ index2 = pm2->data_types & (1<<BPHYS_DATA_INDEX) ? pm2->cur[BPHYS_DATA_INDEX] : &i;
+ }
}
}
@@ -1156,13 +1321,18 @@ int BKE_ptcache_write_cache(PTCacheID *pid, int cfra)
ptcache_file_init_pointers(pf);
- for(i=0; i<totpoint; i++) {
- if(pid->write_elem(i, pid->calldata, pf->cur))
- if(!ptcache_file_write_data(pf)) {
- ptcache_file_close(pf);
- return 0;
- }
+ if(pf && pid->write_stream) {
+ // we have stream writing here
+ pid->write_stream(pf, pid->calldata);
}
+ else
+ for(i=0; i<totpoint; i++) {
+ if(pid->write_elem && pid->write_elem(i, pid->calldata, pf->cur))
+ if(!ptcache_file_write_data(pf)) {
+ ptcache_file_close(pf);
+ return 0;
+ }
+ }
}
}
else {
@@ -1206,7 +1376,7 @@ int BKE_ptcache_write_cache(PTCacheID *pid, int cfra)
ptcache_mem_init_pointers(pm);
for(i=0; i<totpoint; i++) {
- if(pid->write_elem(i, pid->calldata, pm->cur))
+ if(pid->write_elem && pid->write_elem(i, pid->calldata, pm->cur))
ptcache_mem_incr_pointers(pm);
}
//ptcache_make_index_array(pm, pid->totpoint(pid->calldata));
@@ -1284,7 +1454,7 @@ void BKE_ptcache_id_clear(PTCacheID *pid, int mode, int cfra)
BLI_delete(path_full, 0, 0);
} else {
/* read the number of the file */
- int frame, len2 = strlen(de->d_name);
+ 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*/
@@ -1468,6 +1638,8 @@ int BKE_ptcache_id_reset(Scene *scene, PTCacheID *pid, int mode)
sbFreeSimulation(pid->calldata);
else if(pid->type == PTCACHE_TYPE_PARTICLES)
psys_reset(pid->calldata, PSYS_RESET_DEPSGRAPH);
+ else if(pid->type == PTCACHE_TYPE_SMOKE_DOMAIN_LOW)
+ smokeModifier_reset(pid->calldata);
}
if(clear)
BKE_ptcache_id_clear(pid, PTCACHE_CLEAR_ALL, 0);
@@ -1516,6 +1688,17 @@ int BKE_ptcache_object_reset(Scene *scene, Object *ob, int mode)
BKE_ptcache_id_from_cloth(&pid, ob, (ClothModifierData*)md);
reset |= BKE_ptcache_id_reset(scene, &pid, mode);
}
+ /*
+ // enabled on next commit
+ if(md->type == eModifierType_Smoke) {
+ SmokeModifierData *smd = (SmokeModifierData *)md;
+ if(smd->type & MOD_SMOKE_TYPE_DOMAIN)
+ {
+ BKE_ptcache_id_from_smoke(&pid, ob, (SmokeModifierData*)md, 0);
+ reset |= BKE_ptcache_id_reset(scene, &pid, mode);
+ }
+ }
+ */
}
return reset;
@@ -2034,7 +2217,7 @@ void BKE_ptcache_load_external(PTCacheID *pid)
if (strstr(de->d_name, ext)) { /* do we have the right extension?*/
if (strncmp(filename, de->d_name, len ) == 0) { /* do we have the right prefix */
/* read the number of the file */
- int frame, len2 = strlen(de->d_name);
+ 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*/