[Bf-blender-cvs] [92081461990] master: Cleanup: remove Mesh.bb and Curve.bb, no reason for these to be persistent

Brecht Van Lommel noreply at git.blender.org
Mon Sep 23 16:28:00 CEST 2019


Commit: 9208146199019e111711f077abcda31f976cabcc
Author: Brecht Van Lommel
Date:   Mon Sep 23 15:31:11 2019 +0200
Branches: master
https://developer.blender.org/rB9208146199019e111711f077abcda31f976cabcc

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.

===================================================================

M	source/blender/blenkernel/BKE_curve.h
M	source/blender/blenkernel/BKE_mesh.h
M	source/blender/blenkernel/intern/curve.c
M	source/blender/blenkernel/intern/mesh.c
M	source/blender/blenkernel/intern/mesh_convert.c
M	source/blender/blenkernel/intern/object.c
M	source/blender/blenkernel/intern/particle.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/draw/intern/draw_manager_data.c
M	source/blender/draw/modes/object_mode.c
M	source/blender/makesdna/DNA_curve_types.h
M	source/blender/makesdna/DNA_mesh_types.h
M	source/blender/makesrna/intern/rna_curve.c
M	source/blender/makesrna/intern/rna_mesh.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_curve.h b/source/blender/blenkernel/BKE_curve.h
index aeff6007292..98712af82e9 100644
--- a/source/blender/blenkernel/BKE_curve.h
+++ b/source/blender/blenkernel/BKE_curve.h
@@ -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]);
diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h
index af40eef6ab5..fe45530e01e 100644
--- a/source/blender/blenkernel/BKE_mesh.h
+++ b/source/blender/blenkernel/BKE_mesh.h
@@ -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);
diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c
index 67b0aaffc4a..a9d98c726c9 100644
--- a/source/blender/blenkernel/intern/curve.c
+++ b/source/blender/blenkernel/intern/curve.c
@@ -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;
+  if (cu->texflag & CU_AUTOSPACE) {
+    float min[3], max[3];
 
-  BKE_curve_boundbox_calc(cu, loc, size);
+    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;
+    }
 
-  if (cu->texflag & CU_AUTOSPACE) {
-    for (a = 0; a < 3; a++) {
+    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);
diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c
index c108ff90850..e451ca06cba 100644
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@ -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,50 +809,49 @@ 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 *BKE_mesh_boundbox_get(Object *ob)
 {
-  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;
+  /* This is Object-level data access,
+   * DO NOT touch to Mesh's bb, would be totally thread-unsafe. */
+  if (ob->runtime.bb == NULL || ob->runtime.bb->flag & BOUNDBOX_DIRTY) {
+    Mesh *me = ob->data;
+    float min[3], max[3];
 
-  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;
+    }
 
-  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;
+    if (ob->runtime.bb == NULL) {
+      ob->runtime.bb = MEM_mallocN(sizeof(*ob->runtime.bb), __func__);
+    }
+    BKE_boundbox_init_from_minmax(ob->runtime.bb, min, max);
+    ob->runtime.bb->flag &= ~BOUNDBOX_DIRTY;
   }
 
-  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;
+  return ob->runtime.bb;
 }
 
 void BKE_mesh_texspace_calc(Mesh *me)
 {
-  float loc[3], size[3];
-  int a;
+  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;
+    }
 
-  BKE_mesh_boundbox_calc(me, loc, size);
+    float loc[3], size[3];
+    mid_v3_v3v3(loc, min, max);
 
-  if (me->texflag & ME_AUTOSPACE) {
-    for (a = 0; a < 3; a++) {
+    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;
       }
@@ -869,38 +866,2

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list