[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [22457] branches/blender2.5/blender/source /blender/blenkernel: Pointcache:
Daniel Genrich
daniel.genrich at gmx.net
Fri Aug 14 19:39:28 CEST 2009
Revision: 22457
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=22457
Author: genscher
Date: 2009-08-14 19:39:27 +0200 (Fri, 14 Aug 2009)
Log Message:
-----------
Pointcache:
* prepare pointcache for smoke (smoke doesn't use it yet, commit follows later)
Modified Paths:
--------------
branches/blender2.5/blender/source/blender/blenkernel/BKE_pointcache.h
branches/blender2.5/blender/source/blender/blenkernel/intern/pointcache.c
Modified: branches/blender2.5/blender/source/blender/blenkernel/BKE_pointcache.h
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/BKE_pointcache.h 2009-08-14 17:16:16 UTC (rev 22456)
+++ branches/blender2.5/blender/source/blender/blenkernel/BKE_pointcache.h 2009-08-14 17:39:27 UTC (rev 22457)
@@ -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 @@
/* 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_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);
Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/pointcache.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/pointcache.c 2009-08-14 17:16:16 UTC (rev 22456)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/pointcache.c 2009-08-14 17:39:27 UTC (rev 22457)
@@ -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 @@
return totwrite;
}
+
/* Cloth functions */
static int ptcache_write_cloth(int index, void *cloth_v, void **data)
{
@@ -376,6 +381,7 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
}
}
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 @@
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 @@
if(cfra1 && cfra1==cfra2)
error = 1;
+ if(!error)
+ {
+ if(pf && pid->read_stream) {
+ if(totpoint != pid->totpoint(pid->calldata))
+ error = 1;
+ else
+ {
+ // we have stream writing here
+ pid->read_stream(pf, pid->calldata);
+ }
+ }
+ }
+
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);
- else
- { error = 1; break; }
+ 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;
+ }
}
- 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);
+ }
+
+ if(!error)
+ {
+ if(pf2 && pid->read_stream) {
+ if(totpoint2 != pid->totpoint(pid->calldata))
+ error = 1;
else
- { error = 1; break; }
+ {
+ // we have stream writing here
+ pid->read_stream(pf2, pid->calldata);
+ }
}
-
- if(pm) {
- ptcache_mem_incr_pointers(pm);
- index = pm->data_types & (1<<BPHYS_DATA_INDEX) ? pm->cur[BPHYS_DATA_INDEX] : &i;
- }
}
- 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)) {
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list