Wrap runtime curve members into own structure
authorSergey Sharybin <sergey.vfx@gmail.com>
Wed, 3 Jul 2013 12:32:29 +0000 (12:32 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Wed, 3 Jul 2013 12:32:29 +0000 (12:32 +0000)
This allows easier assignment on file loading,
keeps curve-specific runtime data grouped and
saves couple of bytes in Object for non-curve
types.

23 files changed:
source/blender/blenkernel/BKE_curve.h
source/blender/blenkernel/BKE_object.h
source/blender/blenkernel/intern/anim.c
source/blender/blenkernel/intern/armature.c
source/blender/blenkernel/intern/cdderivedmesh.c
source/blender/blenkernel/intern/constraint.c
source/blender/blenkernel/intern/curve.c
source/blender/blenkernel/intern/displist.c
source/blender/blenkernel/intern/effect.c
source/blender/blenkernel/intern/font.c
source/blender/blenkernel/intern/lattice.c
source/blender/blenkernel/intern/material.c
source/blender/blenkernel/intern/mball.c
source/blender/blenkernel/intern/mesh.c
source/blender/blenkernel/intern/object.c
source/blender/blenloader/intern/readfile.c
source/blender/editors/object/object_add.c
source/blender/editors/space_info/info_stats.c
source/blender/editors/space_view3d/drawobject.c
source/blender/editors/space_view3d/view3d_iterators.c
source/blender/makesdna/DNA_object_types.h
source/blender/makesrna/intern/rna_main_api.c
source/blender/modifiers/intern/MOD_array.c

index 6c5bbbd487ea67557d412b68cb73962059e10ab2..cf0cbb4ef5857d44adfe27a7870d0cafdd860f55 100644 (file)
@@ -42,6 +42,13 @@ struct Main;
 struct Nurb;
 struct Object;
 struct Scene;
+struct Path;
+
+typedef struct CurveCache {
+       ListBase disp;
+       ListBase bev;
+       struct Path *path;
+} CurveCache;
 
 #define KNOTSU(nu)      ( (nu)->orderu + (nu)->pntsu + (((nu)->flagu & CU_NURB_CYCLIC) ? ((nu)->orderu - 1) : 0) )
 #define KNOTSV(nu)      ( (nu)->orderv + (nu)->pntsv + (((nu)->flagv & CU_NURB_CYCLIC) ? ((nu)->orderv - 1) : 0) )
index 463720fb8cfdd8ed25785d6b038502656ed963d3..0f390e618712cf1f7068135fc21d7f3e8c9d5a82 100644 (file)
@@ -60,6 +60,7 @@ void BKE_object_copy_softbody(struct Object *obn, struct Object *ob);
 void BKE_object_free_particlesystems(struct Object *ob);
 void BKE_object_free_softbody(struct Object *ob);
 void BKE_object_free_bulletsoftbody(struct Object *ob);
+void BKE_object_free_curve_cache(struct Object *ob);
 void BKE_object_update_base_layer(struct Scene *scene, struct Object *ob);
 
 void BKE_object_free(struct Object *ob);
index 8a1eaa66664cd153695e20f697f4e09b65abceb9..23655f04ccc4bf51e8bc66f36c1897bf97cbb21d 100644 (file)
@@ -509,11 +509,11 @@ void calc_curvepath(Object *ob)
        }
        cu = ob->data;
 
-       if (ob->path) free_path(ob->path);
-       ob->path = NULL;
+       if (ob->curve_cache->path) free_path(ob->curve_cache->path);
+       ob->curve_cache->path = NULL;
        
        /* weak! can only use first curve */
-       bl = ob->bev.first;
+       bl = ob->curve_cache->bev.first;
        if (bl == NULL || !bl->nr) {
                return;
        }
@@ -521,7 +521,7 @@ void calc_curvepath(Object *ob)
        nurbs = BKE_curve_nurbs_get(cu);
        nu = nurbs->first;
 
-       ob->path = path = MEM_callocN(sizeof(Path), "calc_curvepath");
+       ob->curve_cache->path = path = MEM_callocN(sizeof(Path), "calc_curvepath");
        
        /* if POLY: last vertice != first vertice */
        cycl = (bl->poly != -1);
