[Bf-blender-cvs] [b7d20abaff8] temp-vert-normals-cleanup: Many fixes and code cleanups

Hans Goudey noreply at git.blender.org
Wed Oct 6 20:09:09 CEST 2021


Commit: b7d20abaff8e7c93172f2bfbd7d9714947994993
Author: Hans Goudey
Date:   Wed Oct 6 13:09:00 2021 -0500
Branches: temp-vert-normals-cleanup
https://developer.blender.org/rBb7d20abaff8e7c93172f2bfbd7d9714947994993

Many fixes and code cleanups

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

M	source/blender/blenkernel/BKE_mesh.h
M	source/blender/blenkernel/BKE_shrinkwrap.h
M	source/blender/blenkernel/intern/DerivedMesh.cc
M	source/blender/blenkernel/intern/customdata.c
M	source/blender/blenkernel/intern/fluid.c
M	source/blender/blenkernel/intern/geometry_component_mesh.cc
M	source/blender/blenkernel/intern/geometry_set_instances.cc
M	source/blender/blenkernel/intern/gpencil_geom.cc
M	source/blender/blenkernel/intern/mesh.c
M	source/blender/blenkernel/intern/mesh_convert.cc
M	source/blender/blenkernel/intern/mesh_normals.cc
M	source/blender/blenkernel/intern/mesh_runtime.c
M	source/blender/blenkernel/intern/mesh_tangent.c
M	source/blender/blenkernel/intern/mesh_validate.c
M	source/blender/blenkernel/intern/modifier.c
M	source/blender/blenkernel/intern/object_update.c
M	source/blender/blenkernel/intern/pbvh.c
M	source/blender/blenkernel/intern/shrinkwrap.c
M	source/blender/blenkernel/intern/subdiv_eval.c
M	source/blender/blenkernel/intern/subdiv_mesh.c
M	source/blender/blenkernel/intern/subsurf_ccg.c
M	source/blender/bmesh/intern/bmesh_log.c
M	source/blender/bmesh/intern/bmesh_log.h
M	source/blender/bmesh/intern/bmesh_mesh_convert.c
M	source/blender/draw/intern/draw_cache_extract_mesh_render_data.c
M	source/blender/draw/intern/mesh_extractors/extract_mesh.h
M	source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_mesh_analysis.cc
M	source/blender/editors/armature/meshlaplacian.c
M	source/blender/editors/mesh/mesh_data.c
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/editors/sculpt_paint/sculpt_boundary.c
M	source/blender/editors/sculpt_paint/sculpt_filter_mesh.c
M	source/blender/editors/sculpt_paint/sculpt_intern.h
M	source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp
M	source/blender/io/alembic/exporter/abc_writer_hair.cc
M	source/blender/io/alembic/intern/abc_reader_mesh.cc
M	source/blender/io/alembic/intern/abc_reader_points.cc
M	source/blender/io/usd/intern/usd_reader_mesh.cc
M	source/blender/io/usd/intern/usd_writer_mesh.cc
M	source/blender/makesdna/DNA_mesh_types.h
M	source/blender/modifiers/intern/MOD_array.c
M	source/blender/modifiers/intern/MOD_build.c
M	source/blender/modifiers/intern/MOD_explode.c
M	source/blender/modifiers/intern/MOD_normal_edit.c
M	source/blender/modifiers/intern/MOD_screw.c
M	source/blender/modifiers/intern/MOD_wave.c
M	source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_circle.cc
M	source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_grid.cc
M	source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc
M	source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_uv_sphere.cc
M	source/blender/render/intern/texture_pointdensity.c

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

diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h
index 0066c22bd05..4b7ad4f3fa4 100644
--- a/source/blender/blenkernel/BKE_mesh.h
+++ b/source/blender/blenkernel/BKE_mesh.h
@@ -282,15 +282,9 @@ void BKE_mesh_calc_normals_poly(const struct MVert *mvert,
                                 const struct MPoly *mpoly,
                                 int mpoly_len,
                                 float (*r_poly_normals)[3]);
