Cleanup: remove Mesh.bb and Curve.bb, no reason for these to be persistent

These were only strictly valid for texture space calculation, don't store them
since they should not be used after that. Only store a flag to indicate if the
auto texture space has been evaluated.

In the future it might make sense to store bounding boxes at the mesh level to
speed up bounding box computation for multiple objects using the same mesh, but
then it will need to be implemented differently.
This commit is contained in:
2019-09-23 15:31:11 +02:00
parent 5c89c689db
commit 9208146199
14 changed files with 95 additions and 176 deletions

View File

@@ -86,11 +86,10 @@ void BKE_curve_curve_dimension_update(struct Curve *cu);
void BKE_curve_boundbox_calc(struct Curve *cu, float r_loc[3], float r_size[3]);
struct BoundBox *BKE_curve_boundbox_get(struct Object *ob);
void BKE_curve_texspace_calc(struct Curve *cu);
struct BoundBox *BKE_curve_texspace_get(struct Curve *cu,
float r_loc[3],
float r_rot[3],
float r_size[3]);
void BKE_curve_texspace_ensure(struct Curve *cu);
void BKE_curve_texspace_get(struct Curve *cu, float r_loc[3], float r_rot[3], float r_size[3]);
bool BKE_curve_minmax(struct Curve *cu, bool use_radius, float min[3], float max[3]);
bool BKE_curve_center_median(struct Curve *cu, float cent[3]);

View File

@@ -141,8 +141,6 @@ bool BKE_mesh_ensure_facemap_customdata(struct Mesh *me);
bool BKE_mesh_clear_facemap_customdata(struct Mesh *me);
void BKE_mesh_make_local(struct Main *bmain, struct Mesh *me, const bool lib_local);
void BKE_mesh_boundbox_calc(struct Mesh *me, float r_loc[3], float r_size[3]);
void BKE_mesh_texspace_calc(struct Mesh *me);
float (*BKE_mesh_orco_verts_get(struct Object *ob))[3];
void BKE_mesh_orco_verts_transform(struct Mesh *me, float (*orco)[3], int totvert, int invert);
int test_index_face(struct MFace *mface, struct CustomData *mfdata, int mfindex, int nr);
@@ -192,10 +190,10 @@ void BKE_mesh_smooth_flag_set(struct Mesh *me, const bool use_smooth);
const char *BKE_mesh_cmp(struct Mesh *me1, struct Mesh *me2, float thresh);
struct BoundBox *BKE_mesh_boundbox_get(struct Object *ob);
struct BoundBox *BKE_mesh_texspace_get(struct Mesh *me,
float r_loc[3],
float r_rot[3],
float r_size[3]);
void BKE_mesh_texspace_calc(struct Mesh *me);
void BKE_mesh_texspace_ensure(struct Mesh *me);
void BKE_mesh_texspace_get(struct Mesh *me, float r_loc[3], float r_rot[3], float r_size[3]);
void BKE_mesh_texspace_get_reference(
struct Mesh *me, short **r_texflag, float **r_loc, float **r_rot, float **r_size);
void BKE_mesh_texspace_copy_from_object(struct Mesh *me, struct Object *ob);

View File

