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:
authorJanne Karhu <jhkarh@gmail.com>2009-08-12 13:54:29 +0400
committerJanne Karhu <jhkarh@gmail.com>2009-08-12 13:54:29 +0400
commitb221c0e2e6f390f3ed810b7f520b0ad60511ba36 (patch)
tree09b3b18e14773ee015959b214284cc5010f6fdc4 /source/blender/editors/physics/ed_pointcache.c
parent8641833b57606a2ac21f7c83b53ea5fc55664815 (diff)
New point cache file format:
- HEADER (beginning of each file) * general header: + 8 char: "BPHYSICS" + 1 int: simulation type (same as PTCacheID->type) * custom header (same for sb, particles and cloth, but can be different for new dynamics) + 1 int: totpoint (number of points) + 1 int: data_types (bit flags for what the stored data is) - DATA (directly after header) *totpoint times the data as specified in data_types flags - simulation type soft body = 0, particles = 1, cloth = 2 - data types (more can be added easily when needed) data flag contains ---------------------------------------- index (1<<0) 1 int (index of current point) location (1<<1) 3 float velocity (1<<2) 3 float rotation (1<<3) 4 float (quaternion) avelocity (1<<4) 3 float (used for particles) xconst (1<<4) 3 float (used for cloth) size (1<<5) 1 float times (1<<6) 3 float (birth, die & lifetime of particle) boids (1<<7) 1 BoidData Notes: - Every frame is not nescessary since data is interpolated for the inbetween frames. - For now every point is needed for every cached frame, the "index" data type is reserved for future usage. - For loading external particle caches only "location" data is necessary, other needed values are determined from the given data. - Non-dynamic data should be written into an info file if external usage is desired. * Info file is named as normal cache files, but with frame number 0; * "Non-dynamic" means data such as particle times. * Written automatically when baking to disk so basically a library of particle simulations should be possible. - Old disk cache format is supported for reading, so pre 2.5 files shouldn't break. However old style memory cache (added during 2.5 development) is not supported. To keep memory cached simulations convert the cache to disk cache before svn update and save the blend. - External sb and cloth caches should be perfectly possible, but due to lack of testing these are not yet enabled in ui. Other changes: - Multiple point caches per dynamics system. * In the future these will hopefully be nla editable etc, but for now things are simple and the current (selected) point cache is used. * Changing the amount of cached points (for example particle count) is allowed, but might not give correct results if multiple caches are present. - Generalization of point cache baking etc operator & rna code. - Comb brushing particle hair didn't work smoothly.
Diffstat (limited to 'source/blender/editors/physics/ed_pointcache.c')
-rw-r--r--source/blender/editors/physics/ed_pointcache.c332
1 files changed, 90 insertions, 242 deletions
diff --git a/source/blender/editors/physics/ed_pointcache.c b/source/blender/editors/physics/ed_pointcache.c
index 5d0a6d21fac..a256fd97686 100644
--- a/source/blender/editors/physics/ed_pointcache.c
+++ b/source/blender/editors/physics/ed_pointcache.c
@@ -61,7 +61,6 @@
static int cache_break_test(void *cbd) {
return G.afbreek==1;
}
-/**************************** general **********************************/
static int ptcache_bake_all_poll(bContext *C)
{
Scene *scene= CTX_data_scene(C);
@@ -130,7 +129,7 @@ void PTCACHE_OT_bake_all(wmOperatorType *ot)
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
- RNA_def_boolean(ot->srna, "bake", 0, "Bake", "");
+ RNA_def_boolean(ot->srna, "bake", 1, "Bake", "");
}
void PTCACHE_OT_free_bake_all(wmOperatorType *ot)
{
@@ -145,32 +144,25 @@ void PTCACHE_OT_free_bake_all(wmOperatorType *ot)
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
}
-
-/**************************** softbody **********************************/
-static int ptcache_bake_softbody_poll(bContext *C)
-{
- Scene *scene= CTX_data_scene(C);
- Object *ob= CTX_data_active_object(C);
- SoftBody *sb = ob->soft;
-
- if(!scene || !ob || ob->id.lib || !sb)
- return 0;
-
- return 1;
-}
-
-static int ptcache_bake_softbody_exec(bContext *C, wmOperator *op)
+static int ptcache_bake_exec(bContext *C, wmOperator *op)
{
- Scene *scene= CTX_data_scene(C);
- Object *ob= CTX_data_active_object(C);
- SoftBody *sb = ob->soft;
- PTCacheID pid;
+ Scene *scene = CTX_data_scene(C);
+ PointerRNA ptr= CTX_data_pointer_get_type(C, "PointCache", &RNA_PointCache);
+ Object *ob= ptr.id.data;
+ PointCache *cache= ptr.data;
PTCacheBaker baker;
+ PTCacheID *pid;
+ ListBase pidlist;
- BKE_ptcache_id_from_softbody(&pid, ob, sb);
+ BKE_ptcache_ids_from_object(&pidlist, ob);
+
+ for(pid=pidlist.first; pid; pid=pid->next) {
+ if(pid->cache == cache)
+ break;
+ }
baker.scene = scene;
- baker.pid = &pid;
+ baker.pid = pid;
baker.bake = RNA_boolean_get(op->ptr, "bake");
baker.render = 0;
baker.anim_init = 0;
@@ -182,305 +174,161 @@ static int ptcache_bake_softbody_exec(bContext *C, wmOperator *op)
BKE_ptcache_make_cache(&baker);
- WM_event_add_notifier(C, NC_SCENE|ND_FRAME, scene);
-
- return OPERATOR_FINISHED;
-}
-static int ptcache_free_bake_softbody_exec(bContext *C, wmOperator *op)
-{
- Scene *scene= CTX_data_scene(C);
- Object *ob= CTX_data_active_object(C);
- SoftBody *sb = ob->soft;
- PTCacheID pid;
-
- BKE_ptcache_id_from_softbody(&pid, ob, sb);
- pid.cache->flag &= ~PTCACHE_BAKED;
+ BLI_freelistN(&pidlist);
WM_event_add_notifier(C, NC_SCENE|ND_FRAME, scene);
return OPERATOR_FINISHED;
}
-void PTCACHE_OT_cache_softbody(wmOperatorType *ot)
+static int ptcache_free_bake_exec(bContext *C, wmOperator *op)
{
- /* identifiers */
- ot->name= "Bake Softbody";
- ot->idname= "PTCACHE_OT_cache_softbody";
+ PointerRNA ptr= CTX_data_pointer_get_type(C, "PointCache", &RNA_PointCache);
+ PointCache *cache= ptr.data;
- /* api callbacks */
- ot->exec= ptcache_bake_softbody_exec;
- ot->poll= ptcache_bake_softbody_poll;
-
- /* flags */
- ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-
- RNA_def_boolean(ot->srna, "bake", 0, "Bake", "");
-}
-void PTCACHE_OT_free_bake_softbody(wmOperatorType *ot)
-{
- /* identifiers */
- ot->name= "Free SoftBody Bake";
- ot->idname= "PTCACHE_OT_free_bake_softbody";
-
- /* api callbacks */
- ot->exec= ptcache_free_bake_softbody_exec;
- ot->poll= ptcache_bake_softbody_poll;
-
- /* flags */
- ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-}
-static int ptcache_bake_from_softbody_cache_exec(bContext *C, wmOperator *op)
-{
- Object *ob= CTX_data_active_object(C);
- SoftBody *sb = ob->soft;
- PTCacheID pid;
-
- BKE_ptcache_id_from_softbody(&pid, ob, sb);
- pid.cache->flag |= PTCACHE_BAKED;
+ cache->flag &= ~PTCACHE_BAKED;
return OPERATOR_FINISHED;
}
-void PTCACHE_OT_bake_from_softbody_cache(wmOperatorType *ot)
+static int ptcache_bake_from_cache_exec(bContext *C, wmOperator *op)
{
- /* identifiers */
- ot->name= "Bake From Cache";
- ot->idname= "PTCACHE_OT_bake_from_softbody_cache";
-
- /* api callbacks */
- ot->exec= ptcache_bake_from_softbody_cache_exec;
- ot->poll= ptcache_bake_softbody_poll;
-
- /* flags */
- ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-}
-
-/**************************** cloth **********************************/
-static int ptcache_bake_cloth_poll(bContext *C)
-{
- Scene *scene= CTX_data_scene(C);
- Object *ob= CTX_data_active_object(C);
- ClothModifierData *clmd = (ClothModifierData *)modifiers_findByType(ob, eModifierType_Cloth);
-
- if(!scene || !ob || ob->id.lib || !clmd)
- return 0;
+ PointerRNA ptr= CTX_data_pointer_get_type(C, "PointCache", &RNA_PointCache);
+ PointCache *cache= ptr.data;
- return 1;
-}
-
-static int ptcache_bake_cloth_exec(bContext *C, wmOperator *op)
-{
- Scene *scene= CTX_data_scene(C);
- Object *ob= CTX_data_active_object(C);
- ClothModifierData *clmd = (ClothModifierData *)modifiers_findByType(ob, eModifierType_Cloth);
- PTCacheID pid;
- PTCacheBaker baker;
-
- BKE_ptcache_id_from_cloth(&pid, ob, clmd);
-
- baker.scene = scene;
- baker.pid = &pid;
- baker.bake = RNA_boolean_get(op->ptr, "bake");
- baker.render = 0;
- baker.anim_init = 0;
- baker.quick_step = 1;
- baker.break_test = cache_break_test;
- baker.break_data = NULL;
- baker.progressbar = (void (*)(void *, int))WM_timecursor;
- baker.progresscontext = CTX_wm_window(C);
-
- BKE_ptcache_make_cache(&baker);
-
- WM_event_add_notifier(C, NC_SCENE|ND_FRAME, scene);
+ cache->flag |= PTCACHE_BAKED;
return OPERATOR_FINISHED;
}
-static int ptcache_free_bake_cloth_exec(bContext *C, wmOperator *op)
-{
- Scene *scene= CTX_data_scene(C);
- Object *ob= CTX_data_active_object(C);
- ClothModifierData *clmd = (ClothModifierData *)modifiers_findByType(ob, eModifierType_Cloth);
- PTCacheID pid;
-
- BKE_ptcache_id_from_cloth(&pid, ob, clmd);
- pid.cache->flag &= ~PTCACHE_BAKED;
-
- WM_event_add_notifier(C, NC_SCENE|ND_FRAME, scene);
-
- return OPERATOR_FINISHED;
-}
-void PTCACHE_OT_cache_cloth(wmOperatorType *ot)
+void PTCACHE_OT_bake(wmOperatorType *ot)
{
/* identifiers */
- ot->name= "Bake Cloth";
- ot->idname= "PTCACHE_OT_cache_cloth";
+ ot->name= "Bake Physics";
+ ot->idname= "PTCACHE_OT_bake";
/* api callbacks */
- ot->exec= ptcache_bake_cloth_exec;
- ot->poll= ptcache_bake_cloth_poll;
+ ot->exec= ptcache_bake_exec;
+ ot->poll= ptcache_bake_all_poll;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
- RNA_def_boolean(ot->srna, "bake", 0, "Bake", "");
+ RNA_def_boolean(ot->srna, "bake", 1, "Bake", "");
}
-void PTCACHE_OT_free_bake_cloth(wmOperatorType *ot)
+void PTCACHE_OT_free_bake(wmOperatorType *ot)
{
/* identifiers */
- ot->name= "Free Cloth Bake";
- ot->idname= "PTCACHE_OT_free_bake_cloth";
+ ot->name= "Free Physics Bake";
+ ot->idname= "PTCACHE_OT_free_bake";
/* api callbacks */
- ot->exec= ptcache_free_bake_cloth_exec;
- ot->poll= ptcache_bake_cloth_poll;
+ ot->exec= ptcache_free_bake_exec;
+ ot->poll= ptcache_bake_all_poll;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
}
-static int ptcache_bake_from_cloth_cache_exec(bContext *C, wmOperator *op)
-{
- Object *ob= CTX_data_active_object(C);
- ClothModifierData *clmd = (ClothModifierData *)modifiers_findByType(ob, eModifierType_Cloth);
- PTCacheID pid;
-
- BKE_ptcache_id_from_cloth(&pid, ob, clmd);
- pid.cache->flag |= PTCACHE_BAKED;
-
- return OPERATOR_FINISHED;
-}
-void PTCACHE_OT_bake_from_cloth_cache(wmOperatorType *ot)
+void PTCACHE_OT_bake_from_cache(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Bake From Cache";
- ot->idname= "PTCACHE_OT_bake_from_cloth_cache";
+ ot->idname= "PTCACHE_OT_bake_from_cache";
/* api callbacks */
- ot->exec= ptcache_bake_from_cloth_cache_exec;
- ot->poll= ptcache_bake_cloth_poll;
+ ot->exec= ptcache_bake_from_cache_exec;
+ ot->poll= ptcache_bake_all_poll;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
}
-/**************************** particles **********************************/
-static int ptcache_bake_particle_system_poll(bContext *C)
+static int ptcache_add_new_exec(bContext *C, wmOperator *op)
{
- Scene *scene= CTX_data_scene(C);
- Object *ob= CTX_data_active_object(C);
+ Scene *scene = CTX_data_scene(C);
+ PointerRNA ptr= CTX_data_pointer_get_type(C, "PointCache", &RNA_PointCache);
+ Object *ob= ptr.id.data;
+ PointCache *cache= ptr.data;
+ PTCacheID *pid;
+ ListBase pidlist;
- if(!scene || !ob || ob->id.lib)
- return 0;
+ BKE_ptcache_ids_from_object(&pidlist, ob);
- return (ob->particlesystem.first != NULL);
-}
-
-static int ptcache_bake_particle_system_exec(bContext *C, wmOperator *op)
-{
- Scene *scene= CTX_data_scene(C);
- Object *ob= CTX_data_active_object(C);
- ParticleSystem *psys =psys_get_current(ob);
- PTCacheID pid;
- PTCacheBaker baker;
-
- BKE_ptcache_id_from_particles(&pid, ob, psys);
-
- baker.scene = scene;
- baker.pid = &pid;
- baker.bake = RNA_boolean_get(op->ptr, "bake");
- baker.render = 0;
- baker.anim_init = 0;
- baker.quick_step = 1;
- baker.break_test = cache_break_test;
- baker.break_data = NULL;
- baker.progressbar = (void (*)(void *, int))WM_timecursor;
- baker.progresscontext = CTX_wm_window(C);
+ for(pid=pidlist.first; pid; pid=pid->next) {
+ if(pid->cache == cache) {
+ *(pid->cache_ptr) = BKE_ptcache_add(pid->ptcaches);
+ break;
+ }
+ }
- BKE_ptcache_make_cache(&baker);
+ BLI_freelistN(&pidlist);
WM_event_add_notifier(C, NC_SCENE|ND_FRAME, scene);
return OPERATOR_FINISHED;
}
-static int ptcache_free_bake_particle_system_exec(bContext *C, wmOperator *op)
+static int ptcache_remove_exec(bContext *C, wmOperator *op)
{
- Scene *scene= CTX_data_scene(C);
- Object *ob= CTX_data_active_object(C);
- ParticleSystem *psys= psys_get_current(ob);
- PTCacheID pid;
+ Scene *scene = CTX_data_scene(C);
+ PointerRNA ptr= CTX_data_pointer_get_type(C, "PointCache", &RNA_PointCache);
+ Object *ob= ptr.id.data;
+ PointCache *cache= ptr.data;
+ PTCacheID *pid;
+ ListBase pidlist;
- BKE_ptcache_id_from_particles(&pid, ob, psys);
- psys->pointcache->flag &= ~PTCACHE_BAKED;
+ BKE_ptcache_ids_from_object(&pidlist, ob);
+
+ for(pid=pidlist.first; pid; pid=pid->next) {
+ if(pid->cache == cache) {
+ if(pid->ptcaches->first == pid->ptcaches->last)
+ continue; /* don't delete last cache */
- WM_event_add_notifier(C, NC_SCENE|ND_FRAME, scene);
+ BLI_remlink(pid->ptcaches, pid->cache);
+ BKE_ptcache_free(pid->cache);
+ *(pid->cache_ptr) = pid->ptcaches->first;
- return OPERATOR_FINISHED;
-}
-void PTCACHE_OT_cache_particle_system(wmOperatorType *ot)
-{
- /* identifiers */
- ot->name= "Bake Particles";
- ot->idname= "PTCACHE_OT_cache_particle_system";
-
- /* api callbacks */
- ot->exec= ptcache_bake_particle_system_exec;
- ot->poll= ptcache_bake_particle_system_poll;
+ break;
+ }
+ }
- /* flags */
- ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+ BLI_freelistN(&pidlist);
- RNA_def_boolean(ot->srna, "bake", 0, "Bake", "");
+ return OPERATOR_FINISHED;
}
-void PTCACHE_OT_free_bake_particle_system(wmOperatorType *ot)
+void PTCACHE_OT_add_new(wmOperatorType *ot)
{
/* identifiers */
- ot->name= "Free Particles Bake";
- ot->idname= "PTCACHE_OT_free_bake_particle_system";
+ ot->name= "Add new cache";
+ ot->idname= "PTCACHE_OT_add_new";
/* api callbacks */
- ot->exec= ptcache_free_bake_particle_system_exec;
- ot->poll= ptcache_bake_particle_system_poll;
+ ot->exec= ptcache_add_new_exec;
+ ot->poll= ptcache_bake_all_poll;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
}
-static int ptcache_bake_from_particles_cache_exec(bContext *C, wmOperator *op)
-{
- Object *ob= CTX_data_active_object(C);
- ParticleSystem *psys= psys_get_current(ob);
- PTCacheID pid;
-
- BKE_ptcache_id_from_particles(&pid, ob, psys);
- psys->pointcache->flag |= PTCACHE_BAKED;
-
- return OPERATOR_FINISHED;
-}
-void PTCACHE_OT_bake_from_particles_cache(wmOperatorType *ot)
+void PTCACHE_OT_remove(wmOperatorType *ot)
{
/* identifiers */
- ot->name= "Bake From Cache";
- ot->idname= "PTCACHE_OT_bake_from_particles_cache";
+ ot->name= "Delete current cache";
+ ot->idname= "PTCACHE_OT_remove";
/* api callbacks */
- ot->exec= ptcache_bake_from_particles_cache_exec;
- ot->poll= ptcache_bake_particle_system_poll;
+ ot->exec= ptcache_remove_exec;
+ ot->poll= ptcache_bake_all_poll;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
}
-
/**************************** registration **********************************/
void ED_operatortypes_pointcache(void)
{
WM_operatortype_append(PTCACHE_OT_bake_all);
WM_operatortype_append(PTCACHE_OT_free_bake_all);
- WM_operatortype_append(PTCACHE_OT_cache_particle_system);
- WM_operatortype_append(PTCACHE_OT_free_bake_particle_system);
- WM_operatortype_append(PTCACHE_OT_bake_from_particles_cache);
- WM_operatortype_append(PTCACHE_OT_cache_cloth);
- WM_operatortype_append(PTCACHE_OT_free_bake_cloth);
- WM_operatortype_append(PTCACHE_OT_bake_from_cloth_cache);
- WM_operatortype_append(PTCACHE_OT_cache_softbody);
- WM_operatortype_append(PTCACHE_OT_free_bake_softbody);
- WM_operatortype_append(PTCACHE_OT_bake_from_softbody_cache);
+ WM_operatortype_append(PTCACHE_OT_bake);
+ WM_operatortype_append(PTCACHE_OT_free_bake);
+ WM_operatortype_append(PTCACHE_OT_bake_from_cache);
+ WM_operatortype_append(PTCACHE_OT_add_new);
+ WM_operatortype_append(PTCACHE_OT_remove);
}
//void ED_keymap_pointcache(wmWindowManager *wm)