Cleanup: move object bounding-box into runtime struct
authorCampbell Barton <ideasman42@gmail.com>
Sun, 17 Feb 2019 01:24:08 +0000 (12:24 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 17 Feb 2019 01:52:53 +0000 (12:52 +1100)
15 files changed:
source/blender/blenkernel/intern/armature.c
source/blender/blenkernel/intern/curve.c
source/blender/blenkernel/intern/displist.c
source/blender/blenkernel/intern/gpencil.c
source/blender/blenkernel/intern/lattice.c
source/blender/blenkernel/intern/mball.c
source/blender/blenkernel/intern/mesh.c
source/blender/blenkernel/intern/object.c
source/blender/blenkernel/intern/object_update.c
source/blender/blenloader/intern/readfile.c
source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc
source/blender/editors/object/object_transform.c
source/blender/editors/sculpt_paint/sculpt.c
source/blender/editors/space_view3d/view3d_edit.c
source/blender/makesdna/DNA_object_types.h

index 99474ce9bae050bd98794c9d8ccd2240ce9d473c..c4462c7d4798e5630d69442327efba88c9a2ce97 100644 (file)
@@ -2466,10 +2466,10 @@ static void boundbox_armature(Object *ob)
        BoundBox *bb;
        float min[3], max[3];
 
-       if (ob->bb == NULL) {
-               ob->bb = MEM_callocN(sizeof(BoundBox), "Armature boundbox");
+       if (ob->runtime.bb == NULL) {
+               ob->runtime.bb = MEM_callocN(sizeof(BoundBox), "Armature boundbox");
        }
-       bb = ob->bb;
+       bb = ob->runtime.bb;
 
        INIT_MINMAX(min, max);
        if (!minmax_armature(ob, min, max)) {
@@ -2486,7 +2486,7 @@ BoundBox *BKE_armature_boundbox_get(Object *ob)
 {
        boundbox_armature(ob);
 
-       return ob->bb;
+       return ob->runtime.bb;
 }
 
 bool BKE_pose_minmax(Object *ob, float r_min[3], float r_max[3], bool use_hidden, bool use_select)
index 3be101134ec0bbc42e81dcb5461abaa3eda01aa1..6f44dcdecc53e008fd0814b481344fef17670c17 100644 (file)
@@ -319,21 +319,21 @@ void BKE_curve_boundbox_calc(Curve *cu, float r_loc[3], float r_size[3])
 BoundBox *BKE_curve_boundbox_get(Object *ob)
 {
        /* This is Object-level data access, DO NOT touch to Mesh's bb, would be totally thread-unsafe. */
-       if (ob->bb == NULL || ob->bb->flag & BOUNDBOX_DIRTY) {
+       if (ob->runtime.bb == NULL || ob->runtime.bb->flag & BOUNDBOX_DIRTY) {
                Curve *cu = ob->data;
                float min[3], max[3];
 
                INIT_MINMAX(min, max);
                BKE_curve_minmax(cu, true, min, max);
 
-               if (ob->bb == NULL) {
-                       ob->bb = MEM_mallocN(sizeof(*ob->bb), __func__);
+               if (ob->runtime.bb == NULL) {
+                       ob->runtime.bb = MEM_mallocN(sizeof(*ob->runtime.bb), __func__);
                }
-               BKE_boundbox_init_from_minmax(ob->bb, min, max);
-               ob->bb->flag &= ~BOUNDBOX_DIRTY;
+               BKE_boundbox_init_from_minmax(ob->runtime.bb, min, max);
+               ob->runtime.bb->flag &= ~BOUNDBOX_DIRTY;
        }
 
-       return ob->bb;
+       return ob->runtime.bb;
 }
 
 void BKE_curve_texspace_calc(Curve *cu)
index 0f3a3192d75283bd70edc75c6284c9f7574b8bed..19ddb59acee4cb4b889f3f4fe4d2fe3239ebe2e4 100644 (file)
@@ -1894,8 +1894,8 @@ static void boundbox_displist_object(Object *ob)
                 */
 
                /* object's BB is calculated from final displist */
-               if (ob->bb == NULL)
-                       ob->bb = MEM_callocN(sizeof(BoundBox), "boundbox");
+               if (ob->runtime.bb == NULL)
+                       ob->runtime.bb = MEM_callocN(sizeof(BoundBox), "boundbox");
 
                if (ob->runtime.mesh_eval) {
                        BKE_object_boundbox_calc_from_mesh(ob, ob->runtime.mesh_eval);
@@ -1905,9 +1905,9 @@ static void boundbox_displist_object(Object *ob)
 
                        INIT_MINMAX(min, max);
                        BKE_displist_minmax(&ob->runtime.curve_cache->disp, min, max);
-                       BKE_boundbox_init_from_minmax(ob->bb, min, max);
+                       BKE_boundbox_init_from_minmax(ob->runtime.bb, min, max);
 
-                       ob->bb->flag &= ~BOUNDBOX_DIRTY;
+                       ob->runtime.bb->flag &= ~BOUNDBOX_DIRTY;
                }
        }
 }
index d2ca18ef231e0ea01b564a9c9acb6a6f59a2a9a7..83c69ee657fb43e55adeb01db910f97e5fe6f593 100644 (file)
@@ -1111,11 +1111,11 @@ static void boundbox_gpencil(Object *ob)
        bGPdata *gpd;
        float min[3], max[3];
 
-       if (ob->bb == NULL) {
-               ob->bb = MEM_callocN(sizeof(BoundBox), "GPencil boundbox");
+       if (ob->runtime.bb == NULL) {
+               ob->runtime.bb = MEM_callocN(sizeof(BoundBox), "GPencil boundbox");
        }
 
-       bb  = ob->bb;
+       bb  = ob->runtime.bb;
        gpd = ob->data;
 
        BKE_gpencil_data_minmax(NULL, gpd, min, max);
@@ -1133,15 +1133,15 @@ BoundBox *BKE_gpencil_boundbox_get(Object *ob)
                return NULL;
 
        gpd = ob->data;
-       if ((ob->bb) && ((ob->bb->flag & BOUNDBOX_DIRTY) == 0) &&
+       if ((ob->runtime.bb) && ((ob->runtime.bb->flag & BOUNDBOX_DIRTY) == 0) &&
            ((gpd->flag & GP_DATA_CACHE_IS_DIRTY) == 0))
        {
-               return ob->bb;
+               return ob->runtime.bb;
        }
 
        boundbox_gpencil(ob);
 
-       return ob->bb;
+       return ob->runtime.bb;
 }
 
 /* ************************************************** */
index 4a9742679501cd5899ea104d4234e153d370379d..f11c1cb134fb1681a2b5e325d664995fa724a92c 100644 (file)
@@ -1089,11 +1089,11 @@ static void boundbox_lattice(Object *ob)
        Lattice *lt;
        float min[3], max[3];
 
-       if (ob->bb == NULL) {
-               ob->bb = MEM_callocN(sizeof(BoundBox), "Lattice boundbox");
+       if (ob->runtime.bb == NULL) {
+               ob->runtime.bb = MEM_callocN(sizeof(BoundBox), "Lattice boundbox");
        }
 
-       bb = ob->bb;
+       bb = ob->runtime.bb;
        lt = ob->data;
 
        INIT_MINMAX(min, max);
@@ -1107,7 +1107,7 @@ BoundBox *BKE_lattice_boundbox_get(Object *ob)
 {
        boundbox_lattice(ob);
 
-       return ob->bb;
+       return ob->runtime.bb;
 }
 
 void BKE_lattice_minmax_dl(Object *ob, Lattice *lt, float min[3], float max[3])
index 10825a36ea6382db2e1e90a4ea4b0834ad08a10e..14878cdf4944c73da494484da26ed083d3edd0a4 100644 (file)
@@ -186,8 +186,10 @@ void BKE_mball_texspace_calc(Object *ob)
        int tot;
        bool do_it = false;
 
-       if (ob->bb == NULL) ob->bb = MEM_callocN(sizeof(BoundBox), "mb boundbox");
-       bb = ob->bb;
+       if (ob->runtime.bb == NULL) {
+               ob->runtime.bb = MEM_callocN(sizeof(BoundBox), "mb boundbox");
+       }
+       bb = ob->runtime.bb;
 
        /* Weird one, this. */
 /*      INIT_MINMAX(min, max); */
@@ -222,8 +224,8 @@ BoundBox *BKE_mball_boundbox_get(Object *ob)
 {
        BLI_assert(ob->type == OB_MBALL);
 
-       if (ob->bb != NULL && (ob->bb->flag & BOUNDBOX_DIRTY) == 0) {
-               return ob->bb;
+       if (ob->runtime.bb != NULL && (ob->runtime.bb->flag & BOUNDBOX_DIRTY) == 0) {
+               return ob->runtime.bb;
        }
 
        /* This should always only be called with evaluated objects, but currently RNA is a problem here... */
@@ -231,7 +233,7 @@ BoundBox *BKE_mball_boundbox_get(Object *ob)
                BKE_mball_texspace_calc(ob);
        }
 
-       return ob->bb;
+       return ob->runtime.bb;
 }
 
 float *BKE_mball_make_orco(Object *ob, ListBase *dispbase)
@@ -243,7 +245,7 @@ float *BKE_mball_make_orco(Object *ob, ListBase *dispbase)
        int a;
 
        /* restore size and loc */
-       bb = ob->bb;
+       bb = ob->runtime.bb;
        loc[0] = (bb->vec[0][0] + bb->vec[4][0]) / 2.0f;
        size[0] = bb->vec[4][0] - loc[0];
        loc[1] = (bb->vec[0][1] + bb->vec[2][1]) / 2.0f;
index 9a725be302cc8699438eefbdb544007069846577..780712c8e2569cc4e2bb5a5565597f6be63b533e 100644 (file)
@@ -897,7 +897,7 @@ void BKE_mesh_texspace_calc(Mesh *me)
 BoundBox *BKE_mesh_boundbox_get(Object *ob)
 {
        /* This is Object-level data access, DO NOT touch to Mesh's bb, would be totally thread-unsafe. */
-       if (ob->bb == NULL || ob->bb->flag & BOUNDBOX_DIRTY) {
+       if (ob->runtime.bb == NULL || ob->runtime.bb->flag & BOUNDBOX_DIRTY) {
                Mesh *me = ob->data;
                float min[3], max[3];
 
@@ -907,14 +907,14 @@ BoundBox *BKE_mesh_boundbox_get(Object *ob)
                        max[0] = max[1] = max[2] = 1.0f;
                }
 
-               if (ob->bb == NULL) {
-                       ob->bb = MEM_mallocN(sizeof(*ob->bb), __func__);
+               if (ob->runtime.bb == NULL) {
+                       ob->runtime.bb = MEM_mallocN(sizeof(*ob->runtime.bb), __func__);
                }
-               BKE_boundbox_init_from_minmax(ob->bb, min, max);
-               ob->bb->flag &= ~BOUNDBOX_DIRTY;
+               BKE_boundbox_init_from_minmax(ob->runtime.bb, min, max);
+               ob->runtime.bb->flag &= ~BOUNDBOX_DIRTY;
        }
 
-       return ob->bb;
+       return ob->runtime.bb;
 }
 
 BoundBox *BKE_mesh_texspace_get(Mesh *me, float r_loc[3], float r_rot[3], float r_size[3])
index 91ecc8dd74ab4d86de3fe70aeec26f0e472a6f75..8a50a93487a4196d0e07293baf7e8db32944c29a 100644 (file)
@@ -449,9 +449,9 @@ void BKE_object_free_derived_caches(Object *ob)
                }
        }
 
-       if (ob->bb) {
-               MEM_freeN(ob->bb);
-               ob->bb = NULL;
+       if (ob->runtime.bb) {
+               MEM_freeN(ob->runtime.bb);
+               ob->runtime.bb = NULL;
        }
 
        object_update_from_subsurf_ccg(ob);
@@ -565,7 +565,7 @@ void BKE_object_free(Object *ob)
        MEM_SAFE_FREE(ob->mat);
        MEM_SAFE_FREE(ob->matbits);
        MEM_SAFE_FREE(ob->iuser);
-       MEM_SAFE_FREE(ob->bb);
+       MEM_SAFE_FREE(ob->runtime.bb);
 
        BLI_freelistN(&ob->defbase);
        BLI_freelistN(&ob->fmaps);
@@ -1342,7 +1342,7 @@ void BKE_object_copy_data(Main *bmain, Object *ob_dst, const Object *ob_src, con
 
        if (ob_src->iuser) ob_dst->iuser = MEM_dupallocN(ob_src->iuser);
 
-       if (ob_src->bb) ob_dst->bb = MEM_dupallocN(ob_src->bb);
+       if (ob_src->runtime.bb) ob_dst->runtime.bb = MEM_dupallocN(ob_src->runtime.bb);
 
        BLI_listbase_clear(&ob_dst->modifiers);
 
@@ -2447,13 +2447,13 @@ void BKE_object_boundbox_calc_from_mesh(struct Object *ob, struct Mesh *me_eval)
                zero_v3(max);
        }
 
-       if (ob->bb == NULL) {
-               ob->bb = MEM_callocN(sizeof(BoundBox), "DM-BoundBox");
+       if (ob->runtime.bb == NULL) {
+               ob->runtime.bb = MEM_callocN(sizeof(BoundBox), "DM-BoundBox");
        }
 
-       BKE_boundbox_init_from_minmax(ob->bb, min, max);
+       BKE_boundbox_init_from_minmax(ob->runtime.bb, min, max);
 
-       ob->bb->flag &= ~BOUNDBOX_DIRTY;
+       ob->runtime.bb->flag &= ~BOUNDBOX_DIRTY;
 }
 
 void BKE_object_dimensions_get(Object *ob, float vec[3])
index 59068dc4cd51b8796f9e1ae2dc174e38f0749c52..78c1ca6419b39b806caa2a45449ca5a40309a9e8 100644 (file)
@@ -258,10 +258,10 @@ void BKE_object_eval_boundbox(Depsgraph *depsgraph, Object *object)
        Object *ob_orig = DEG_get_original_object(object);
        BoundBox *bb = BKE_object_boundbox_get(object);
        if (bb != NULL) {
-               if (ob_orig->bb == NULL) {
-                       ob_orig->bb = MEM_mallocN(sizeof(*ob_orig->bb), __func__);
+               if (ob_orig->runtime.bb == NULL) {
+                       ob_orig->runtime.bb = MEM_mallocN(sizeof(*ob_orig->runtime.bb), __func__);
                }
-               *ob_orig->bb = *bb;
+               *ob_orig->runtime.bb = *bb;
        }
 }
 
index fcd745eeb1f0f902a1db44e61051218c348e2667..186bf613de52a1e10358bf7807c153eff7e8db1f 100644 (file)
@@ -5654,7 +5654,7 @@ static void direct_link_object(FileData *fd, Object *ob)
                BKE_object_empty_draw_type_set(ob, ob->empty_drawtype);
        }
 
-       ob->bb = NULL;
+       ob->runtime.bb = NULL;
        ob->derivedDeform = NULL;
        ob->derivedFinal = NULL;
        BKE_object_runtime_reset(ob);
index 32212b0e1c14c602dbddd7b68bd1b6df35a640ac..597cc8cd2efe45f1ffd7913fc3a7022fb6b7b1be 100644 (file)
@@ -885,7 +885,7 @@ ID *deg_update_copy_on_write_datablock(const Depsgraph *depsgraph,
        ListBase *gpumaterial_ptr = NULL;
        DrawDataList drawdata_backup;
        DrawDataList *drawdata_ptr = NULL;
-       ObjectRuntimeBackup object_runtime_backup = {{NULL}};
+       ObjectRuntimeBackup object_runtime_backup = {{0}};
        if (check_datablock_expanded(id_cow)) {
                switch (id_type) {
                        case ID_MA:
index 24abafe7d0fe8216f81d70485a776850c7376bc6..201e8a8ea1685b5cfb6477583440aff4a54b1d6b 100644 (file)
@@ -1011,7 +1011,7 @@ static int object_origin_set_exec(bContext *C, wmOperator *op)
 
                                Curve *cu = ob->data;
 
-                               if (ob->bb == NULL && (centermode != ORIGIN_TO_CURSOR)) {
+                               if (ob->runtime.bb == NULL && (centermode != ORIGIN_TO_CURSOR)) {
                                        /* do nothing*/
                                }
                                else {
@@ -1020,8 +1020,8 @@ static int object_origin_set_exec(bContext *C, wmOperator *op)
                                        }
                                        else {
                                                /* extra 0.5 is the height o above line */
-                                               cent[0] = 0.5f * (ob->bb->vec[4][0] + ob->bb->vec[0][0]);
-                                               cent[1] = 0.5f * (ob->bb->vec[0][1] + ob->bb->vec[2][1]);
+                                               cent[0] = 0.5f * (ob->runtime.bb->vec[4][0] + ob->runtime.bb->vec[0][0]);
+                                               cent[1] = 0.5f * (ob->runtime.bb->vec[0][1] + ob->runtime.bb->vec[2][1]);
                                        }
 
                                        cent[2] = 0.0f;
index cf580e093fdae47ea65106b8ac9df66a95f059a7..b84798581a0d2d1898e7c64e98d4fa7c93785fe4 100644 (file)
@@ -5045,11 +5045,11 @@ static void sculpt_restore_mesh(Sculpt *sd, Object *ob)
 /* Copy the PBVH bounding box into the object's bounding box */
 void sculpt_update_object_bounding_box(Object *ob)
 {
-       if (ob->bb) {
+       if (ob->runtime.bb) {
                float bb_min[3], bb_max[3];
 
                BKE_pbvh_bounding_box(ob->sculpt->pbvh, bb_min, bb_max);
-               BKE_boundbox_init_from_minmax(ob->bb, bb_min, bb_max);
+               BKE_boundbox_init_from_minmax(ob->runtime.bb, bb_min, bb_max);
        }
 }
 
index 6994b0486980a4bf9fdafbf22e960853fe00ace6..aaf1d8a01a366784124bf0578aa2a28a0f2cda8a 100644 (file)
@@ -295,10 +295,10 @@ static bool view3d_orbit_calc_center(bContext *C, float r_dyn_ofs[3])
                                /* use the boundbox if we can */
                                Object *ob_eval = base_eval->object;
 
-                               if (ob_eval->bb && !(ob_eval->bb->flag & BOUNDBOX_DIRTY)) {
+                               if (ob_eval->runtime.bb && !(ob_eval->runtime.bb->flag & BOUNDBOX_DIRTY)) {
                                        float cent[3];
 
-                                       BKE_boundbox_calc_center_aabb(ob_eval->bb, cent);
+                                       BKE_boundbox_calc_center_aabb(ob_eval->runtime.bb, cent);
 
                                        mul_m4_v3(ob_eval->obmat, cent);
                                        add_v3_v3(select_center, cent);
index f951b7273c9b975503cc73df4dc16e00cfa793ee..b79009e9d1d29e0830239864ac4f9ea9af32940c 100644 (file)
@@ -121,6 +121,15 @@ struct ObjectBBoneDeform;
 
 /* Not saved in file! */
 typedef struct Object_Runtime {
+       /**
+        * The custom data layer mask that was last used
+        * to calculate mesh_eval and mesh_deform_eval.
+        */
+       uint64_t last_data_mask;
+
+       /** Axis aligned boundbox (in localspace). */
+       struct BoundBox *bb;
+
        /**
         * Original mesh pointer, before object->data was changed to point
         * to mesh_eval.
@@ -138,7 +147,6 @@ typedef struct Object_Runtime {
         */
        struct Mesh *mesh_deform_eval;
 
-
        /** Runtime evaluated curve-specific data, not stored in the file. */
        struct CurveCache *curve_cache;
 
@@ -147,12 +155,6 @@ typedef struct Object_Runtime {
 
        struct ObjectBBoneDeform *cached_bbone_deformation;
 
-       /**
-        * The custom data layer mask that was last used
-        * to calculate mesh_eval and mesh_deform_eval.
-        */
-       uint64_t last_data_mask;
-
        /** Did last modifier stack generation need mapping support? */
        char last_need_mapping;
        char pad[7];
@@ -179,8 +181,6 @@ typedef struct Object {
        /** Old animation system, deprecated for 2.5. */
        struct Ipo *ipo  DNA_DEPRECATED;
        /* struct Path *path; */
-       /** Axis aligned boundbox (in localspace). */
-       struct BoundBox *bb;
        struct bAction *action  DNA_DEPRECATED;  // XXX deprecated... old animation system
        struct bAction *poselib;
        /** Pose data, armature objects only. */