-void BKE_mesh_calc_normals_poly_and_vertex(struct MVert *mvert,
-                                           int mvert_len,
-                                           const struct MLoop *mloop,
-                                           int mloop_len,
-                                           const struct MPoly *mpolys,
-                                           int mpoly_len,
-                                           float (*r_poly_normals)[3],
-                                           float (*r_vert_normals)[3]);
 void BKE_mesh_calc_normals(struct Mesh *me);
+float (*BKE_mesh_vertex_normals_for_write(struct Mesh *mesh))[3];
+float (*BKE_mesh_face_normals_for_write(struct Mesh *mesh))[3];
 const float (*BKE_mesh_ensure_vertex_normals(const struct Mesh *mesh))[3];
 const float (*BKE_mesh_ensure_face_normals(const struct Mesh *mesh))[3];
 void BKE_mesh_ensure_normals_for_display(struct Mesh *mesh);
diff --git a/source/blender/blenkernel/BKE_shrinkwrap.h b/source/blender/blenkernel/BKE_shrinkwrap.h
index 70aeb37d995..22da681117b 100644
--- a/source/blender/blenkernel/BKE_shrinkwrap.h
+++ b/source/blender/blenkernel/BKE_shrinkwrap.h
@@ -84,7 +84,7 @@ typedef struct ShrinkwrapTreeData {
   BVHTree *bvh;
   BVHTreeFromMesh treeData;
 
-  float (*pnors)[3];
+  const float (*pnors)[3];
   float (*clnors)[3];
   ShrinkwrapBoundaryData *boundary;
 } ShrinkwrapTreeData;
diff --git a/source/blender/blenkernel/intern/DerivedMesh.cc b/source/blender/blenkernel/intern/DerivedMesh.cc
index ffca219fbb6..c7cd84963d4 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.cc
+++ b/source/blender/blenkernel/intern/DerivedMesh.cc
@@ -796,6 +796,26 @@ static void add_orco_mesh(Object *ob, BMEditMesh *em, Mesh *mesh, Mesh *mesh_orc
   }
 }
 
