[Bf-blender-cvs] [f11401d32a3] master: Cleanup: Deduplicate Alembic procedural bounding box mesh creation

Hans Goudey noreply at git.blender.org
Tue May 17 09:42:12 CEST 2022


Commit: f11401d32a30ddbfa775177b67ad78100dc6c5ea
Author: Hans Goudey
Date:   Tue May 17 09:41:32 2022 +0200
Branches: master
https://developer.blender.org/rBf11401d32a30ddbfa775177b67ad78100dc6c5ea

Cleanup: Deduplicate Alembic procedural bounding box mesh creation

This removes the manual construction of a box mesh in the mesh sequence
cache modifier when the Alembic procedural is enabled. It also removes
the use of `BKE_object_boundbox_get` which doesn't make sense on a
non-evaluated object.

Differential Revision: https://developer.blender.org/D14958

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

M	source/blender/geometry/GEO_mesh_primitive_cuboid.hh
M	source/blender/geometry/intern/mesh_primitive_cuboid.cc
M	source/blender/modifiers/intern/MOD_meshsequencecache.cc

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

diff --git a/source/blender/geometry/GEO_mesh_primitive_cuboid.hh b/source/blender/geometry/GEO_mesh_primitive_cuboid.hh
index d9901db9f15..6107b15b62d 100644
--- a/source/blender/geometry/GEO_mesh_primitive_cuboid.hh
+++ b/source/blender/geometry/GEO_mesh_primitive_cuboid.hh
@@ -16,4 +16,6 @@ namespace blender::geometry {
 Mesh *create_cuboid_mesh(
     const float3 &size, int verts_x, int verts_y, int verts_z, const bke::AttributeIDRef &uv_id);
 
+Mesh *create_cuboid_mesh(const float3 &size, int verts_x, int verts_y, int verts_z);
+
 }  // namespace blender::geometry
diff --git a/source/blender/geometry/intern/mesh_primitive_cuboid.cc b/source/blender/geometry/intern/mesh_primitive_cuboid.cc
index e41516d0486..07ac2419ad9 100644
--- a/source/blender/geometry/intern/mesh_primitive_cuboid.cc
+++ b/source/blender/geometry/intern/mesh_primitive_cuboid.cc
@@ -420,4 +420,12 @@ Mesh *create_cuboid_mesh(const float3 &size,
   return mesh;
 }
 
+Mesh *create_cuboid_mesh(const float3 &size,
+                         const int verts_x,
+                         const int verts_y,
+                         const int verts_z)
+{
+  return create_cuboid_mesh(size, verts_x, verts_y, verts_z, {});
+}
+
 }  // namespace blender::geometry
diff --git a/source/blender/modifiers/intern/MOD_meshsequencecache.cc b/source/blender/modifiers/intern/MOD_meshsequencecache.cc
index 998fb0a94a3..273050eafd8 100644
--- a/source/blender/modifiers/intern/MOD_meshsequencecache.cc
+++ b/source/blender/modifiers/intern/MOD_meshsequencecache.cc
@@ -5,8 +5,9 @@
  */
 
 #include <cstring>
+#include <limits>
 
-#include "BLI_math_vector.h"
+#include "BLI_math_vector.hh"
 #include "BLI_string.h"
 #include "BLI_utildefines.h"
 
@@ -15,7 +16,6 @@
 #include "DNA_cachefile_types.h"
 #include "DNA_defaults.h"
 #include "DNA_mesh_types.h"
-#include "DNA_meshdata_types.h"
 #include "DNA_modifier_types.h"
 #include "DNA_object_types.h"
 #include "DNA_scene_types.h"
@@ -42,6 +42,8 @@
 #include "DEG_depsgraph_build.h"
 #include "DEG_depsgraph_query.h"
 
+#include "GEO_mesh_primitive_cuboid.hh"
+
 #include "MOD_modifiertypes.h"
 #include "MOD_ui_common.h"
 
@@ -104,40 +106,17 @@ static bool isDisabled(const struct Scene *UNUSED(scene),
   return (mcmd->cache_file == nullptr) || (mcmd->object_path[0] == '\0');
 }
 
-static Mesh *generate_bounding_box_mesh(Object *object, Mesh *org_mesh)
+static Mesh *generate_bounding_box_mesh(const Mesh *org_mesh)
 {
-  const BoundBox *bb = BKE_object_boundbox_get(object);
-  Mesh *result = BKE_mesh_new_nomain_from_template(org_mesh, 8, 0, 0, 24, 6);
-
-  MVert *mvert = result->mvert;
-  for (int i = 0; i < 8; ++i) {
-    copy_v3_v3(mvert[i].co, bb->vec[i]);
-  }
-
-  /* See DNA_object_types.h for the diagram showing the order of the vertices for a BoundBox. */
-  static unsigned int loops_v[6][4] = {
-      {0, 4, 5, 1},
-      {4, 7, 6, 5},
-      {7, 3, 2, 6},
-      {3, 0, 1, 2},
-      {1, 5, 6, 2},
-      {3, 7, 4, 0},
-  };
-
-  MLoop *mloop = result->mloop;
-  for (int i = 0; i < 6; ++i) {
-    for (int j = 0; j < 4; ++j, ++mloop) {
-      mloop->v = loops_v[i][j];
-    }
-  }
-
-  MPoly *mpoly = result->mpoly;
-  for (int i = 0; i < 6; ++i) {
-    mpoly[i].loopstart = i * 4;
-    mpoly[i].totloop = 4;
+  using namespace blender;
+  float3 min(std::numeric_limits<float>::max());
+  float3 max(-std::numeric_limits<float>::max());
+  if (!BKE_mesh_minmax(org_mesh, min, max)) {
+    return nullptr;
   }
 
-  BKE_mesh_calc_edges(result, false, false);
+  Mesh *result = geometry::create_cuboid_mesh(max - min, 2, 2, 2);
+  BKE_mesh_translate(result, math::midpoint(min, max), false);
 
   return result;
 }
@@ -170,7 +149,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
   /* Do not process data if using a render procedural, return a box instead for displaying in the
    * viewport. */
   if (BKE_cache_file_uses_render_procedural(cache_file, scene)) {
-    return generate_bounding_box_mesh(ctx->object, org_mesh);
+    return generate_bounding_box_mesh(org_mesh);
   }
 
   /* If this invocation is for the ORCO mesh, and the mesh hasn't changed topology, we



More information about the Bf-blender-cvs mailing list