[Bf-blender-cvs] [1442711908f] refactor-mesh-sharp-face-generic: Branch compiling

Hans Goudey noreply at git.blender.org
Thu Jan 5 18:50:54 CET 2023


Commit: 1442711908f0e34d96fe5801823dda898f68398e
Author: Hans Goudey
Date:   Thu Jan 5 12:50:46 2023 -0500
Branches: refactor-mesh-sharp-face-generic
https://developer.blender.org/rB1442711908f0e34d96fe5801823dda898f68398e

Branch compiling

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

M	intern/cycles/blender/mesh.cpp
M	source/blender/blenkernel/BKE_mesh_legacy_convert.h
M	source/blender/blenkernel/BKE_mesh_mapping.h
M	source/blender/blenkernel/intern/fluid.c
M	source/blender/blenkernel/intern/key.cc
M	source/blender/blenkernel/intern/mesh.cc
M	source/blender/blenkernel/intern/mesh_boolean_convert.cc
M	source/blender/blenkernel/intern/mesh_legacy_convert.cc
M	source/blender/blenkernel/intern/mesh_mapping.cc
M	source/blender/blenkernel/intern/mesh_mirror.cc
M	source/blender/blenkernel/intern/mesh_remap.cc
M	source/blender/blenkernel/intern/pbvh.c
M	source/blender/blenkernel/intern/subdiv_ccg_material.c
M	source/blender/blenkernel/intern/subsurf_ccg.c
M	source/blender/blenloader/intern/versioning_400.cc
M	source/blender/draw/intern/draw_cache_extract_mesh_render_data.cc
M	source/blender/draw/intern/draw_pbvh.cc
M	source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_tan.cc
M	source/blender/editors/mesh/mesh_data.cc
M	source/blender/editors/sculpt_paint/paint_image_proj.cc
M	source/blender/io/collada/MeshImporter.cpp
M	source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc
M	source/blender/makesdna/DNA_meshdata_types.h
M	source/blender/makesdna/intern/dna_rename_defs.h
M	source/blender/makesrna/intern/rna_mesh.c
M	source/blender/makesrna/intern/rna_mesh_api.c
M	source/blender/modifiers/intern/MOD_normal_edit.cc
M	source/blender/modifiers/intern/MOD_solidify_extrude.c
M	source/blender/modifiers/intern/MOD_solidify_nonmanifold.c
M	source/blender/modifiers/intern/MOD_weighted_normal.cc
M	source/blender/nodes/geometry/nodes/node_geo_extrude_mesh.cc

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

diff --git a/intern/cycles/blender/mesh.cpp b/intern/cycles/blender/mesh.cpp
index 234488794ed..aaf89e4218f 100644
--- a/intern/cycles/blender/mesh.cpp
+++ b/intern/cycles/blender/mesh.cpp
@@ -895,7 +895,7 @@ static std::optional<BL::IntAttribute> find_material_index_attribute(BL::Mesh b_
   return std::nullopt;
 }
 
