Pointcache:
authorDaniel Genrich <daniel.genrich@gmx.net>
Tue, 25 Aug 2009 18:41:36 +0000 (18:41 +0000)
committerDaniel Genrich <daniel.genrich@gmx.net>
Tue, 25 Aug 2009 18:41:36 +0000 (18:41 +0000)
*introducing unique ID's following brechts hint from ML

Enhancements resulting from this:
* multiple caches per modifier stack position

source/blender/blenkernel/BKE_object.h
source/blender/blenkernel/intern/object.c
source/blender/blenkernel/intern/pointcache.c
source/blender/blenloader/intern/readfile.c
source/blender/editors/space_view3d/drawvolume.c
source/blender/gpu/intern/gpu_extensions.c
source/blender/makesdna/DNA_object_types.h

index a57529ccf75f917836e0ed38f94be3e058b073d2..68173a1b5c4d1693270a09764183c68f696876e7 100644 (file)
@@ -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
index 0e45aedc3ed823d58d97499b03cd77c10b8a5c26..8f5ff988745a05ae856b48423a0dacae7e2ecdbf 100644 (file)
@@ -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
index ca27bde039b6c95420fce471098b0de3f9d40754..75b49817812ecbc997d71c573f4da4c606d75049 100644 (file)
@@ -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);
 
index 920e202520ed0442796a23c1cf5e4a25e56e3c51..26e3d5bf6f1138816221a090e6707c54c565148b 100644 (file)
@@ -3993,6 +3993,7 @@ static void direct_link_object(FileData *fd, Object *ob)
        ob->derivedDeform= NULL;
        ob->derivedFinal= NULL;
        ob->gpulamp.first= ob->gpulamp.last= NULL;
+       link_list(fd, &ob->pc_ids);
 
        if(ob->sculpt)
                ob->sculpt= MEM_callocN(sizeof(SculptSession), "reload sculpt session");
index 5e0ffb9ba48b05934336dedf3bae37bb4aebc751..f4242c70139fa4f0564c1633e2cfdb33e4fa8346 100644 (file)
@@ -236,8 +236,7 @@ void draw_volume(Scene *scene, ARegion *ar, View3D *v3d, Base *base, GPUTexture
 
        GPU_texture_bind(tex, 0);
 
-       if (!GLEW_ARB_texture_non_power_of_two) 
-       {
+       if (!GLEW_ARB_texture_non_power_of_two) {
                cor[0] = (float)res[0]/(float)larger_pow2(res[0]);
                cor[1] = (float)res[1]/(float)larger_pow2(res[1]);
                cor[2] = (float)res[2]/(float)larger_pow2(res[2]);
index 36936a9fcb03edda174e7bbb61ffe23def873428..850b46dc28cd612acc3fe63c2bf1b12a4ddc1ead 100644 (file)
@@ -337,8 +337,7 @@ GPUTexture *GPU_texture_create_3D(int w, int h, int depth, float *fpixels)
                return NULL;
        }
 
-       if (!GLEW_ARB_texture_non_power_of_two) 
-       {
+       if (!GLEW_ARB_texture_non_power_of_two) {
                tex->w = larger_pow2(tex->w);
                tex->h = larger_pow2(tex->h);
                tex->depth = larger_pow2(tex->depth);
index be43ae7f99dcee85cac0a78e8822b3f80bbff277..25fdf615adbea46fc886c31abb3d6c84b440d00e 100644 (file)
@@ -237,6 +237,7 @@ typedef struct Object {
        int pad2;
 
        ListBase gpulamp;               /* runtime, for lamps only */
+       ListBase pc_ids;
 } Object;
 
 /* Warning, this is not used anymore because hooks are now modifiers */