Cleanup: move object bounding-box into runtime struct
This commit is contained in:
parent
0d86259fc8
commit
ae2b677dcb
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/* ************************************************** */
|
||||
|
|
|
@ -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])
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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])
|
||||
|
|
|
@ -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])
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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. */
|
||||
|
|
Loading…
Reference in New Issue