@@ -142,7 +142,6 @@ void BKE_curve_free(Curve *cu)
MEM_SAFE_FREE(cu->mat);
MEM_SAFE_FREE(cu->str);
MEM_SAFE_FREE(cu->strinfo);
MEM_SAFE_FREE(cu->bb);
MEM_SAFE_FREE(cu->tb);
}
@@ -154,8 +153,6 @@ void BKE_curve_init(Curve *cu, const short curve_type)
cu->type = curve_type;
cu->bb = BKE_boundbox_alloc_unit();
if (cu->type == OB_FONT) {
cu->flag |= CU_FRONT | CU_BACK;
cu->vfont = cu->vfontb = cu->vfonti = cu->vfontbi = BKE_vfont_builtin_get();
@@ -204,7 +201,6 @@ void BKE_curve_copy_data(Main *bmain, Curve *cu_dst, const Curve *cu_src, const
cu_dst->str = MEM_dupallocN(cu_src->str);
cu_dst->strinfo = MEM_dupallocN(cu_src->strinfo);
cu_dst->tb = MEM_dupallocN(cu_src->tb);
cu_dst->bb = MEM_dupallocN(cu_src->bb);
cu_dst->batch_cache = NULL;
if (cu_src->key && (flag & LIB_ID_COPY_SHAPEKEY)) {
@@ -291,41 +287,6 @@ void BKE_curve_type_test(Object *ob)
}
}
void BKE_curve_boundbox_calc(Curve *cu, float r_loc[3], float r_size[3])
{
BoundBox *bb;
float min[3], max[3];
float mloc[3], msize[3];
if (cu->bb == NULL) {
cu->bb = MEM_callocN(sizeof(BoundBox), "boundbox");
}
bb = cu->bb;
if (!r_loc) {
r_loc = mloc;
}
if (!r_size) {
r_size = msize;
}
INIT_MINMAX(min, max);
if (!BKE_curve_minmax(cu, true, min, max)) {
min[0] = min[1] = min[2] = -1.0f;
max[0] = max[1] = max[2] = 1.0f;
}
mid_v3_v3v3(r_loc, min, max);
r_size[0] = (max[0] - min[0]) / 2.0f;
r_size[1] = (max[1] - min[1]) / 2.0f;
r_size[2] = (max[2] - min[2]) / 2.0f;
BKE_boundbox_init_from_minmax(bb, min, max);
bb->flag &= ~BOUNDBOX_DIRTY;
}
BoundBox *BKE_curve_boundbox_get(Object *ob)
{
/* This is Object-level data access,
@@ -349,13 +310,23 @@ BoundBox *BKE_curve_boundbox_get(Object *ob)
void BKE_curve_texspace_calc(Curve *cu)
{
float loc[3], size[3];
int a;
BKE_curve_boundbox_calc(cu, loc, size);
if (cu->texflag & CU_AUTOSPACE) {
for (a = 0; a < 3; a++) {
float min[3], max[3];
INIT_MINMAX(min, max);
if (!BKE_curve_minmax(cu, true, min, max)) {
min[0] = min[1] = min[2] = -1.0f;
max[0] = max[1] = max[2] = 1.0f;
}
float loc[3], size[3];
mid_v3_v3v3(loc, min, max);
size[0] = (max[0] - min[0]) / 2.0f;
size[1] = (max[1] - min[1]) / 2.0f;
size[2] = (max[2] - min[2]) / 2.0f;
for (int a = 0; a < 3; a++) {
if (size[a] == 0.0f) {
size[a] = 1.0f;
}
@@ -370,14 +341,21 @@ void BKE_curve_texspace_calc(Curve *cu)
copy_v3_v3(cu->loc, loc);
copy_v3_v3(cu->size, size);
zero_v3(cu->rot);
cu->texflag |= CU_AUTOSPACE_EVALUATED;
}
}
BoundBox *BKE_curve_texspace_get(Curve *cu, float r_loc[3], float r_rot[3], float r_size[3])
void BKE_curve_texspace_ensure(Curve *cu)
{
if (cu->bb == NULL || (cu->bb->flag & BOUNDBOX_DIRTY)) {
if ((cu->texflag & CU_AUTOSPACE) && !(cu->texflag & CU_AUTOSPACE_EVALUATED)) {
BKE_curve_texspace_calc(cu);
}
}
void BKE_curve_texspace_get(Curve *cu, float r_loc[3], float r_rot[3], float r_size[3])
{
BKE_curve_texspace_ensure(cu);
if (r_loc) {
copy_v3_v3(r_loc, cu->loc);
@@ -388,8 +366,6 @@ BoundBox *BKE_curve_texspace_get(Curve *cu, float r_loc[3], float r_rot[3], floa
if (r_size) {
copy_v3_v3(r_size, cu->size);
}
return cu->bb;
}
bool BKE_nurbList_index_get_co(ListBase *nurb, const int index, float r_co[3])
@@ -5501,12 +5477,8 @@ void BKE_curve_eval_geometry(Depsgraph *depsgraph, Curve *curve)
BKE_curve_texspace_calc(curve);
if (DEG_is_active(depsgraph)) {
Curve *curve_orig = (Curve *)DEG_get_original_id(&curve->id);
BoundBox *bb = curve->bb;
if (bb != NULL) {
if (curve_orig->bb == NULL) {
curve_orig->bb = MEM_mallocN(sizeof(*curve_orig->bb), __func__);
}
*curve_orig->bb = *bb;
if (curve->texflag & CU_AUTOSPACE_EVALUATED) {
curve_orig->texflag |= CU_AUTOSPACE_EVALUATED;
copy_v3_v3(curve_orig->loc, curve->loc);
copy_v3_v3(curve_orig->size, curve->size);
copy_v3_v3(curve_orig->rot, curve->rot);

View File

@@ -496,7 +496,6 @@ void BKE_mesh_clear_geometry(Mesh *mesh)
CustomData_free(&mesh->ldata, mesh->totloop);
CustomData_free(&mesh->pdata, mesh->totpoly);
MEM_SAFE_FREE(mesh->bb);
MEM_SAFE_FREE(mesh->mselect);
MEM_SAFE_FREE(mesh->edit_mesh);
@@ -605,7 +604,6 @@ void BKE_mesh_copy_data(Main *bmain, Mesh *me_dst, const Mesh *me_src, const int
me_dst->edit_mesh = NULL;
me_dst->mselect = MEM_dupallocN(me_dst->mselect);
me_dst->bb = MEM_dupallocN(me_dst->bb);
/* TODO Do we want to add flag to prevent this? */
if (me_src->key && (flag & LIB_ID_COPY_SHAPEKEY)) {
@@ -811,67 +809,6 @@ void BKE_mesh_make_local(Main *bmain, Mesh *me, const bool lib_local)
BKE_id_make_local_generic(bmain, &me->id, true, lib_local);
}
void BKE_mesh_boundbox_calc(Mesh *me, float r_loc[3], float r_size[3])
{
BoundBox *bb;
float min[3], max[3];
float mloc[3], msize[3];
if (me->bb == NULL) {
me->bb = MEM_callocN(sizeof(BoundBox), "boundbox");
}
bb = me->bb;
if (!r_loc) {
r_loc = mloc;
}
if (!r_size) {
r_size = msize;
}
INIT_MINMAX(min, max);
if (!BKE_mesh_minmax(me, min, max)) {
min[0] = min[1] = min[2] = -1.0f;
max[0] = max[1] = max[2] = 1.0f;
}
mid_v3_v3v3(r_loc, min, max);
r_size[0] = (max[0] - min[0]) / 2.0f;
r_size[1] = (max[1] - min[1]) / 2.0f;
r_size[2] = (max[2] - min[2]) / 2.0f;
BKE_boundbox_init_from_minmax(bb, min, max);
bb->flag &= ~BOUNDBOX_DIRTY;
}
void BKE_mesh_texspace_calc(Mesh *me)
{
float loc[3], size[3];
int a;
BKE_mesh_boundbox_calc(me, loc, size);
if (me->texflag & ME_AUTOSPACE) {
for (a = 0; a < 3; a++) {
if (size[a] == 0.0f) {
size[a] = 1.0f;
}
else if (size[a] > 0.0f && size[a] < 0.00001f) {
size[a] = 0.00001f;
}
else if (size[a] < 0.0f && size[a] > -0.00001f) {
size[a] = -0.00001f;
}
}
copy_v3_v3(me->loc, loc);
copy_v3_v3(me->size, size);
zero_v3(me->rot);
}
}
BoundBox *BKE_mesh_boundbox_get(Object *ob)
{
/* This is Object-level data access,
@@ -896,11 +833,54 @@ BoundBox *BKE_mesh_boundbox_get(Object *ob)
return ob->runtime.bb;
}
BoundBox *BKE_mesh_texspace_get(Mesh *me, float r_loc[3], float r_rot[3], float r_size[3])
void BKE_mesh_texspace_calc(Mesh *me)
{
if (me->bb == NULL || (me->bb->flag & BOUNDBOX_DIRTY)) {
if (me->texflag & ME_AUTOSPACE) {
float min[3], max[3];
INIT_MINMAX(min, max);
if (!BKE_mesh_minmax(me, min, max)) {
min[0] = min[1] = min[2] = -1.0f;
max[0] = max[1] = max[2] = 1.0f;
}
float loc[3], size[3];
mid_v3_v3v3(loc, min, max);
size[0] = (max[0] - min[0]) / 2.0f;
size[1] = (max[1] - min[1]) / 2.0f;
size[2] = (max[2] - min[2]) / 2.0f;
for (int a = 0; a < 3; a++) {
if (size[a] == 0.0f) {
size[a] = 1.0f;
}
else if (size[a] > 0.0f && size[a] < 0.00001f) {
size[a] = 0.00001f;
}
else if (size[a] < 0.0f && size[a] > -0.00001f) {
size[a] = -0.00001f;
}
}
copy_v3_v3(me->loc, loc);
copy_v3_v3(me->size, size);
zero_v3(me->rot);
me->texflag |= ME_AUTOSPACE_EVALUATED;
}
}
void BKE_mesh_texspace_ensure(Mesh *me)
{
if ((me->texflag & ME_AUTOSPACE) && !(me->texflag & ME_AUTOSPACE_EVALUATED)) {
BKE_mesh_texspace_calc(me);
}
}
void BKE_mesh_texspace_get(Mesh *me, float r_loc[3], float r_rot[3], float r_size[3])
{
BKE_mesh_texspace_ensure(me);
if (r_loc) {
copy_v3_v3(r_loc, me->loc);
@@ -911,16 +891,12 @@ BoundBox *BKE_mesh_texspace_get(Mesh *me, float r_loc[3], float r_rot[3], float
if (r_size) {
copy_v3_v3(r_size, me->size);
}
return me->bb;
}
void BKE_mesh_texspace_get_reference(
Mesh *me, short **r_texflag, float **r_loc, float **r_rot, float **r_size)
{
if (me->bb == NULL || (me->bb->flag & BOUNDBOX_DIRTY)) {
BKE_mesh_texspace_calc(me);
}
BKE_mesh_texspace_ensure(me);
if (r_texflag != NULL) {
*r_texflag = &me->texflag;
@@ -1962,12 +1938,8 @@ void BKE_mesh_eval_geometry(Depsgraph *depsgraph, Mesh *mesh)
}
if (DEG_is_active(depsgraph)) {
Mesh *mesh_orig = (Mesh *)DEG_get_original_id(&mesh->id);
BoundBox *bb = mesh->bb;
if (bb != NULL) {
if (mesh_orig->bb == NULL) {
mesh_orig->bb = MEM_mallocN(sizeof(*mesh_orig->bb), __func__);
}
*mesh_orig->bb = *bb;
if (mesh->texflag & ME_AUTOSPACE_EVALUATED) {
mesh_orig->texflag |= ME_AUTOSPACE_EVALUATED;
copy_v3_v3(mesh_orig->loc, mesh->loc);
copy_v3_v3(mesh_orig->size, mesh->size);
copy_v3_v3(mesh_orig->rot, mesh->rot);

View File

@@ -1576,11 +1576,7 @@ void BKE_mesh_nomain_to_mesh(Mesh *mesh_src,
/* Clear selection history */
MEM_SAFE_FREE(tmp.mselect);
tmp.totselect = 0;
BLI_assert(ELEM(tmp.bb, NULL, mesh_dst->bb));
if (mesh_dst->bb) {
MEM_freeN(mesh_dst->bb);
tmp.bb = NULL;
}
tmp.texflag &= ~ME_AUTOSPACE_EVALUATED;
/* skip the listbase */
MEMCPY_STRUCT_AFTER(mesh_dst, &tmp, id.prev);

View File

@@ -3284,9 +3284,7 @@ int BKE_object_obdata_texspace_get(
}
case ID_CU: {
Curve *cu = ob->data;
if (cu->bb == NULL || (cu->bb->flag & BOUNDBOX_DIRTY)) {
BKE_curve_texspace_calc(cu);
}
BKE_curve_texspace_ensure(cu);
if (r_texflag) {
*r_texflag = &cu->texflag;
}

View File

@@ -4068,9 +4068,7 @@ void psys_get_texture(
0,
texvec);
if (me->bb == NULL || (me->bb->flag & BOUNDBOX_DIRTY)) {
BKE_mesh_texspace_calc(me);
}
BKE_mesh_texspace_ensure(me);
sub_v3_v3(texvec, me->loc);
if (me->size[0] != 0.0f) {
texvec[0] /= me->size[0];

View File

@@ -4373,7 +4373,7 @@ static void direct_link_curve(FileData *fd, Curve *cu)
switch_endian_knots(nu);
}
}
cu->bb = NULL;
cu->texflag &= ~CU_AUTOSPACE_EVALUATED;
}
/** \} */
@@ -5040,7 +5040,7 @@ static void direct_link_mesh(FileData *fd, Mesh *mesh)
direct_link_customdata(fd, &mesh->ldata, mesh->totloop);
direct_link_customdata(fd, &mesh->pdata, mesh->totpoly);
mesh->bb = NULL;
mesh->texflag &= ~ME_AUTOSPACE_EVALUATED;
mesh->edit_mesh = NULL;
BKE_mesh_runtime_reset(mesh);

View File

@@ -451,9 +451,7 @@ static void drw_call_calc_orco(Object *ob, float (*r_orcofacs)[4])
break;
case ID_CU: {
Curve *cu = (Curve *)ob_data;
if (cu->bb == NULL || (cu->bb->flag & BOUNDBOX_DIRTY)) {
BKE_curve_texspace_calc(cu);
}
BKE_curve_texspace_ensure(cu);
texcoloc = cu->loc;
texcosize = cu->size;
break;

View File

@@ -3023,9 +3023,7 @@ static void DRW_shgroup_texture_space(OBJECT_ShadingGroupList *sgl, Object *ob,
break;
case ID_CU: {
Curve *cu = (Curve *)ob_data;
if (cu->bb == NULL || (cu->bb->flag & BOUNDBOX_DIRTY)) {
BKE_curve_texspace_calc(cu);
}
BKE_curve_texspace_ensure(cu);
texcoloc = cu->loc;
texcosize = cu->size;
break;

View File

@@ -212,8 +212,6 @@ typedef struct Curve {
/** Animation data (must be immediately after id for utilities to use it). */
struct AnimData *adt;
struct BoundBox *bb;
/** Actual data, called splines in rna. */
ListBase nurb;
@@ -308,6 +306,7 @@ typedef struct Curve {
/* Curve.texflag */
enum {
CU_AUTOSPACE = 1,
CU_AUTOSPACE_EVALUATED = 2,
};
#if 0 /* Moved to overlay options in 2.8 */

View File

@@ -116,8 +116,6 @@ typedef struct Mesh {
/** Animation data (must be immediately after id for utilities to use it). */
struct AnimData *adt;
struct BoundBox *bb;
/** Old animation system, deprecated for 2.5. */
struct Ipo *ipo DNA_DEPRECATED;
struct Key *key;
@@ -218,6 +216,7 @@ typedef struct TFace {
/* texflag */
enum {
ME_AUTOSPACE = 1,
ME_AUTOSPACE_EVALUATED = 2,
};
/* me->editflag */

View File

@@ -291,9 +291,7 @@ static void rna_Curve_texspace_loc_get(PointerRNA *ptr, float *values)
{
Curve *cu = (Curve *)ptr->data;
if (!cu->bb) {
BKE_curve_texspace_calc(cu);
}
BKE_curve_texspace_ensure(cu);
copy_v3_v3(values, cu->loc);
}
@@ -309,9 +307,7 @@ static void rna_Curve_texspace_size_get(PointerRNA *ptr, float *values)
{
Curve *cu = (Curve *)ptr->data;
if (!cu->bb) {
BKE_curve_texspace_calc(cu);
}
BKE_curve_texspace_ensure(cu);
copy_v3_v3(values, cu->size);
}

View File

@@ -503,9 +503,7 @@ static void rna_Mesh_texspace_size_get(PointerRNA *ptr, float values[3])
{
Mesh *me = (Mesh *)ptr->data;
if (me->bb == NULL || (me->bb->flag & BOUNDBOX_DIRTY)) {
BKE_mesh_texspace_calc(me);
}
BKE_mesh_texspace_ensure(me);
copy_v3_v3(values, me->size);
}
@@ -514,9 +512,7 @@ static void rna_Mesh_texspace_loc_get(PointerRNA *ptr, float values[3])
{
Mesh *me = (Mesh *)ptr->data;
if (me->bb == NULL || (me->bb->flag & BOUNDBOX_DIRTY)) {
BKE_mesh_texspace_calc(me);
}
BKE_mesh_texspace_ensure(me);
copy_v3_v3(values, me->loc);
}