diff options
author | Daniel Genrich <daniel.genrich@gmx.net> | 2009-08-25 22:41:36 +0400 |
---|---|---|
committer | Daniel Genrich <daniel.genrich@gmx.net> | 2009-08-25 22:41:36 +0400 |
commit | 1d1e8595f23579e940ca403023305f2499c39a54 (patch) | |
tree | 5de682ad2c8c45b67626287b0f07fdf721f207aa /source/blender/blenkernel | |
parent | 0ff90bb2586e9e50e962106b6bcafa97484c31ca (diff) |
Pointcache:
*introducing unique ID's following brechts hint from ML
Enhancements resulting from this:
* multiple caches per modifier stack position
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_object.h | 5 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/object.c | 65 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/pointcache.c | 25 |
3 files changed, 80 insertions, 15 deletions
diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h index a57529ccf75..68173a1b5c4 100644 --- a/source/blender/blenkernel/BKE_object.h +++ b/source/blender/blenkernel/BKE_object.h @@ -115,6 +115,11 @@ void object_handle_update(struct Scene *scene, struct Object *ob); float give_timeoffset(struct Object *ob); int give_obdata_texspace(struct Object *ob, int **texflag, float **loc, float **size, float **rot); + +int object_insert_pc(struct Object *ob); +// void object_delete_pc(struct Object *ob, int index); + + #ifdef __cplusplus } #endif diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index 0e45aedc3ed..8f5ff988745 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -307,6 +307,8 @@ void free_object(Object *ob) if(ob->gpulamp.first) GPU_lamp_free(ob); free_sculptsession(&ob->sculpt); + + if(ob->pc_ids.first) BLI_freelistN(&ob->pc_ids); } static void unlink_object__unlinkModifierLinks(void *userData, Object *ob, Object **obpoin) @@ -1016,6 +1018,8 @@ Object *add_only_object(int type, char *name) ob->fluidsimFlag = 0; ob->fluidsimSettings = NULL; + ob->pc_ids.first = ob->pc_ids.last = NULL; + return ob; } @@ -1268,7 +1272,8 @@ Object *copy_object(Object *ob) obn->derivedFinal = NULL; obn->gpulamp.first = obn->gpulamp.last = NULL; - + obn->pc_ids.first = obn->pc_ids.last = NULL; + return obn; } @@ -2535,3 +2540,61 @@ int ray_hit_boundbox(struct BoundBox *bb, float ray_start[3], float ray_normal[3 return result; } + +static int pc_cmp(void *a, void *b) +{ + LinkData *ad = a, *bd = b; + if((int)ad->data > (int)bd->data) + return 1; + else return 0; +} + +int object_insert_pc(Object *ob) +{ + LinkData *link = NULL; + int i = 0; + + BLI_sortlist(&ob->pc_ids, pc_cmp); + + for(link=ob->pc_ids.first, i = 0; link; link=link->next, i++) + { + int index =(int)link->data; + + if(i < index) + break; + } + + link = MEM_callocN(sizeof(LinkData), "PCLink"); + link->data = (void *)i; + BLI_addtail(&ob->pc_ids, link); + + return i; +} + +static int pc_findindex(ListBase *listbase, int index) +{ + LinkData *link= NULL; + int number= 0; + + if (listbase == NULL) return -1; + + link= listbase->first; + while (link) { + if ((int)link->data == index) + return number; + + number++; + link= link->next; + } + + return -1; +} + +#if 0 +void object_delete_pc(Object *ob, int index) +{ + int list_index = pc_findindex(&ob->pc_ids, index); + LinkData *link = BLI_findlink(&ob->pc_ids, list_index); + BLI_freelinkN(&ob->pc_ids, link); +} +#endif
\ No newline at end of file diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c index ca27bde039b..75b49817812 100644 --- a/source/blender/blenkernel/intern/pointcache.c +++ b/source/blender/blenkernel/intern/pointcache.c @@ -391,8 +391,6 @@ static int ptcache_totpoint_cloth(void *cloth_v) void BKE_ptcache_id_from_softbody(PTCacheID *pid, Object *ob, SoftBody *sb) { ParticleSystemModifierData *psmd; - ModifierData *md; - int a; memset(pid, 0, sizeof(PTCacheID)); @@ -418,16 +416,10 @@ void BKE_ptcache_id_from_softbody(PTCacheID *pid, Object *ob, SoftBody *sb) if(sb->particles) { psmd= psys_get_modifier(ob, sb->particles); - pid->stack_index= modifiers_indexInObject(ob, (ModifierData*)psmd); - } - else { - for(a=0, md=ob->modifiers.first; md; md=md->next, a++) { - if(md->type == eModifierType_Softbody) { - pid->stack_index = a; - break; - } - } + // pid->stack_index= modifiers_indexInObject(ob, (ModifierData*)psmd); XXX TODO - get other index DG } + else + pid->stack_index = pid->cache->index; } void BKE_ptcache_id_from_particles(PTCacheID *pid, Object *ob, ParticleSystem *psys) @@ -439,7 +431,7 @@ void BKE_ptcache_id_from_particles(PTCacheID *pid, Object *ob, ParticleSystem *p pid->ob= ob; pid->calldata= psys; pid->type= PTCACHE_TYPE_PARTICLES; - pid->stack_index= modifiers_indexInObject(ob, (ModifierData *)psmd); + pid->stack_index= psys->pointcache->index; pid->cache= psys->pointcache; pid->cache_ptr= &psys->pointcache; pid->ptcaches= &psys->ptcaches; @@ -728,7 +720,7 @@ void BKE_ptcache_id_from_smoke(PTCacheID *pid, struct Object *ob, struct SmokeMo pid->calldata= smd; pid->type= PTCACHE_TYPE_SMOKE_DOMAIN; - pid->stack_index= modifiers_indexInObject(ob, (ModifierData *)smd); + pid->stack_index= sds->point_cache->index; pid->cache= sds->point_cache; pid->cache_ptr= &sds->point_cache; @@ -758,7 +750,7 @@ void BKE_ptcache_id_from_cloth(PTCacheID *pid, Object *ob, ClothModifierData *cl pid->ob= ob; pid->calldata= clmd; pid->type= PTCACHE_TYPE_CLOTH; - pid->stack_index= modifiers_indexInObject(ob, (ModifierData *)clmd); + pid->stack_index= clmd->point_cache->index; pid->cache= clmd->point_cache; pid->cache_ptr= &clmd->point_cache; pid->ptcaches= &clmd->ptcaches; @@ -901,6 +893,10 @@ static int BKE_ptcache_id_filename(PTCacheID *pid, char *filename, int cfra, sho } if (do_ext) { + + if(pid->cache->index < 0) + pid->cache->index = pid->stack_index = object_insert_pc(pid->ob); + if(pid->cache->flag & PTCACHE_EXTERNAL) { if(pid->cache->index >= 0) snprintf(newname, MAX_PTCACHE_FILE, "_%06d_%02d"PTCACHE_EXT, cfra, pid->stack_index); /* always 6 chars */ @@ -1952,6 +1948,7 @@ PointCache *BKE_ptcache_add(ListBase *ptcaches) cache->startframe= 1; cache->endframe= 250; cache->step= 10; + cache->index = -1; BLI_addtail(ptcaches, cache); |