[Bf-blender-cvs] [a44093693e6] refactor-mesh-position-generic: Various fixes and cleanups

Hans Goudey noreply at git.blender.org
Thu Nov 17 06:20:04 CET 2022


Commit: a44093693e61c2391b6e721b9deabe8c6e80c17b
Author: Hans Goudey
Date:   Wed Nov 16 23:19:53 2022 -0600
Branches: refactor-mesh-position-generic
https://developer.blender.org/rBa44093693e61c2391b6e721b9deabe8c6e80c17b

Various fixes and cleanups

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

M	source/blender/blenkernel/BKE_bvhutils.h
M	source/blender/blenkernel/BKE_mesh.h
M	source/blender/blenkernel/intern/DerivedMesh.cc
M	source/blender/blenkernel/intern/bvhutils.cc
M	source/blender/blenkernel/intern/cloth.cc
M	source/blender/blenkernel/intern/mesh_evaluate.cc
M	source/blender/blenkernel/intern/mesh_remap.cc
M	source/blender/blenkernel/intern/multires_reshape_apply_base.c
M	source/blender/editors/uvedit/uvedit_unwrap_ops.c
M	source/blender/modifiers/intern/MOD_uvproject.cc

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

diff --git a/source/blender/blenkernel/BKE_bvhutils.h b/source/blender/blenkernel/BKE_bvhutils.h
index 64d53613538..320eb698b20 100644
--- a/source/blender/blenkernel/BKE_bvhutils.h
+++ b/source/blender/blenkernel/BKE_bvhutils.h
@@ -59,7 +59,6 @@ typedef struct BVHTreeFromMesh {
 
   /* Vertex array, so that callbacks have instant access to data. */
   const float (*positions)[3];
-  const float (*vert_normals)[3];
   const struct MEdge *edge;
   const struct MFace *face;
   const struct MLoop *loop;
diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h
index 9e34868e4f3..700274a7872 100644
--- a/source/blender/blenkernel/BKE_mesh.h
+++ b/source/blender/blenkernel/BKE_mesh.h
@@ -697,10 +697,6 @@ void BKE_mesh_calc_poly_normal(const struct MPoly *mpoly,
                                const struct MLoop *loopstart,
                                const float (*positions)[3],
                                float r_no[3]);
-void BKE_mesh_calc_poly_normal_coords(const struct MPoly *mpoly,
-                                      const struct MLoop *loopstart,
-                                      const float (*vertex_coords)[3],
-                                      float r_no[3]);
 void BKE_mesh_calc_poly_center(const struct MPoly *mpoly,
                                const struct MLoop *loopstart,
                                const float (*positions)[3],
diff --git a/source/blender/blenkernel/intern/DerivedMesh.cc b/source/blender/blenkernel/intern/DerivedMesh.cc
index 87eebc22046..1cb28e718c5 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.cc
+++ b/source/blender/blenkernel/intern/DerivedMesh.cc
@@ -669,8 +669,8 @@ static void mesh_calc_modifiers(struct Depsgraph *depsgraph,
 
   BLI_assert((mesh_input->id.tag & LIB_TAG_COPIED_ON_WRITE_EVAL_RESULT) == 0);
 
-  /* TODO: Remove use of "deformed_verts" in mesh modifier stack since mesh positions are now in a
-   * contiguous array. */
+  /* TODO: Remove use of `deformed_verts` in mesh modifier stack
+   * since mesh positions are now stored in a contiguous array. */
   float(*deformed_verts)[3] = nullptr;
   int num_deformed_verts = mesh_input->totvert;
   bool isPrevDeform = false;
@@ -1257,10 +1257,8 @@ static void editbmesh_calc_modifiers(struct Depsgraph *depsgraph,
   /* This geometry set contains the non-mesh data that might be generated by modifiers. */
   GeometrySet geometry_set_final;
 
-  /* Deformed vertex locations array. Deform only modifier need this type of
-   * float array rather than MVert*. Tracked along with mesh_final as an
-   * optimization to avoid copying coordinates back and forth if there are
-   * multiple sequential deform only modifiers. */
+  /* TODO: Remove use of `deformed_verts` in mesh modifier stack
+   * since mesh positions are now stored in a contiguous array. */
   float(*deformed_verts)[3] = nullptr;
   int num_deformed_verts = 0;
   bool isPrevDeform = false;
diff --git a/source/blender/blenkernel/intern/bvhutils.cc b/source/blender/blenkernel/intern/bvhutils.cc
index 7edc8316c07..142ba155372 100644
--- a/source/blender/blenkernel/intern/bvhutils.cc
+++ b/source/blender/blenkernel/intern/bvhutils.cc
@@ -1115,16 +1115,15 @@ BVHTree *bvhtree_from_mesh_looptri_ex(BVHTreeFromMesh *data,
                                       int tree_type,
                                       int axis)
 {
-  BVHTree *tree = nullptr;
-  tree = bvhtree_from_mesh_looptri_create_tree(epsilon,
-                                               tree_type,
-                                               axis,
-                                               positions,
-                                               mloop,
-                                               looptri,
-                                               looptri_num,
-                                               looptri_mask,
-                                               looptri_num_active);
+  BVHTree *tree = bvhtree_from_mesh_looptri_create_tree(epsilon,
+                                                        tree_type,
+                                                        axis,
+                                                        positions,
+                                                        mloop,
+                                                        looptri,
+                                                        looptri_num,
+                                                        looptri_mask,
+                                                        looptri_num_active);
 
   bvhtree_balance(tree, false);
 
@@ -1224,15 +1223,14 @@ BVHTree *BKE_bvhtree_from_mesh_get(struct BVHTreeFromMesh *data,
     looptri = BKE_mesh_runtime_looptri_ensure(mesh);
     looptri_len = BKE_mesh_runtime_looptri_len(mesh);
   }
-  const Span<float3> positions = mesh->positions();
-  const float(*c_positions)[3] = reinterpret_cast<const float(*)[3]>(positions.data());
+  const float(*positions)[3] = reinterpret_cast<const float(*)[3]>(mesh->positions().data());
   const Span<MEdge> edges = mesh->edges();
   const Span<MLoop> loops = mesh->loops();
 
   /* Setup BVHTreeFromMesh */
   bvhtree_from_mesh_setup_data(nullptr,
                                bvh_cache_type,
-                               c_positions,
+                               positions,
                                edges.data(),
                                (const MFace *)CustomData_get_layer(&mesh->fdata, CD_MFACE),
                                loops.data(),
@@ -1260,7 +1258,7 @@ BVHTree *BKE_bvhtree_from_mesh_get(struct BVHTreeFromMesh *data,
       ATTR_FALLTHROUGH;
     case BVHTREE_FROM_VERTS:
       data->tree = bvhtree_from_mesh_verts_create_tree(
-          0.0f, tree_type, 6, c_positions, mesh->totvert, mask, mask_bits_act_len);
+          0.0f, tree_type, 6, positions, mesh->totvert, mask, mask_bits_act_len);
       break;
 
     case BVHTREE_FROM_LOOSEEDGES:
@@ -1268,7 +1266,7 @@ BVHTree *BKE_bvhtree_from_mesh_get(struct BVHTreeFromMesh *data,
       ATTR_FALLTHROUGH;
     case BVHTREE_FROM_EDGES:
       data->tree = bvhtree_from_mesh_edges_create_tree(
-          c_positions, edges.data(), mesh->totedge, mask, mask_bits_act_len, 0.0f, tree_type, 6);
+          positions, edges.data(), mesh->totedge, mask, mask_bits_act_len, 0.0f, tree_type, 6);
       break;
 
     case BVHTREE_FROM_FACES:
@@ -1277,7 +1275,7 @@ BVHTree *BKE_bvhtree_from_mesh_get(struct BVHTreeFromMesh *data,
           0.0f,
           tree_type,
           6,
-          c_positions,
+          positions,
           (const MFace *)CustomData_get_layer(&mesh->fdata, CD_MFACE),
           mesh->totface,
           {},
@@ -1297,7 +1295,7 @@ BVHTree *BKE_bvhtree_from_mesh_get(struct BVHTreeFromMesh *data,
       data->tree = bvhtree_from_mesh_looptri_create_tree(0.0f,
                                                          tree_type,
                                                          6,
-                                                         c_positions,
+                                                         positions,
                                                          loops.data(),
                                                          looptri,
                                                          looptri_len,
diff --git a/source/blender/blenkernel/intern/cloth.cc b/source/blender/blenkernel/intern/cloth.cc
index 0b21dec3f4e..b0eaee8e761 100644
--- a/source/blender/blenkernel/intern/cloth.cc
+++ b/source/blender/blenkernel/intern/cloth.cc
@@ -247,6 +247,7 @@ static bool do_init_cloth(Object *ob, ClothModifierData *clmd, Mesh *result, int
 static int do_step_cloth(
     Depsgraph *depsgraph, Object *ob, ClothModifierData *clmd, Mesh *result, int framenr)
 {
+  using namespace blender;
   /* simulate 1 frame forward */
   ClothVertex *verts = nullptr;
   Cloth *cloth;
@@ -257,7 +258,7 @@ static int do_step_cloth(
 
   cloth = clmd->clothObject;
   verts = cloth->verts;
-  const float(*positions)[3] = BKE_mesh_positions(result);
+  const Span<float3> positions = result->positions();
   vert_mass_changed = verts->mass != clmd->sim_parms->mass;
 
   /* force any pinned verts to their constrained location. */
@@ -714,6 +715,7 @@ static float cloth_shrink_factor(ClothModifierData *clmd, ClothVertex *verts, in
 static bool cloth_from_object(
     Object *ob, ClothModifierData *clmd, Mesh *mesh, float UNUSED(framenr), int first)
 {
+  using namespace blender;
   int i = 0;
   ClothVertex *verts = nullptr;
   const float(*shapekey_rest)[3] = nullptr;
@@ -757,7 +759,7 @@ static bool cloth_from_object(
         CustomData_get_layer(&mesh->vdata, CD_CLOTH_ORCO));
   }
 
-  const float(*positions)[3] = BKE_mesh_positions(mesh);
+  const Span<float3> positions = mesh->positions();
 
   verts = clmd->clothObject->verts;
 
@@ -1151,8 +1153,9 @@ static void cloth_update_springs(ClothModifierData *clmd)
 /* Update rest verts, for dynamically deformable cloth */
 static void cloth_update_verts(Object *ob, ClothModifierData *clmd, Mesh *mesh)
 {
+  using namespace blender;
   uint i = 0;
-  const float(*positions)[3] = BKE_mesh_positions(mesh);
+  const Span<float3> positions = mesh->positions();
   ClothVertex *verts = clmd->clothObject->verts;
 
   /* vertex count is already ensured to match */
@@ -1165,9 +1168,10 @@ static void cloth_update_verts(Object *ob, ClothModifierData *clmd, Mesh *mesh)
 /* Write rest vert locations to a copy of the mesh. */
 static Mesh *cloth_make_rest_mesh(ClothModifierData *clmd, Mesh *mesh)
 {
+  using namespace blender;
   Mesh *new_mesh = BKE_mesh_copy_for_eval(mesh, false);
   ClothVertex *verts = clmd->clothObject->verts;
-  float(*positions)[3] = BKE_mesh_positions_for_write(mesh);
+  MutableSpan<float3> positions = mesh->positions_for_write();
 
   /* vertex count is already ensured to match */
   for (int i = 0; i < mesh->totvert; i++, verts++) {
@@ -1388,7 +1392,7 @@ static bool find_internal_spring_target_vertex(BVHTreeFromMesh *treedata,
   float radius;
 
   copy_v3_v3(co, treedata->positions[v_idx]);
-  negate_v3_v3(no, treedata->vert_normals[v_idx]);
+  negate_v3_v3(no, vert_normals[v_idx]);
 
   float vec_len = sin(max_diversion);
   float offset[3];
diff -

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list