@@ -630,15 +630,15 @@ int where_on_path(Object *ob, float ctime, float vec[4], float dir[3], float qua
 
        if (ob == NULL || ob->type != OB_CURVE) return 0;
        cu = ob->data;
-       if (ob->path == NULL || ob->path->data == NULL) {
+       if (ob->curve_cache == NULL || ob->curve_cache->path == NULL || ob->curve_cache->path->data == NULL) {
                printf("no path!\n");
                return 0;
        }
-       path = ob->path;
+       path = ob->curve_cache->path;
        pp = path->data;
        
        /* test for cyclic */
-       bl = ob->bev.first;
+       bl = ob->curve_cache->bev.first;
        if (!bl) return 0;
        if (!bl->nr) return 0;
        if (bl->poly > -1) cycl = 1;
index fe62127dff50ab5116eb13f09905e237459b57bc..196d4dfb2564df9a59a38746e6c5713486e3c916 100644 (file)
@@ -1821,11 +1821,11 @@ static void splineik_init_tree_from_pchan(Scene *scene, Object *UNUSED(ob), bPos
                 */
 
                /* only happens on reload file, but violates depsgraph still... fix! */
-               if (ELEM(NULL, ikData->tar->path, ikData->tar->path->data)) {
+               if (ELEM3(NULL,  ikData->tar->curve_cache, ikData->tar->curve_cache->path, ikData->tar->curve_cache->path->data)) {
                        BKE_displist_make_curveTypes(scene, ikData->tar, 0);
                        
                        /* path building may fail in EditMode after removing verts [#33268]*/
-                       if (ELEM(NULL, ikData->tar->path, ikData->tar->path->data)) {
+                       if (ELEM(NULL, ikData->tar->curve_cache->path, ikData->tar->curve_cache->path->data)) {
                                /* BLI_assert(cu->path != NULL); */
                                return;
                        }
@@ -1901,7 +1901,7 @@ static void splineik_init_tree_from_pchan(Scene *scene, Object *UNUSED(ob), bPos
 
                /* get the current length of the curve */
                /* NOTE: this is assumed to be correct even after the curve was resized */
-               splineLen = ikData->tar->path->totdist;
+               splineLen = ikData->tar->curve_cache->path->totdist;
 
                /* calculate the scale factor to multiply all the path values by so that the
                 * bone chain retains its current length, such that
index 7f6dc680a7468172e4150a2f3781c5e3e029fe7e..1d51f10441c7cb2db12ab88300544a79fea19ee1 100644 (file)
@@ -1818,7 +1818,13 @@ DerivedMesh *CDDM_from_mesh(Mesh *mesh, Object *UNUSED(ob))
 
 DerivedMesh *CDDM_from_curve(Object *ob)
 {
-       return CDDM_from_curve_displist(ob, &ob->disp);
+       ListBase disp = {NULL};
+
+       if (ob->curve_cache) {
+               disp = ob->curve_cache->disp;
+       }
+
+       return CDDM_from_curve_displist(ob, &disp);
 }
 
 DerivedMesh *CDDM_from_curve_displist(Object *ob, ListBase *dispbase)
index 6b8cd19639ec8ba32a4604c8fbfb1359f2521b2c..7ead1da02d8ebbef1922367fc81a6dca1189cdde 100644 (file)
@@ -69,6 +69,7 @@
 #include "BKE_bvhutils.h"
 #include "BKE_camera.h"
 #include "BKE_constraint.h"
+#include "BKE_curve.h"
 #include "BKE_displist.h"
 #include "BKE_deform.h"
 #include "BKE_DerivedMesh.h"    /* for geometry targets */
@@ -449,7 +450,7 @@ static void contarget_get_lattice_mat(Object *ob, const char *substring, float m
 {
        Lattice *lt = (Lattice *)ob->data;
        
-       DispList *dl = BKE_displist_find(&ob->disp, DL_VERTS);
+       DispList *dl = ob->curve_cache ? BKE_displist_find(&ob->curve_cache->disp, DL_VERTS) : NULL;
        float *co = dl ? dl->verts : NULL;
        BPoint *bp = lt->def;
        
@@ -1164,10 +1165,10 @@ static void followpath_get_tarmat(bConstraint *con, bConstraintOb *cob, bConstra
                 */
                
                /* only happens on reload file, but violates depsgraph still... fix! */
-               if (ct->tar->path == NULL || ct->tar->path->data == NULL)
+               if (ct->tar->curve_cache == NULL || ct->tar->curve_cache->path == NULL || ct->tar->curve_cache->path->data == NULL)
                        BKE_displist_make_curveTypes(cob->scene, ct->tar, 0);
                
-               if (ct->tar->path && ct->tar->path->data) {
+               if (ct->tar->curve_cache->path && ct->tar->curve_cache->path->data) {
                        float quat[4];
                        if ((data->followflag & FOLLOWPATH_STATIC) == 0) {
                                /* animated position along curve depending on time */
@@ -1935,7 +1936,7 @@ static void pycon_get_tarmat(bConstraint *con, bConstraintOb *cob, bConstraintTa
                /* special exception for curves - depsgraph issues */
                if (ct->tar->type == OB_CURVE) {
                        /* this check is to make sure curve objects get updated on file load correctly.*/
-                       if (ct->tar->path == NULL || ct->tar->path->data == NULL) /* only happens on reload file, but violates depsgraph still... fix! */
+                       if (ct->tar->curve_cache == NULL || ct->tar->curve_cache->path == NULL || ct->tar->curve_cache->path->data == NULL) /* only happens on reload file, but violates depsgraph still... fix! */
                                BKE_displist_make_curveTypes(cob->scene, ct->tar, 0);
                }
                
@@ -3011,7 +3012,7 @@ static void clampto_get_tarmat(bConstraint *UNUSED(con), bConstraintOb *cob, bCo
                 */
                
                /* only happens on reload file, but violates depsgraph still... fix! */
-               if (ct->tar->path == NULL || ct->tar->path->data == NULL)
+               if (ct->tar->curve_cache == NULL || ct->tar->curve_cache->path == NULL || ct->tar->curve_cache->path->data == NULL)
                        BKE_displist_make_curveTypes(cob->scene, ct->tar, 0);
        }
        
@@ -3041,7 +3042,7 @@ static void clampto_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *tar
                BKE_object_minmax(ct->tar, curveMin, curveMax, TRUE);
                
                /* get targetmatrix */
-               if (data->tar->path && data->tar->path->data) {
+               if (data->tar->curve_cache &&  data->tar->curve_cache->path && data->tar->curve_cache->path->data) {
                        float vec[4], dir[3], totmat[4][4];
                        float curvetime;
                        short clamp_axis;
@@ -3649,7 +3650,7 @@ static void splineik_get_tarmat(bConstraint *UNUSED(con), bConstraintOb *cob, bC
                 */
                
                /* only happens on reload file, but violates depsgraph still... fix! */
-               if (ct->tar->path == NULL || ct->tar->path->data == NULL)
+               if (ct->tar->curve_cache == NULL || ct->tar->curve_cache->path == NULL || ct->tar->curve_cache->path->data == NULL)
                        BKE_displist_make_curveTypes(cob->scene, ct->tar, 0);
        }
        
index ea8f49a319963ba0789639a3dd8fed20e63d615a..2ac735d97e67150f8c735c981552891932fa46ed 100644 (file)
@@ -1419,10 +1419,10 @@ void BKE_curve_bevel_make(Scene *scene, Object *ob, ListBase *disp, int forRende
                                dl = bevdisp.first;
                        }
                        else {
-                               dl = cu->bevobj->disp.first;
+                               dl = cu->bevobj->curve_cache ? cu->bevobj->curve_cache->disp.first : NULL;
                                if (dl == NULL) {
                                        BKE_displist_make_curveTypes(scene, cu->bevobj, 0);
-                                       dl = cu->bevobj->disp.first;
+                                       dl = cu->bevobj->curve_cache->disp.first;
                                }
                        }
 
@@ -2263,14 +2263,14 @@ void BKE_curve_bevelList_make(Object *ob, bool for_render)
        /* this function needs an object, because of tflag and upflag */
        cu = ob->data;
 
-       bev = &ob->bev;
+       bev = &ob->curve_cache->bev;
 
        /* do we need to calculate the radius for each point? */
        /* do_radius = (cu->bevobj || cu->taperobj || (cu->flag & CU_FRONT) || (cu->flag & CU_BACK)) ? 0 : 1; */
 
        /* STEP 1: MAKE POLYS  */
 
-       BLI_freelistN(&(ob->bev));
+       BLI_freelistN(&(ob->curve_cache->bev));
        if (cu->editnurb && ob->type != OB_FONT) {
                ListBase *nurbs = BKE_curve_editNurbs_get(cu);
                nu = nurbs->first;
index 058122c21aa6d8adb53a73527211e4c64e422cab..7a14ed54e53e64532df4a8cc153ef4c289fee78c 100644 (file)
@@ -668,10 +668,10 @@ static float displist_calc_taper(Scene *scene, Object *taperobj, float fac)
        if (taperobj == NULL || taperobj->type != OB_CURVE)
                return 1.0;
 
-       dl = taperobj->disp.first;
+       dl = taperobj->curve_cache ? taperobj->curve_cache->disp.first : NULL;
        if (dl == NULL) {
                BKE_displist_make_curveTypes(scene, taperobj, 0);
-               dl = taperobj->disp.first;
+               dl = taperobj->curve_cache->disp.first;
        }
        if (dl) {
                float minx, dx, *fp;
@@ -713,14 +713,19 @@ void BKE_displist_make_mball(Scene *scene, Object *ob)
        if (!ob || ob->type != OB_MBALL)
                return;
 
-       BKE_displist_free(&(ob->disp));
+       if (ob->curve_cache) {
+               BKE_displist_free(&(ob->curve_cache->disp));
+       }
+       else {
+               ob->curve_cache = MEM_callocN(sizeof(CurveCache), "CurveCache for MBall");
+       }
 
        if (ob->type == OB_MBALL) {
                if (ob == BKE_mball_basis_find(scene, ob)) {
-                       BKE_mball_polygonize(scene, ob, &ob->disp, false);
+                       BKE_mball_polygonize(scene, ob, &ob->curve_cache->disp, false);
                        BKE_mball_texspace_calc(ob);
 
-                       object_deform_mball(ob, &ob->disp);
+                       object_deform_mball(ob, &ob->curve_cache->disp);
                }
 
                boundbox_displist_object(ob);
@@ -1398,10 +1403,10 @@ static void do_makeDispListCurveTypes(Scene *scene, Object *ob, ListBase *dispba
                /* XXX: Temp workaround for depsgraph_mt branch. */
                BLI_lock_thread(LOCK_CUSTOM1);
 
-               BLI_freelistN(&(ob->bev));
+               BLI_freelistN(&(ob->curve_cache->bev));
 
-               if (ob->path) free_path(ob->path);
-               ob->path = NULL;
+               if (ob->curve_cache->path) free_path(ob->curve_cache->path);
+               ob->curve_cache->path = NULL;
 
                if (ob->type == OB_FONT)
                        BKE_vfont_to_curve(G.main, scene, ob, 0);
@@ -1420,7 +1425,7 @@ static void do_makeDispListCurveTypes(Scene *scene, Object *ob, ListBase *dispba
                }
                else {
                        float widfac = cu->width - 1.0f;
-                       BevList *bl = ob->bev.first;
+                       BevList *bl = ob->curve_cache->bev.first;
                        Nurb *nu = nubase->first;
 
                        for (; bl && nu; bl = bl->next, nu = nu->next) {
@@ -1627,9 +1632,14 @@ void BKE_displist_make_curveTypes(Scene *scene, Object *ob, int forOrco)
        if (!ELEM3(ob->type, OB_SURF, OB_CURVE, OB_FONT))
                return;
 
-       BKE_displist_free(&(ob->disp));
-       dispbase = &(ob->disp);
-       BKE_displist_free(dispbase);
+       if (ob->curve_cache) {
+               BKE_displist_free(&(ob->curve_cache->disp));
+       }
+       else {
+               ob->curve_cache = MEM_callocN(sizeof(CurveCache), "CurveCache for curve types");
+       }
+
+       dispbase = &(ob->curve_cache->disp);
 
        do_makeDispListCurveTypes(scene, ob, dispbase, &ob->derivedFinal, 0, forOrco, 0);
 
@@ -1712,7 +1722,7 @@ static void boundbox_displist_object(Object *ob)
                        DM_set_object_boundbox(ob, ob->derivedFinal);
                }
                else {
-                       boundbox_dispbase(ob->bb, &ob->disp);
+                       boundbox_dispbase(ob->bb, &ob->curve_cache->disp);
                }
        }
 }
index 1a2c368a7d46f72d20ed0668733d824a66dbce7d..8d58caf8769134005970a343853e59767d47c1c0 100644 (file)
@@ -67,6 +67,7 @@
 #include "BKE_blender.h"
 #include "BKE_collision.h"
 #include "BKE_constraint.h"
+#include "BKE_curve.h"
 #include "BKE_deform.h"
 #include "BKE_depsgraph.h"
 #include "BKE_displist.h"
@@ -176,10 +177,10 @@ static void precalculate_effector(EffectorCache *eff)
        if (eff->pd->forcefield == PFIELD_GUIDE && eff->ob->type==OB_CURVE) {
                Curve *cu= eff->ob->data;
                if (cu->flag & CU_PATH) {
-                       if (eff->ob->path==NULL || eff->ob->path->data==NULL)
+                       if (eff->ob->curve_cache == NULL || eff->ob->curve_cache->path==NULL || eff->ob->curve_cache->path->data==NULL)
                                BKE_displist_make_curveTypes(eff->scene, eff->ob, 0);
 
-                       if (eff->ob->path && eff->ob->path->data) {
+                       if (eff->ob->curve_cache->path && eff->ob->curve_cache->path->data) {
                                where_on_path(eff->ob, 0.0, eff->guide_loc, eff->guide_dir, NULL, &eff->guide_radius, NULL);
                                mul_m4_v3(eff->ob->obmat, eff->guide_loc);
                                mul_mat3_m4_v3(eff->ob->obmat, eff->guide_dir);
index 24cbe1e19ab44b0bdac9816df80da119b216e61e..60c00f821135f9ff41f3d8e6069a74fff7f622c2 100644 (file)
@@ -819,8 +819,10 @@ makebreak:
                
                cucu->flag |= (CU_PATH + CU_FOLLOW);
                
-               if (cu->textoncurve->path == NULL) BKE_displist_make_curveTypes(scene, cu->textoncurve, 0);
-               if (cu->textoncurve->path) {
+               if (cu->textoncurve->curve_cache == NULL || cu->textoncurve->curve_cache->path == NULL) {
+                       BKE_displist_make_curveTypes(scene, cu->textoncurve, 0);
+               }
+               if (cu->textoncurve->curve_cache->path) {
                        float distfac, imat[4][4], imat3[3][3], cmat[3][3];
                        float minx, maxx, miny, maxy;
                        float timeofs, sizefac;
@@ -845,7 +847,7 @@ makebreak:
                        /* we put the x-coordinaat exact at the curve, the y is rotated */
                        
                        /* length correction */
-                       distfac = sizefac * cu->textoncurve->path->totdist / (maxx - minx);
+                       distfac = sizefac * cu->textoncurve->curve_cache->path->totdist / (maxx - minx);
                        timeofs = 0.0f;
                        
                        if (distfac > 1.0f) {
index abe5a153b9e9e52137a87c4df2ae395d26846a94..30b2970bb2e2ca78e2586a9421fcfa7421e82ab2 100644 (file)
@@ -51,6 +51,7 @@
 #include "BKE_animsys.h"
 #include "BKE_anim.h"
 #include "BKE_cdderivedmesh.h"
+#include "BKE_curve.h"
 #include "BKE_displist.h"
 #include "BKE_global.h"
 #include "BKE_key.h"
@@ -164,7 +165,7 @@ void BKE_lattice_resize(Lattice *lt, int uNew, int vNew, int wNew, Object *ltOb)
                lt->typeu = lt->typev = lt->typew = KEY_LINEAR;
 
                /* prevent using deformed locations */
-               BKE_displist_free(&ltOb->disp);
+               BKE_displist_free(&ltOb->curve_cache->disp);
 
                copy_m4_m4(mat, ltOb->obmat);
                unit_m4(ltOb->obmat);
@@ -311,7 +312,7 @@ void init_latt_deform(Object *oblatt, Object *ob)
        /* we make an array with all differences */
        Lattice *lt = oblatt->data;
        BPoint *bp;
-       DispList *dl = BKE_displist_find(&oblatt->disp, DL_VERTS);
+       DispList *dl = oblatt->curve_cache ? BKE_displist_find(&oblatt->curve_cache->disp, DL_VERTS) : NULL;
        float *co = dl ? dl->verts : NULL;
        float *fp, imat[4][4];
        float fu, fv, fw;
@@ -511,7 +512,7 @@ static int where_on_path_deform(Object *ob, float ctime, float vec[4], float dir
        int cycl = 0;
        
        /* test for cyclic */
-       bl = ob->bev.first;
+       bl = ob->curve_cache->bev.first;
        if (!bl->nr) return 0;
        if (bl->poly > -1) cycl = 1;
 
@@ -526,7 +527,7 @@ static int where_on_path_deform(Object *ob, float ctime, float vec[4], float dir
        if (where_on_path(ob, ctime1, vec, dir, quat, radius, NULL)) {
                
                if (cycl == 0) {
-                       Path *path = ob->path;
+                       Path *path = ob->curve_cache->path;
                        float dvec[3];
                        
                        if (ctime < 0.0f) {
@@ -564,9 +565,9 @@ static int calc_curve_deform(Scene *scene, Object *par, float co[3],
        const int is_neg_axis = (axis > 2);
 
        /* to be sure, mostly after file load */
-       if (par->path == NULL) {
+       if (ELEM(NULL, par->curve_cache, par->curve_cache->path)) {
                BKE_displist_make_curveTypes(scene, par, 0);
-               if (par->path == NULL) return 0;  // happens on append...
+               if (par->curve_cache->path == NULL) return 0;  // happens on append...
        }
        
        /* options */
@@ -575,14 +576,14 @@ static int calc_curve_deform(Scene *scene, Object *par, float co[3],
                if (cu->flag & CU_STRETCH)
                        fac = (-co[index] - cd->dmax[index]) / (cd->dmax[index] - cd->dmin[index]);
                else
-                       fac = -(co[index] - cd->dmax[index]) / (par->path->totdist);
+                       fac = -(co[index] - cd->dmax[index]) / (par->curve_cache->path->totdist);
        }
        else {
                index = axis;
                if (cu->flag & CU_STRETCH)
                        fac = (co[index] - cd->dmin[index]) / (cd->dmax[index] - cd->dmin[index]);
                else
-                       fac = +(co[index] - cd->dmin[index]) / (par->path->totdist);
+                       fac = +(co[index] - cd->dmin[index]) / (par->curve_cache->path->totdist);
        }
        
        if (where_on_path_deform(par, fac, loc, dir, new_quat, &radius)) {  /* returns OK */
@@ -995,7 +996,12 @@ void BKE_lattice_modifiers_calc(Scene *scene, Object *ob)
        float (*vertexCos)[3] = NULL;
        int numVerts, editmode = (lt->editlatt != NULL);
 
-       BKE_displist_free(&ob->disp);
+       if (ob->curve_cache) {
+               BKE_displist_free(&ob->curve_cache->disp);
+       }
+       else {
+               ob->curve_cache = MEM_callocN(sizeof(CurveCache), "CurveCache for lattice");
+       }
 
        for (; md; md = md->next) {
                ModifierTypeInfo *mti = modifierType_getInfo(md->type);
@@ -1021,7 +1027,7 @@ void BKE_lattice_modifiers_calc(Scene *scene, Object *ob)
                dl->nr = numVerts;
                dl->verts = (float *) vertexCos;
                
-               BLI_addtail(&ob->disp, dl);
+               BLI_addtail(&ob->curve_cache->disp, dl);
        }
 }
 
index c8cd65e94773948018984168642b4faecab4da12..017158a9a010583cd64fa7cad209c583a48d6111 100644 (file)
@@ -1275,7 +1275,9 @@ int object_remove_material_slot(Object *ob)
        /* check indices from mesh */
        if (ELEM4(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT)) {
                data_delete_material_index_id((ID *)ob->data, actcol - 1);
-               BKE_displist_free(&ob->disp);
+               if (ob->curve_cache) {
+                       BKE_displist_free(&ob->curve_cache->disp);
+               }
        }
 
        return TRUE;
index f84a6088ee53e875f8a4568931fbc3547dcdf7b7..ffcb7d3e265a2debb4c50f4bd6e2c640b724aa36 100644 (file)
@@ -56,6 +56,7 @@
 
 /*  #include "BKE_object.h" */
 #include "BKE_animsys.h"
+#include "BKE_curve.h"
 #include "BKE_scene.h"
 #include "BKE_library.h"
 #include "BKE_displist.h"
@@ -366,7 +367,7 @@ void BKE_mball_texspace_calc(Object *ob)
        (min)[0] = (min)[1] = (min)[2] = 1.0e30f;
        (max)[0] = (max)[1] = (max)[2] = -1.0e30f;
 
-       dl = ob->disp.first;
+       dl = ob->curve_cache->disp.first;
        while (dl) {
                tot = dl->nr;
                if (tot) do_it = TRUE;
index 4ec86cbac7b3c1e13dce64501c379f91809cbd42..741729ab050473a11cbacc95f04c1c4e6af76d2f 100644 (file)
@@ -1292,7 +1292,13 @@ int BKE_mesh_nurbs_to_mdata(Object *ob, MVert **allvert, int *totvert,
                             MEdge **alledge, int *totedge, MLoop **allloop, MPoly **allpoly,
                             int *totloop, int *totpoly)
 {
-       return BKE_mesh_nurbs_displist_to_mdata(ob, &ob->disp,
+       ListBase disp = {NULL};
+
+       if (ob->curve_cache) {
+               disp = ob->curve_cache->disp;
+       }
+
+       return BKE_mesh_nurbs_displist_to_mdata(ob, &disp,
                                                allvert, totvert,
                                                alledge, totedge,
                                                allloop, allpoly, NULL,
@@ -1638,8 +1644,13 @@ void BKE_mesh_from_nurbs(Object *ob)
 {
        Curve *cu = (Curve *) ob->data;
        bool use_orco_uv = (cu->flag & CU_UV_ORCO) != 0;
+       ListBase disp = {NULL};
+
+       if (ob->curve_cache) {
+               disp = ob->curve_cache->disp;
+       }
 
-       BKE_mesh_from_nurbs_displist(ob, &ob->disp, use_orco_uv);
+       BKE_mesh_from_nurbs_displist(ob, &disp, use_orco_uv);
 }
 
 typedef struct EdgeLink {
index 875217e94dd3a655be4013a9e216450d388dc15f..77e9839293a8bb23111718b1769021a5999353fe 100644 (file)
@@ -170,6 +170,19 @@ void BKE_object_free_bulletsoftbody(Object *ob)
        }
 }
 
+void BKE_object_free_curve_cache(Object *ob)
+{
+       if (ob->curve_cache) {
+               BKE_displist_free(&ob->curve_cache->disp);
+               BLI_freelistN(&ob->curve_cache->bev);
+               if (ob->curve_cache->path) {
+                       free_path(ob->curve_cache->path);
+               }
+               MEM_freeN(ob->curve_cache);
+               ob->curve_cache = NULL;
+       }
+}
+
 void BKE_object_free_modifiers(Object *ob)
 {
        while (ob->modifiers.first) {
@@ -270,7 +283,9 @@ void BKE_object_free_derived_caches(Object *ob)
                ob->derivedDeform = NULL;
        }
        
-       BKE_displist_free(&ob->disp);
+       if (ob->curve_cache) {
+               BKE_displist_free(&ob->curve_cache->disp);
+       }
 }
 
 /* do not free object itself */
@@ -342,9 +357,12 @@ void BKE_object_free(Object *ob)
        if (ob->pc_ids.first) BLI_freelistN(&ob->pc_ids);
 
        /* Free runtime curves data. */
-       BLI_freelistN(&ob->bev);
-       if (ob->path)
-               free_path(ob->path);
+       if (ob->curve_cache) {
+               BLI_freelistN(&ob->curve_cache->bev);
+               if (ob->curve_cache->path)
+                       free_path(ob->curve_cache->path);
+               MEM_freeN(ob->curve_cache);
+       }
 }
 
 static void unlink_object__unlinkModifierLinks(void *userData, Object *ob, Object **obpoin)
@@ -1255,8 +1273,6 @@ Object *BKE_object_copy_ex(Main *bmain, Object *ob, int copy_caches)
 
        for (a = 0; a < obn->totcol; a++) id_us_plus((ID *)obn->mat[a]);
        
-       obn->disp.first = obn->disp.last = NULL;
-       
        if (ob->pd) {
                obn->pd = MEM_dupallocN(ob->pd);
                if (obn->pd->tex)
@@ -1280,8 +1296,7 @@ Object *BKE_object_copy_ex(Main *bmain, Object *ob, int copy_caches)
        obn->mpath = NULL;
 
        /* Copy runtime surve data. */
-       obn->bev.first = obn->bev.last = NULL;
-       obn->path = NULL;
+       obn->curve_cache = NULL;
 
        return obn;
 }
@@ -1760,9 +1775,9 @@ static void ob_parcurve(Scene *scene, Object *ob, Object *par, float mat[4][4])
        unit_m4(mat);
        
        cu = par->data;
-       if (par->path == NULL || par->path->data == NULL) /* only happens on reload file, but violates depsgraph still... fix! */
+       if (ELEM3(NULL, par->curve_cache, par->curve_cache->path, par->curve_cache->path->data)) /* only happens on reload file, but violates depsgraph still... fix! */
                BKE_displist_make_curveTypes(scene, par, 0);
-       if (par->path == NULL) return;
+       if (par->curve_cache->path == NULL) return;
        
        /* catch exceptions: feature for nla stride editing */
        if (ob->ipoflag & OB_DISABLE_PATH) {
@@ -1793,7 +1808,7 @@ static void ob_parcurve(Scene *scene, Object *ob, Object *par, float mat[4][4])
        
        /* time calculus is correct, now apply distance offset */
        if (cu->flag & CU_OFFS_PATHDIST) {
-               ctime += timeoffs / par->path->totdist;
+               ctime += timeoffs / par->curve_cache->path->totdist;
 
                /* restore */
                SWAP(float, sf_orig, ob->sf);
@@ -1950,7 +1965,7 @@ static void give_parvert(Object *par, int nr, float vec[3])
        }
        else if (par->type == OB_LATTICE) {
                Lattice *latt  = par->data;
-               DispList *dl   = BKE_displist_find(&par->disp, DL_VERTS);
+               DispList *dl   = par->curve_cache ? BKE_displist_find(&par->curve_cache->disp, DL_VERTS) : NULL;
                float (*co)[3] = dl ? (float (*)[3])dl->verts : NULL;
                int tot;
 
@@ -2503,10 +2518,10 @@ void BKE_object_foreach_display_point(
                        func_cb(co, user_data);
                }
        }
-       else if (ob->disp.first) {
+       else if (ob->curve_cache && ob->curve_cache->disp.first) {
                DispList *dl;
 
-               for (dl = ob->disp.first; dl; dl = dl->next) {
+               for (dl = ob->curve_cache->disp.first; dl; dl = dl->next) {
                        float *v3 = dl->verts;
                        int totvert = dl->nr;
                        int i;
index d78edc80654a9a241880bc99d4031d00db50a0f6..b7a9ce092ef9187bc5d7d9d2b69e530024761941 100644 (file)
@@ -4818,8 +4818,6 @@ static void direct_link_object(FileData *fd, Object *ob)
                ob->mode &= ~(OB_MODE_EDIT | OB_MODE_PARTICLE_EDIT);
        }
        
-       ob->disp.first = ob->disp.last = NULL;
-       
        ob->adt = newdataadr(fd, ob->adt);
        direct_link_animdata(fd, ob->adt);
        
@@ -5015,8 +5013,7 @@ static void direct_link_object(FileData *fd, Object *ob)
        link_list(fd, &ob->pc_ids);
 
        /* Runtime curve data  */
-       ob->bev.first = ob->bev.last = NULL;
-       ob->path = NULL;
+       ob->curve_cache = NULL;
 
        /* in case this value changes in future, clamp else we get undefined behavior */
        CLAMP(ob->rotmode, ROT_MODE_MIN, ROT_MODE_MAX);
index d6f48b4d3503e2b12b9294359f3ed5e5719406b2..3d5db18c5468bb1ef974a81ca7251319941eac7c 100644 (file)
@@ -1244,7 +1244,7 @@ static void make_object_duplilist_real(bContext *C, Scene *scene, Base *base,
 
                ob->parent = NULL;
                ob->constraints.first = ob->constraints.last = NULL;
-               ob->disp.first = ob->disp.last = NULL;
+               ob->curve_cache = NULL;
                ob->transflag &= ~OB_DUPLI;
                ob->lay = base->lay;
 
@@ -1386,7 +1386,7 @@ static EnumPropertyItem convert_target_items[] = {
 
 static void curvetomesh(Scene *scene, Object *ob) 
 {
-       if (ob->disp.first == NULL)
+       if (ELEM(NULL, ob->curve_cache, ob->curve_cache->disp.first))
                BKE_displist_make_curveTypes(scene, ob, 0);  /* force creation */
 
        BKE_mesh_from_nurbs(ob); /* also does users */
@@ -1554,7 +1554,7 @@ static int convert_exec(bContext *C, wmOperator *op)
 
                        cu = newob->data;
 
-                       if (!newob->disp.first)
+                       if ( !newob->curve_cache || !newob->curve_cache->disp.first)
                                BKE_displist_make_curveTypes(scene, newob, 0);
 
                        newob->type = OB_CURVE;
@@ -1596,7 +1596,7 @@ static int convert_exec(bContext *C, wmOperator *op)
                                curvetomesh(scene, newob);
 
                                /* meshes doesn't use displist */
-                               BKE_displist_free(&newob->disp);
+                               BKE_object_free_curve_cache(newob);
                        }
                }
                else if (ELEM(ob->type, OB_CURVE, OB_SURF)) {
@@ -1617,7 +1617,7 @@ static int convert_exec(bContext *C, wmOperator *op)
                                        newob = ob;
 
                                        /* meshes doesn't use displist */
-                                       BKE_displist_free(&newob->disp);
+                                       BKE_object_free_curve_cache(newob);
                                }
 
                                curvetomesh(scene, newob);
@@ -1636,7 +1636,7 @@ static int convert_exec(bContext *C, wmOperator *op)
                                ob->flag |= OB_DONE;
                        }
 
-                       if (!baseob->disp.first) {
+                       if (!baseob->curve_cache || !baseob->curve_cache->disp.first) {
                                BKE_displist_make_mball(scene, baseob);
                        }
 
@@ -1659,7 +1659,7 @@ static int convert_exec(bContext *C, wmOperator *op)
                                        for (a = 0; a < newob->totcol; a++) id_us_plus((ID *)me->mat[a]);
                                }
 
-                               BKE_mesh_from_metaball(&baseob->disp, newob->data);
+                               BKE_mesh_from_metaball(&baseob->curve_cache->disp, newob->data);
 
                                if (obact->type == OB_MBALL) {
                                        basact = basen;
index 98c9c8d15fe3a2a459bec6dea1b5cd8b3836ff16..c1cddf092aa0429a577f3b3119a70c748667414d 100644 (file)
@@ -115,8 +115,8 @@ static void stats_object(Object *ob, int sel, int totob, SceneStats *stats)
                {
                        int totv = 0, totf = 0, tottri = 0;
 
-                       if (ob->disp.first)
-                               BKE_displist_count(&ob->disp, &totv, &totf, &tottri);
+                       if (ob->curve_cache && ob->curve_cache->disp.first)
+                               BKE_displist_count(&ob->curve_cache->disp, &totv, &totf, &tottri);
 
                        totv   *= totob;
                        totf   *= totob;
index 512651e91fbee8a403847b4ba0c756a7169d33fa..66ae7f6f8aca30af07cc5c853a9b5b9a3c8c9bb1 100644 (file)
@@ -1900,9 +1900,9 @@ static void drawlattice(Scene *scene, View3D *v3d, Object *ob)
        const bool is_edit = (lt->editlatt != NULL);
 
        /* now we default make displist, this will modifiers work for non animated case */
-       if (ob->disp.first == NULL)
+       if (ELEM(NULL, ob->curve_cache, ob->curve_cache->disp.first))
                BKE_lattice_modifiers_calc(scene, ob);
-       dl = BKE_displist_find(&ob->disp, DL_VERTS);
+       dl = BKE_displist_find(&ob->curve_cache->disp, DL_VERTS);
        
        if (is_edit) {
                lt = lt->editlatt->latt;
@@ -3885,7 +3885,7 @@ static bool drawDispList_nobackface(Scene *scene, View3D *v3d, RegionView3D *rv3
                case OB_CURVE:
                        cu = ob->data;
 
-                       lb = &ob->disp;
+                       lb = &ob->curve_cache->disp;
 
                        if (solid) {
                                dl = lb->first;
@@ -3935,7 +3935,7 @@ static bool drawDispList_nobackface(Scene *scene, View3D *v3d, RegionView3D *rv3
                        break;
                case OB_SURF:
 
-                       lb = &ob->disp;
+                       lb = &ob->curve_cache->disp;
 
                        if (solid) {
                                dl = lb->first;
@@ -3963,8 +3963,11 @@ static bool drawDispList_nobackface(Scene *scene, View3D *v3d, RegionView3D *rv3
                case OB_MBALL:
 
                        if (BKE_mball_is_basis(ob)) {
-                               lb = &ob->disp;
-                               if (lb->first == NULL) BKE_displist_make_mball(scene, ob);
+                               lb = ob->curve_cache ? &ob->curve_cache->disp : NULL;
+                               if (lb->first == NULL) {
+                                       BKE_displist_make_mball(scene, ob);
+                                       lb = &ob->curve_cache->disp;
+                               }
                                if (lb->first == NULL) {
                                        return true;
                                }
@@ -5554,7 +5557,7 @@ static void drawnurb(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
        if ((cu->flag & CU_3D) && (ts->normalsize > 0.0015f) && (cu->drawflag & CU_HIDE_NORMALS) == 0) {
 
                UI_ThemeColor(TH_WIRE_EDIT);
-               for (bl = ob->bev.first, nu = nurb; nu && bl; bl = bl->next, nu = nu->next) {
+               for (bl = ob->curve_cache->bev.first, nu = nurb; nu && bl; bl = bl->next, nu = nu->next) {
                        BevPoint *bevp = (BevPoint *)(bl + 1);
                        int nr = bl->nr;
                        int skip = nu->resolu / 16;
@@ -5977,7 +5980,7 @@ static void draw_forcefield(Object *ob, RegionView3D *rv3d,
        }
        else if (pd->forcefield == PFIELD_GUIDE && ob->type == OB_CURVE) {
                Curve *cu = ob->data;
-               if ((cu->flag & CU_PATH) && ob->path && ob->path->data) {
+               if ((cu->flag & CU_PATH) && ob->curve_cache->path && ob->curve_cache->path->data) {
                        float mindist, guidevec1[4], guidevec2[3];
 
                        //if (has_ipo_code(ob->ipo, OB_PD_FSTR))
@@ -6242,7 +6245,7 @@ static void drawObjectSelect(Scene *scene, View3D *v3d, ARegion *ar, Base *base,
                        has_faces = dm->getNumTessFaces(dm);
                }
                else {
-                       has_faces = BKE_displist_has_faces(&ob->disp);
+                       has_faces = BKE_displist_has_faces(&ob->curve_cache->disp);
                }
 
                if (has_faces && ED_view3d_boundbox_clip(rv3d, ob->obmat, ob->bb)) {
@@ -6251,7 +6254,7 @@ static void drawObjectSelect(Scene *scene, View3D *v3d, ARegion *ar, Base *base,
                                draw_mesh_object_outline(v3d, ob, dm);
                        }
                        else {
-                               drawDispListwire(&ob->disp);
+                               drawDispListwire(&ob->curve_cache->disp);
                        }
                        draw_index_wire = true;
                }
@@ -6259,7 +6262,7 @@ static void drawObjectSelect(Scene *scene, View3D *v3d, ARegion *ar, Base *base,
        else if (ob->type == OB_MBALL) {
                if (BKE_mball_is_basis(ob)) {
                        if ((base->flag & OB_FROMDUPLI) == 0)
-                               drawDispListwire(&ob->disp);
+                               drawDispListwire(&ob->curve_cache->disp);
                }
        }
        else if (ob->type == OB_ARMATURE) {
@@ -6294,7 +6297,7 @@ static void draw_wire_extra(Scene *scene, RegionView3D *rv3d, Object *ob, unsign
                                        drawCurveDMWired(ob);
                                }
                                else {
-                                       drawDispListwire(&ob->disp);
+                                       drawDispListwire(&ob->curve_cache->disp);
                                }
 
                                if (ob->type == OB_CURVE)
@@ -6303,7 +6306,7 @@ static void draw_wire_extra(Scene *scene, RegionView3D *rv3d, Object *ob, unsign
                }
                else if (ob->type == OB_MBALL) {
                        if (BKE_mball_is_basis(ob)) {
-                               drawDispListwire(&ob->disp);
+                               drawDispListwire(&ob->curve_cache->disp);
                        }
                }
 
@@ -6613,7 +6616,9 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, const short
        /* bad exception, solve this! otherwise outline shows too late */
        if (ELEM3(ob->type, OB_CURVE, OB_SURF, OB_FONT)) {
                /* still needed for curves hidden in other layers. depgraph doesnt handle that yet */
-               if (ob->disp.first == NULL) BKE_displist_make_curveTypes(scene, ob, 0);
+               if (ELEM(NULL, ob->curve_cache, ob->curve_cache->disp.first)) {
+                       BKE_displist_make_curveTypes(scene, ob, 0);
+               }
        }
        
        /* draw outline for selected objects, mesh does itself */
index 0490d8763d8ff43616a42be4bd72347ec1639544..9f922f12976cb13b5d371e798d4bb565d4ce69f8 100644 (file)
@@ -368,7 +368,7 @@ void lattice_foreachScreenVert(
        Object *obedit = vc->obedit;
        Lattice *lt = obedit->data;
        BPoint *bp = lt->editlatt->latt->def;
-       DispList *dl = BKE_displist_find(&obedit->disp, DL_VERTS);
+       DispList *dl = obedit->curve_cache ? BKE_displist_find(&obedit->curve_cache->disp, DL_VERTS) : NULL;
        float *co = dl ? dl->verts : NULL;
        int i, N = lt->editlatt->latt->pntsu * lt->editlatt->latt->pntsv * lt->editlatt->latt->pntsw;
 
index 4544e0332c4b4ca4d7d7967f5d333838f989bbb9..1e844d2a6fb9b0e46739adc5a113582e2deb4cd6 100644 (file)
@@ -130,7 +130,6 @@ typedef struct Object {
        
        ListBase constraintChannels  DNA_DEPRECATED; // XXX deprecated... old animation system
        ListBase effect  DNA_DEPRECATED;             // XXX deprecated... keep for readfile
-       ListBase disp;      /* list of DispList, used by lattice, metaballs curve & surfaces */
        ListBase defbase;   /* list of bDeformGroup (vertex groups) names and flag only */
        ListBase modifiers; /* list of ModifierData structures */
 
@@ -277,8 +276,8 @@ typedef struct Object {
 
        float ima_ofs[2];               /* offset for image empties */
 
-       struct Path *path;
-       ListBase bev;
+       /* Runtime valuated curve-specific data, not stored in the file */
+       struct CurveCache *curve_cache;
 } Object;
 
 /* Warning, this is not used anymore because hooks are now modifiers */
index 4c652770e3f89a5a9ea685f51b6efaffbebe9749..5d69ccd2d3f64199b3b0755e59f0bdfe427689ae 100644 (file)
@@ -359,8 +359,13 @@ Mesh *rna_Main_meshes_new_from_object(
                                BKE_mesh_from_metaball(&disp, tmpmesh);
                                BKE_displist_free(&disp);
                        }
-                       else
-                               BKE_mesh_from_metaball(&ob->disp, tmpmesh);
+                       else {
+                               ListBase disp = {NULL, NULL};
+                               if (ob->curve_cache) {
+                                       disp = ob->curve_cache->disp;
+                               }
+                               BKE_mesh_from_metaball(&disp, tmpmesh);
+                       }
 
                        break;
 
index 0a61777ee672fe7a8b40372583305bd4246af93a..3478ec6e3b4221c4914147a5d468e2fd0a8e1b79 100644 (file)
@@ -50,6 +50,7 @@
 
 #include "BKE_cdderivedmesh.h"
 #include "BKE_displist.h"
+#include "BKE_curve.h"
 #include "BKE_mesh.h"
 #include "BKE_modifier.h"
 #include "BKE_object.h"
@@ -387,12 +388,12 @@ static DerivedMesh *arrayModifier_doArray(ArrayModifierData *amd,
                        BKE_object_to_mat3(amd->curve_ob, tmp_mat);
                        scale = mat3_to_scale(tmp_mat);
                                
-                       if (!amd->curve_ob->path) {
+                       if (!amd->curve_ob->curve_cache || !amd->curve_ob->curve_cache->path) {
                                cu->flag |= CU_PATH; // needed for path & bevlist
                                BKE_displist_make_curveTypes(scene, amd->curve_ob, 0);
                        }
-                       if (amd->curve_ob->path)
-                               length = scale * amd->curve_ob->path->totdist;
+                       if (amd->curve_ob->curve_cache->path)
+                               length = scale * amd->curve_ob->curve_cache->path->totdist;
                }
        }