+static void assert_normals_dirty_or_calculated(const Mesh &mesh)
+{
+  if (!(mesh.runtime.cd_dirty_vert & CD_MASK_NORMAL)) {
+    if (!CustomData_has_layer(&mesh.vdata, CD_NORMAL)) {
+      Mesh *me = const_cast<Mesh *>(&mesh);
+      MEM_freeN(me);
+      MEM_freeN(me);
+    }
+    BLI_assert(CustomData_has_layer(&mesh.vdata, CD_NORMAL));
+  }
+  if (!(mesh.runtime.cd_dirty_poly & CD_MASK_NORMAL)) {
+    if (!CustomData_has_layer(&mesh.pdata, CD_NORMAL)) {
+      Mesh *me = const_cast<Mesh *>(&mesh);
+      MEM_freeN(me);
+      MEM_freeN(me);
+    }
+    BLI_assert(CustomData_has_layer(&mesh.vdata, CD_NORMAL));
+  }
+}
+
 static void mesh_calc_modifier_final_normals(const Mesh *mesh_input,
                                              const CustomData_MeshMasks *final_datamask,
                                              const bool sculpt_dyntopo,
@@ -804,28 +824,6 @@ static void mesh_calc_modifier_final_normals(const Mesh *mesh_input,
   /* Compute normals. */
   const bool do_loop_normals = ((mesh_input->flag & ME_AUTOSMOOTH) != 0 ||
                                 (final_datamask->lmask & CD_MASK_NORMAL) != 0);
-  /* Some modifiers may need this info from their target (other) object,
-   * simpler to generate it here as well.
-   * Note that they will always be generated when no loop normals are computed,
-   * since they are needed by drawing code. */
-  const bool do_poly_normals = ((final_datamask->pmask & CD_MASK_NORMAL) != 0);
-
-  /* In case we also need poly normals, add the layer and compute them here
-   * (BKE_mesh_calc_normals_split() assumes that if that data exists, it is always valid). */
-  if (do_poly_normals) {
-    if (!CustomData_has_layer(&mesh_final->pdata, CD_NORMAL)) {
-      float(*polynors)[3] = (float(*)[3])CustomData_add_layer(
-          &mesh_final->pdata, CD_NORMAL, CD_CALLOC, nullptr, mesh_final->totpoly);
-      BKE_mesh_calc_normals_poly_and_vertex(mesh_final->mvert,
-                                            mesh_final->totvert,
-                                            mesh_final->mloop,
-                                            mesh_final->totloop,
-                                            mesh_final->mpoly,
-                                            mesh_final->totpoly,
-                                            polynors,
-                                            nullptr);
-    }
-  }
 
   if (do_loop_normals) {
     /* Compute loop normals (NOTE: will compute poly and vert normals as well, if needed!). */
@@ -843,11 +841,7 @@ static void mesh_calc_modifier_final_normals(const Mesh *mesh_input,
      * normals and will also have to calculate normals on the fly, try avoid
      * this where possible since calculating polygon normals isn't fast,
      * note that this isn't a problem for subsurf (only quads) or editmode
-     * which deals with drawing differently.
-     *
-     * Only calc vertex normals if they are flagged as dirty.
-     * If using loop normals, poly nors have already been computed.
-     */
+     * which deals with drawing differently. */
     if (!do_loop_normals) {
       BKE_mesh_ensure_normals_for_display(mesh_final);
     }
@@ -986,6 +980,7 @@ static void mesh_calc_modifiers(struct Depsgraph *depsgraph,
    * constructive modifier is executed, or a deform modifier needs normals
    * or certain data layers. */
   Mesh *mesh_input = (Mesh *)ob->data;
+  assert_normals_dirty_or_calculated(*mesh_input);
   Mesh *mesh_final = nullptr;
   Mesh *mesh_deform = nullptr;
   /* This geometry set contains the non-mesh data that might be generated by modifiers. */
@@ -1525,26 +1520,6 @@ static void editbmesh_calc_modifier_final_normals(Mesh *mesh_final,
 
   const bool do_loop_normals = ((mesh_final->flag & ME_AUTOSMOOTH) != 0 ||
                                 (final_datamask->lmask & CD_MASK_NORMAL) != 0);
-  /* Some modifiers may need this info from their target (other) object,
-   * simpler to generate it here as well. */
-  const bool do_poly_normals = ((final_datamask->pmask & CD_MASK_NORMAL) != 0);
-
-  /* In case we also need poly normals, add the layer and compute them here
-   * (BKE_mesh_calc_normals_split() assumes that if that data exists, it is always valid). */
-  if (do_poly_normals) {
-    if (!CustomData_has_layer(&mesh_final->pdata, CD_NORMAL)) {
-      float(*polynors)[3] = (float(*)[3])CustomData_add_layer(
-          &mesh_final->pdata, CD_NORMAL, CD_CALLOC, nullptr, mesh_final->totpoly);
-      BKE_mesh_calc_normals_poly_and_vertex(mesh_final->mvert,
-                                            mesh_final->totvert,
-                                            mesh_final->mloop,
-                                            mesh_final->totloop,
-                                            mesh_final->mpoly,
-                                            mesh_final->totpoly,
-                                            polynors,
-                                            nullptr);
-    }
-  }
 
   if (do_loop_normals) {
     /* Compute loop normals */
@@ -1875,14 +1850,6 @@ static void mesh_build_extra_data(struct Depsgraph *depsgraph, Object *ob, Mesh
   }
 }
 
-static void mesh_runtime_check_normals_valid(const Mesh *mesh)
-{
-  UNUSED_VARS_NDEBUG(mesh);
-  BLI_assert(!(mesh->runtime.cd_dirty_vert & CD_MASK_NORMAL));
-  BLI_assert(!(mesh->runtime.cd_dirty_loop & CD_MASK_NORMAL));
-  BLI_assert(!(mesh->runtime.cd_dirty_poly & CD_MASK_NORMAL));
-}
-
 static void mesh_build_data(struct Depsgraph *depsgraph,
                             Scene *scene,
                             Object *ob,
@@ -1957,7 +1924,6 @@ static void mesh_build_data(struct Depsgraph *depsgraph,
     }
   }
 
-  mesh_runtime_check_normals_valid(mesh_eval);
   mesh_build_extra_data(depsgraph, ob, mesh_eval);
 }
 
@@ -1990,8 +1956,6 @@ static void editbmesh_build_data(struct Depsgraph *depsgraph,
   BKE_object_boundbox_calc_from_mesh(obedit, em->mesh_eval_final);
 
   em->lastDataMask = *dataMask;
-
-  mesh_runtime_check_normals_valid(em->mesh_eval_final);
 }
 
 static void object_get_datamask(const Depsgraph *depsgraph,
diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c
index 3bb02e1856b..5eac252483f 100644
--- a/source/blender/blenkernel/intern/customdata.c
+++ b/source/blender/blenkernel/intern/customdata.c
@@ -1933,13 +1933,13 @@ const CustomData_MeshMasks CD_MASK_BAREMESH_ORIGINDEX = {
 };
 const CustomData_MeshMasks CD_MASK_MESH = {
     .vmask = (CD_MASK_MVERT | CD_MASK_MDEFORMVERT | CD_MASK_MVERT_SKIN | CD_MASK_PAINT_MASK |
-              CD_MASK_PROP_ALL | CD_MASK_PROP_COLOR),
+              CD_MASK_PROP_ALL | CD_MASK_PROP_COLOR | CD_MASK_NORMAL),
     .emask = (CD_MASK_MEDGE | CD_MASK_FREESTYLE_EDGE | CD_MASK_PROP_ALL),
     .fmask = 0,
     .lmask = (CD_MASK_MLOOP | CD_MASK_MDISPS | CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL |
               CD_MASK_CUSTOMLOOPNORMAL | CD_MASK_GRID_PAINT_MASK | CD_MASK_PROP_ALL),
     .pmask = (CD_MASK_MPOLY | CD_MASK_FACEMAP | CD_MASK_FREESTYLE_FACE | CD_MASK_PROP_ALL |
-              CD_MASK_SCULPT_FACE_SETS),
+              CD_MASK_SCULPT_FACE_SETS | CD_MASK_NORMAL),
 };
 const CustomData_MeshMasks CD_MASK_EDITMESH = {
     .vmask = (CD_MASK_MDEFORMVERT | CD_MASK_PAINT_MASK | CD_MASK_MVERT_SKIN | CD_MASK_SHAPEKEY |
diff --git a/source/blender/blenkernel/intern/fluid.c b/source/blender/blenkernel/intern/fluid.c
index 189a4edce48..5ad9ca815e8 100644
--- a/source/blender/blenkernel/intern/fluid.c
+++ b/source/blender/blenkernel/intern/fluid.c
@@ -1056,7 +1056,6 @@ static void obstacles_from_mesh(Object *coll_ob,
     BKE_mesh_ensure_vertex_normals(me);
     float(*vert_normals)[3] = (float(*)[3])CustomData_get_layer(&me->vdata, CD_NORMAL);
     for (i = 0; i < numverts; i++) {
-      float n[3];
       float co[3];
 
       /* Vertex position. */
@@ -2143,8 +2142,6 @@ static void emit_from_mesh(
     BKE_mesh_ensure_vertex_normals(me);
     float(*vert_normals)[3] = (float(*)[3])CustomData_get_layer(&me->vdata

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list