- Make dupliverts inside a dupligroup render and draw as instances.
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Fri, 4 Jan 2008 17:48:07 +0000 (17:48 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Fri, 4 Jan 2008 17:48:07 +0000 (17:48 +0000)
- Possible fix for a dupli render memory leak, but i'm not sure.

source/blender/blenkernel/BKE_anim.h
source/blender/blenkernel/intern/anim.c
source/blender/render/intern/source/convertblender.c
source/blender/render/intern/source/renderdatabase.c
source/blender/src/drawview.c

index c7808331d7e484e1cb3fd6ff2f92f71479769f07..c3e978a5a9a404fbc0aa01056415bbb9f6ea69e3 100644 (file)
@@ -44,7 +44,7 @@ typedef struct DupliObject {
        struct DupliObject *next, *prev;
        struct Object *ob;
        unsigned int origlay;
-       int index, no_draw;
+       int index, no_draw, type;
        float mat[4][4], omat[4][4];
 } DupliObject;
 
index 0b733f9c0685331d4aade2ec73dfa3673a64967a..de7d9c007fcdbec0a2aafa2470aa8ce320400410 100644 (file)
@@ -284,7 +284,7 @@ int where_on_path(Object *ob, float ctime, float *vec, float *dir)  /* returns OK
 
 /* ****************** DUPLICATOR ************** */
 
-static DupliObject *new_dupli_object(ListBase *lb, Object *ob, float mat[][4], int lay, int index)
+static DupliObject *new_dupli_object(ListBase *lb, Object *ob, float mat[][4], int lay, int index, int type)
 {
        DupliObject *dob= MEM_callocN(sizeof(DupliObject), "dupliobject");
        
@@ -294,6 +294,7 @@ static DupliObject *new_dupli_object(ListBase *lb, Object *ob, float mat[][4], i
        Mat4CpyMat4(dob->omat, ob->obmat);
        dob->origlay= ob->lay;
        dob->index= index;
+       dob->type= type;
        ob->lay= lay;
        
        return dob;
@@ -321,7 +322,7 @@ static void group_duplilist(ListBase *lb, Object *ob, int level)
                if(go->ob!=ob) {
                        
                        Mat4MulMat4(mat, go->ob->obmat, ob->obmat);
-                       dob= new_dupli_object(lb, go->ob, mat, ob->lay, 0);
+                       dob= new_dupli_object(lb, go->ob, mat, ob->lay, 0, OB_DUPLIGROUP);
                        dob->no_draw= (dob->origlay & group->layer)==0;
                        
                        if(go->ob->transflag & OB_DUPLI) {
@@ -360,7 +361,7 @@ static void frames_duplilist(ListBase *lb, Object *ob, int level)
                if(ok) {
                        do_ob_ipo(ob);
                        where_is_object_time(ob, (float)G.scene->r.cfra);
-                       new_dupli_object(lb, ob, ob->obmat, ob->lay, G.scene->r.cfra);
+                       new_dupli_object(lb, ob, ob->obmat, ob->lay, G.scene->r.cfra, OB_DUPLIFRAMES);
                }
        }
 
@@ -405,7 +406,7 @@ static void vertex_dupli__mapFunc(void *userData, int index, float *co, float *n
                Mat4CpyMat4(tmat, obmat);
                Mat4MulMat43(obmat, tmat, mat);
        }
-       new_dupli_object(vdd->lb, vdd->ob, obmat, vdd->par->lay, index);
+       new_dupli_object(vdd->lb, vdd->ob, obmat, vdd->par->lay, index, OB_DUPLIVERTS);
        
        if(vdd->ob->transflag & OB_DUPLI) {
                float tmpmat[4][4];
@@ -631,7 +632,7 @@ static void face_duplilist(ListBase *lb, ID *id, Object *par, float (*par_space_
                                                Mat4CpyMat4(tmat, obmat);
                                                Mat4MulMat43(obmat, tmat, mat);
                                                
-                                               new_dupli_object(lb, ob, obmat, lay, a);
+                                               new_dupli_object(lb, ob, obmat, lay, a, OB_DUPLIFACES);
                                                
                                                if(ob->transflag & OB_DUPLI) {
                                                        float tmpmat[4][4];
@@ -772,7 +773,7 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Object *par, ParticleSy
 
                                                VECADD(tmat[3], go->ob->obmat[3], state.co);
 
-                                               new_dupli_object(lb, go->ob, tmat, par->lay, counter);
+                                               new_dupli_object(lb, go->ob, tmat, par->lay, counter, OB_DUPLIPARTS);
                                        }
                                }
                                else {
@@ -789,7 +790,7 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Object *par, ParticleSy
 
                                        VECCOPY(tmat[3], state.co);
 
-                                       new_dupli_object(lb, ob, tmat, par->lay, counter);
+                                       new_dupli_object(lb, ob, tmat, par->lay, counter, OB_DUPLIPARTS);
                                }
                        }
                }
@@ -867,7 +868,7 @@ static void font_duplilist(ListBase *lb, Object *par, int level)
                        Mat4CpyMat4(obmat, par->obmat);
                        VECCOPY(obmat[3], vec);
                        
-                       new_dupli_object(lb, ob, obmat, par->lay, a);
+                       new_dupli_object(lb, ob, obmat, par->lay, a, OB_DUPLIVERTS);
                }
                
        }
index 5fd90c7f88ed5ecef137a8c81fe424f29237700e..47b9a2a04271ab8304ba8fe0e14279e60b9f6c22 100644 (file)
@@ -4067,10 +4067,10 @@ static int allow_render_object(Object *ob, int nolamps, int onlyselected, Object
        return 1;
 }
 
-static int allow_render_dupli_instance(Render *re, Object *ob, Object *obd)
+static int allow_render_dupli_instance(Render *re, DupliObject *dob, Object *obd)
 {
        return (render_object_type(obd->type) &&
-               (!(ob->transflag & OB_DUPLIGROUP)) &&
+               (!(dob->type == OB_DUPLIGROUP)) &&
                !(re->r.mode & R_RADIO));
 }
 
@@ -4127,7 +4127,7 @@ static void database_init_objects(Render *re, unsigned int lay, int nolamps, int
                                        if(!allow_render_object(obd, nolamps, onlyselected, actob))
                                                continue;
 
-                                       if(allow_render_dupli_instance(re, ob, obd)) {
+                                       if(allow_render_dupli_instance(re, dob, obd)) {
                                                ParticleSystem *psys;
                                                int psysindex;
                                                float imat[4][4], mat[4][4];
index 79c87252fc2354c861863684e8c0f1f74e3c16d8..059a72507c56128a3c075331dcaefebce502b07e 100644 (file)
@@ -822,14 +822,11 @@ void free_renderdata_tables(Render *re)
                re->totinstance= 0;
                re->instancetable.first= re->instancetable.last= NULL;
        }
-       else {
-               BLI_freelistN(&re->instancetable);
 
-               if(re->objecthash) {
-                       BLI_ghash_free(re->objecthash, NULL, NULL);
-                       re->objecthash= NULL;
-               }
-       }
+       if(re->objecthash) {
+               BLI_ghash_free(re->objecthash, NULL, NULL);
+               re->objecthash= NULL;
+       }
 
        if(re->sortedhalos) {
                MEM_freeN(re->sortedhalos);
@@ -843,6 +840,7 @@ void free_renderdata_tables(Render *re)
 
        BLI_freelistN(&re->customdata_names);
        BLI_freelistN(&re->objecttable);
+       BLI_freelistN(&re->instancetable);
 }
 
 /* ------------------------------------------------------------------------ */
index 8fb5ba6cf2af6e06a51faa3b556c3e485cfaed09..663227233a4651c45602460e451f207d15560a3a 100644 (file)
@@ -2657,10 +2657,6 @@ static void draw_dupli_objects_color(View3D *v3d, Base *base, int color)
        
        if (base->object->restrictflag & OB_RESTRICT_VIEW) return;
        
-       /* test if we can do a displist */
-       if(base->object->transflag & OB_DUPLIGROUP)
-               use_displist= 0;
-       
        tbase.flag= OB_FROMDUPLI|base->flag;
        lb= object_duplilist(G.scene, base->object);
 
@@ -2689,7 +2685,7 @@ static void draw_dupli_objects_color(View3D *v3d, Base *base, int color)
                        if(use_displist == -1) {
                                
                                /* lamp drawing messes with matrices, could be handled smarter... but this works */
-                               if(dob->ob->type==OB_LAMP)
+                               if(dob->ob->type==OB_LAMP || dob->type==OB_DUPLIGROUP)
                                        use_displist= 0;
                                else {
                                        /* disable boundbox check for list creation */