-static std::optional<BL::IntAttribute> find_sharp_face_attribute(BL::Mesh b_mesh)
+static std::optional<BL::BoolAttribute> find_sharp_face_attribute(BL::Mesh b_mesh)
 {
   for (BL::Attribute &b_attribute : b_mesh.attributes) {
     if (b_attribute.domain() != BL::Attribute::domain_FACE) {
@@ -1011,13 +1011,10 @@ static void create_mesh(Scene *scene,
     return 0;
   };
 
-
   /* create faces */
-  const MPoly *polys = static_cast<const MPoly *>(b_mesh.polygons[0].ptr.data);
   if (!subdivision) {
     for (BL::MeshLoopTriangle &t : b_mesh.loop_triangles) {
       const int poly_index = t.polygon_index();
-      const MPoly &b_poly = polys[poly_index];
       int3 vi = get_int3(t.vertices());
 
       int shader = get_material_index(poly_index);
@@ -1041,13 +1038,14 @@ static void create_mesh(Scene *scene,
   else {
     vector<int> vi;
 
+    const MPoly *polys = static_cast<const MPoly *>(b_mesh.polygons[0].ptr.data);
     const MLoop *loops = static_cast<const MLoop *>(b_mesh.loops[0].ptr.data);
 
     for (int i = 0; i < numfaces; i++) {
       const MPoly &b_poly = polys[i];
       int n = b_poly.totloop;
       int shader = get_material_index(i);
-      bool smooth = !get_face_sharp(poly_index) || use_loop_normals;
+      bool smooth = !get_face_sharp(i) || use_loop_normals;
 
       vi.resize(n);
       for (int i = 0; i < n; i++) {
diff --git a/source/blender/blenkernel/BKE_mesh_legacy_convert.h b/source/blender/blenkernel/BKE_mesh_legacy_convert.h
index 65804e9ac24..6e7a5833281 100644
--- a/source/blender/blenkernel/BKE_mesh_legacy_convert.h
+++ b/source/blender/blenkernel/BKE_mesh_legacy_convert.h
@@ -24,6 +24,9 @@ struct MFace;
 
 #ifdef __cplusplus
 
+void BKE_mesh_sharp_faces_to_flags(struct Mesh *mesh);
+void BKE_mesh_sharp_faces_from_flags(struct Mesh *mesh);
+
 /**
  * Move face sets to the legacy type from a generic type.
  */
diff --git a/source/blender/blenkernel/BKE_mesh_mapping.h b/source/blender/blenkernel/BKE_mesh_mapping.h
index b49d61ac0a8..48b38537959 100644
--- a/source/blender/blenkernel/BKE_mesh_mapping.h
+++ b/source/blender/blenkernel/BKE_mesh_mapping.h
@@ -322,6 +322,7 @@ bool BKE_mesh_calc_islands_loop_poly_uvmap(struct MVert *verts,
 int *BKE_mesh_calc_smoothgroups(const struct MEdge *medge,
                                 int totedge,
                                 const struct MPoly *mpoly,
+                                const bool *sharp_faces,
                                 int totpoly,
                                 const struct MLoop *mloop,
                                 int totloop,
diff --git a/source/blender/blenkernel/intern/fluid.c b/source/blender/blenkernel/intern/fluid.c
index c72f498cd5a..e76a6eb8de0 100644
--- a/source/blender/blenkernel/intern/fluid.c
+++ b/source/blender/blenkernel/intern/fluid.c
@@ -3212,18 +3212,8 @@ static Mesh *create_liquid_geometry(FluidDomainSettings *fds,
   float size[3];
   float cell_size_scaled[3];
 
-  /* Assign material + flags to new mesh.
-   * If there are no faces in original mesh, keep materials and flags unchanged. */
-  MPoly *mpoly;
-  MPoly mp_example = {0};
-  mpoly = BKE_mesh_polys_for_write(orgmesh);
-  if (mpoly) {
-    mp_example = *mpoly;
-  }
-
   const int *orig_material_indices = BKE_mesh_material_indices(orgmesh);
   const short mp_mat_nr = orig_material_indices ? orig_material_indices[0] : 0;
-  const char mp_flag = mp_example.flag;
 
   int i;
   int num_verts, num_faces;
@@ -3339,7 +3329,6 @@ static Mesh *create_liquid_geometry(FluidDomainSettings *fds,
   for (i = 0; i < num_faces; i++, mpolys++, mloops += 3) {
     /* Initialize from existing face. */
     material_indices[i] = mp_mat_nr;
-    mpolys->flag = mp_flag;
 
     mpolys->loopstart = i * 3;
     mpolys->totloop = 3;
diff --git a/source/blender/blenkernel/intern/key.cc b/source/blender/blenkernel/intern/key.cc
index b19ad6a3e97..00903854ce0 100644
--- a/source/blender/blenkernel/intern/key.cc
+++ b/source/blender/blenkernel/intern/key.cc
@@ -2298,6 +2298,8 @@ void BKE_keyblock_mesh_calc_normals(const KeyBlock *kb,
                                 mesh->totloop,
                                 polys,
                                 poly_normals,
+                                static_cast<const bool *>(CustomData_get_layer_named(
+                                    &mesh->pdata, CD_PROP_BOOL, "sharp_face")),
                                 mesh->totpoly,
                                 (mesh->flag & ME_AUTOSMOOTH) != 0,
                                 mesh->smoothresh,
diff --git a/source/blender/blenkernel/intern/mesh.cc b/source/blender/blenkernel/intern/mesh.cc
index 0468ec53a9e..31dff924f2e 100644
--- a/source/blender/blenkernel/intern/mesh.cc
+++ b/source/blender/blenkernel/intern/mesh.cc
@@ -254,6 +254,7 @@ static void mesh_blend_write(BlendWriter *writer, ID *id, const void *id_address
       BKE_mesh_legacy_convert_hide_layers_to_flags(mesh);
       BKE_mesh_legacy_convert_selection_layers_to_flags(mesh);
       BKE_mesh_legacy_convert_material_indices_to_mpoly(mesh);
+      BKE_mesh_sharp_faces_to_flags(mesh);
       BKE_mesh_legacy_bevel_weight_from_layers(mesh);
       BKE_mesh_legacy_face_set_from_generic(mesh, poly_layers);
       BKE_mesh_legacy_edge_crease_from_layers(mesh);
@@ -1850,6 +1851,8 @@ void BKE_mesh_calc_normals_split_ex(Mesh *mesh,
                               loops.size(),
                               polys.data(),
                               BKE_mesh_poly_normals_ensure(mesh),
+                              static_cast<const bool *>(CustomData_get_layer_named(
+                                  &mesh->pdata, CD_PROP_BOOL, "sharp_face")),
                               polys.size(),
                               use_split_normals,
                               split_angle,
diff --git a/source/blender/blenkernel/intern/mesh_boolean_convert.cc b/source/blender/blenkernel/intern/mesh_boolean_convert.cc
index 3d98fc7c958..836aa3c5498 100644
--- a/source/blender/blenkernel/intern/mesh_boolean_convert.cc
+++ b/source/blender/blenkernel/intern/mesh_boolean_convert.cc
@@ -402,15 +402,12 @@ static void copy_vert_attributes(Mesh *dest_mesh,
 
 /* Similar to copy_vert_attributes but for poly attributes. */
 static void copy_poly_attributes(Mesh *dest_mesh,
-                                 MPoly *mp,
-                                 const MPoly *orig_mp,
                                  const Mesh *orig_me,
                                  int mp_index,
                                  int index_in_orig_me,
                                  Span<short> material_remap,
                                  MutableSpan<int> dst_material_indices)
 {
-  mp->flag = orig_mp->flag;
   CustomData *target_cd = &dest_mesh->pdata;
   const CustomData *source_cd = &orig_me->pdata;
   for (int source_layer_i = 0; source_layer_i < source_cd->totlayer; ++source_layer_i) {
@@ -760,8 +757,6 @@ static Mesh *imesh_to_mesh(IMesh *im, MeshesToIMeshInfo &mim)
     }
 
     copy_poly_attributes(result,
-                         mp,
-                         orig_mp,
                          orig_me,
                          fi,
                          index_in_orig_me,
diff --git a/source/blender/blenkernel/intern/mesh_legacy_convert.cc b/source/blender/blenkernel/intern/mesh_legacy_convert.cc
index 7d4f0f8f7f8..b7c34436d79 100644
--- a/source/blender/blenkernel/intern/mesh_legacy_convert.cc
+++ b/source/blender/blenkernel/intern/mesh_legacy_convert.cc
@@ -440,6 +440,12 @@ static void convert_mfaces_to_mpolys(ID *id,
     material_indices = static_cast<int *>(CustomData_add_layer_named(
         pdata, CD_PROP_INT32, CD_SET_DEFAULT, nullptr, totpoly, "material_index"));
   }
+  bool *sharp_faces = static_cast<bool *>(
+      CustomData_get_layer_named(pdata, CD_PROP_BOOL, "sharp_face"));
+  if (sharp_faces == nullptr) {
+    sharp_faces = static_cast<bool *>(CustomData_add_layer_named(
+        pdata, CD_PROP_BOOL, CD_SET_DEFAULT, nullptr, totpoly, "sharp_face"));
+  }
 
   numTex = CustomData_number_of_layers(fdata, CD_MTFACE);
   numCol = CustomData_number_of_layers(fdata, CD_MCOL);
@@ -484,7 +490,7 @@ static void convert_mfaces_to_mpolys(ID *id,
     mp->totloop = mf->v4 ? 4 : 3;
 
     material_indices[i] = mf->mat_nr;
-    mp->flag = mf->flag;
+    sharp_faces[i] = (mf->flag & ME_SMOOTH) == 0;
 
 #define ML(v1, v2) \
   { \
@@ -966,6 +972,8 @@ static int mesh_tessface_calc(Mesh &mesh,
   mloop = (const MLoop *)CustomData_get_layer(ldata, CD_MLOOP);
   const int *material_indices = static_cast<const int *>(
       CustomData_get_layer_named(pdata, CD_PROP_INT32, "material_index"));
+  const bool *sharp_faces = static_cast<const bool *>(
+      CustomData_get_layer_named(pdata, CD_PROP_BOOL, "sharp_face"));
 
   /* Allocate the length of `totfaces`, avoid many small reallocation's,
    * if all faces are triangles it will be correct, `quads == 2x` allocations. */
@@ -1005,7 +1013,7 @@ static int mesh_tessface_calc(Mesh &mesh,
     lidx[2] = l3; \
     lidx[3] = 0; \
     mf->mat_nr = material_indices ? material_indices[poly_index] : 0; \
-    mf->flag = mp->flag; \
+    mf->flag = (sharp_faces && sharp_faces[poly_index]) ? 0 : ME_SMOOTH; \
     mf->edcode = 0; \
     (void)0
 
@@ -1028,7 +1036,7 @@ static int mesh_tessface_calc(Mesh &mesh,
     lidx[2] = l3; \
     lidx[3] = l4; \
     mf->mat_nr = material_indices ? material_indices[poly_index] : 0; \
-    mf->flag = mp->flag; \
+    mf->flag = (sharp_faces && sharp_faces[poly_index]) ? 0 : ME_SMOOTH; \
     mf->edcode = TESSFACE_IS_QUAD; \
     (void)0
 
@@ -1114,7 +1122,6 @@ static int mesh_tessface_calc(Mesh &mesh,
         lidx[3] = 0;
 
         mf->mat_nr = material_indices ? material_indices[poly_index] : 0;
-        mf->flag = mp->flag;
         mf->edcode = 0;
 
         mface_index++;
@@ -1205,6 +1212,57 @@ void BKE_mesh_tessface_ensure(struct Mesh *mesh)
 
 /** \} */
 
+/* ----

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list