[Bf-blender-cvs] [54ae189d869] refactor-mesh-sharp-face-generic: Start moving ME_SMOOTH flag to generic "sharp_face" attribute

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


Commit: 54ae189d869a4b02578c115d60ef052dc037b76f
Author: Hans Goudey
Date:   Wed Jan 4 23:56:20 2023 -0500
Branches: refactor-mesh-sharp-face-generic
https://developer.blender.org/rB54ae189d869a4b02578c115d60ef052dc037b76f

Start moving ME_SMOOTH flag to generic "sharp_face" attribute

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

M	intern/cycles/blender/mesh.cpp
M	release/scripts/startup/bl_ui/properties_data_mesh.py
M	source/blender/blenkernel/BKE_mesh_tangent.h
M	source/blender/blenkernel/BKE_shrinkwrap.h
M	source/blender/blenkernel/intern/curve_to_mesh_convert.cc
M	source/blender/blenkernel/intern/geometry_component_mesh.cc
M	source/blender/blenkernel/intern/mball_tessellate.cc
M	source/blender/blenkernel/intern/mesh.cc
M	source/blender/blenkernel/intern/mesh_convert.cc
M	source/blender/blenkernel/intern/mesh_tangent.cc
M	source/blender/blenkernel/intern/shrinkwrap.cc
M	source/blender/draw/intern/draw_cache_extract_mesh_render_data.cc
M	source/blender/draw/intern/draw_cache_impl_subdivision.cc
M	source/blender/draw/intern/mesh_extractors/extract_mesh.hh
M	source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_lnor.cc
M	source/blender/editors/mesh/mesh_data.cc
M	source/blender/editors/object/object_remesh.cc
M	source/blender/editors/sculpt_paint/paint_image_proj.cc
M	source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp
M	source/blender/geometry/intern/realize_instances.cc
M	source/blender/io/alembic/intern/abc_reader_mesh.cc
M	source/blender/io/collada/GeometryExporter.cpp
M	source/blender/io/usd/intern/usd_reader_mesh.cc
M	source/blender/io/usd/intern/usd_writer_mesh.cc
M	source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc
M	source/blender/io/wavefront_obj/exporter/obj_export_mesh.hh
M	source/blender/io/wavefront_obj/importer/obj_import_mesh.cc
M	source/blender/makesdna/DNA_meshdata_types.h
M	source/blender/makesrna/intern/rna_mesh.c
M	source/blender/modifiers/intern/MOD_ocean.c
M	source/blender/modifiers/intern/MOD_remesh.c
M	source/blender/modifiers/intern/MOD_screw.cc
M	source/blender/nodes/geometry/nodes/node_geo_input_shade_smooth.cc
M	source/blender/nodes/geometry/nodes/node_geo_set_shade_smooth.cc

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

diff --git a/intern/cycles/blender/mesh.cpp b/intern/cycles/blender/mesh.cpp
index 736b80bacd6..234488794ed 100644
--- a/intern/cycles/blender/mesh.cpp
+++ b/intern/cycles/blender/mesh.cpp
@@ -895,6 +895,23 @@ 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)
+{
+  for (BL::Attribute &b_attribute : b_mesh.attributes) {
+    if (b_attribute.domain() != BL::Attribute::domain_FACE) {
+      continue;
+    }
+    if (b_attribute.data_type() != BL::Attribute::data_type_BOOLEAN) {
+      continue;
+    }
+    if (b_attribute.name() != "sharp_face") {
+      continue;
+    }
+    return BL::BoolAttribute{b_attribute};
+  }
+  return std::nullopt;
+}
+
 static void create_mesh(Scene *scene,
                         Mesh *mesh,
                         BL::Mesh &b_mesh,
@@ -986,6 +1003,15 @@ static void create_mesh(Scene *scene,
     return 0;
   };
 
+  std::optional<BL::BoolAttribute> sharp_faces = find_sharp_face_attribute(b_mesh);
+  auto get_face_sharp = [&](const int poly_index) -> bool {
+    if (sharp_faces) {
+      return sharp_faces->data[poly_index].value();
+    }
+    return 0;
+  };
+
+
   /* create faces */
   const MPoly *polys = static_cast<const MPoly *>(b_mesh.polygons[0].ptr.data);
   if (!subdivision) {
@@ -995,7 +1021,7 @@ static void create_mesh(Scene *scene,
       int3 vi = get_int3(t.vertices());
 
       int shader = get_material_index(poly_index);
-      bool smooth = (b_poly.flag & ME_SMOOTH) || use_loop_normals;
+      bool smooth = !get_face_sharp(poly_index) || use_loop_normals;
 
       if (use_loop_normals) {
         BL::Array<float, 9> loop_normals = t.split_normals();
@@ -1021,7 +1047,7 @@ static void create_mesh(Scene *scene,
       const MPoly &b_poly = polys[i];
       int n = b_poly.totloop;
       int shader = get_material_index(i);
-      bool smooth = (b_poly.flag & ME_SMOOTH) || use_loop_normals;
+      bool smooth = !get_face_sharp(poly_index) || use_loop_normals;
 
       vi.resize(n);
       for (int i = 0; i < n; i++) {
diff --git a/release/scripts/startup/bl_ui/properties_data_mesh.py b/release/scripts/startup/bl_ui/properties_data_mesh.py
index e390b9cb6d4..44bb932e5f2 100644
--- a/release/scripts/startup/bl_ui/properties_data_mesh.py
+++ b/release/scripts/startup/bl_ui/properties_data_mesh.py
@@ -605,7 +605,7 @@ class DATA_PT_mesh_attributes(MeshButtonsPanel, Panel):
         colliding_names = []
         for collection in (
                 # Built-in names.
-                {"position": None, "shade_smooth": None, "normal": None, "crease": None},
+                {"position": None, "normal": None, "crease": None},
                 mesh.attributes,
                 mesh.uv_layers,
                 None if ob is None else ob.vertex_groups,
diff --git a/source/blender/blenkernel/BKE_mesh_tangent.h b/source/blender/blenkernel/BKE_mesh_tangent.h
index b018ab978b2..3428e383917 100644
--- a/source/blender/blenkernel/BKE_mesh_tangent.h
+++ b/source/blender/blenkernel/BKE_mesh_tangent.h
@@ -47,6 +47,7 @@ void BKE_mesh_calc_loop_tangent_ex(const struct MVert *mvert,
                                    const struct MLoop *mloop,
                                    const struct MLoopTri *looptri,
                                    uint looptri_len,
+                                   const bool *sharp_faces,
 
                                    struct CustomData *loopdata,
                                    bool calc_active_tangent,
diff --git a/source/blender/blenkernel/BKE_shrinkwrap.h b/source/blender/blenkernel/BKE_shrinkwrap.h
index b13a1cbd034..5394d7e043a 100644
--- a/source/blender/blenkernel/BKE_shrinkwrap.h
+++ b/source/blender/blenkernel/BKE_shrinkwrap.h
@@ -76,6 +76,7 @@ typedef struct ShrinkwrapTreeData {
   const struct MPoly *polys;
   const float (*vert_normals)[3];
   const float (*poly_normals)[3];
+  const bool *sharp_faces;
   const float (*clnors)[3];
   ShrinkwrapBoundaryData *boundary;
 } ShrinkwrapTreeData;
diff --git a/source/blender/blenkernel/intern/curve_to_mesh_convert.cc b/source/blender/blenkernel/intern/curve_to_mesh_convert.cc
index e5cafd405df..0c9757232a0 100644
--- a/source/blender/blenkernel/intern/curve_to_mesh_convert.cc
+++ b/source/blender/blenkernel/intern/curve_to_mesh_convert.cc
@@ -112,7 +112,6 @@ static void fill_mesh_topology(const int vert_offset,
       MPoly &poly = polys[ring_poly_offset + i_profile];
       poly.loopstart = ring_segment_loop_offset;
       poly.totloop = 4;
-      poly.flag = ME_SMOOTH;
 
       MLoop &loop_a = loops[ring_segment_loop_offset];
       loop_a.v = ring_vert_offset + i_profile;
diff --git a/source/blender/blenkernel/intern/geometry_component_mesh.cc b/source/blender/blenkernel/intern/geometry_component_mesh.cc
index b9702466d17..510a927e6e6 100644
--- a/source/blender/blenkernel/intern/geometry_component_mesh.cc
+++ b/source/blender/blenkernel/intern/geometry_component_mesh.cc
@@ -922,16 +922,6 @@ static void tag_component_positions_changed(void *owner)
   }
 }
 
-static bool get_shade_smooth(const MPoly &mpoly)
-{
-  return mpoly.flag & ME_SMOOTH;
-}
-
-static void set_shade_smooth(MPoly &mpoly, bool value)
-{
-  SET_FLAG_FROM_TEST(mpoly.flag, value, ME_SMOOTH);
-}
-
 static float2 get_loop_uv(const MLoopUV &uv)
 {
   return float2(uv.uv);
@@ -1284,18 +1274,17 @@ static ComponentAttributeProviders create_attribute_providers_for_mesh()
                                                        nullptr,
                                                        AttributeValidator{&material_index_clamp});
 
-  static BuiltinCustomDataLayerProvider shade_smooth(
-      "shade_smooth",
-      ATTR_DOMAIN_FACE,
-      CD_PROP_BOOL,
-      CD_MPOLY,
-      BuiltinAttributeProvider::NonCreatable,
-      BuiltinAttributeProvider::Writable,
-      BuiltinAttributeProvider::NonDeletable,
-      face_access,
-      make_derived_read_attribute<MPoly, bool, get_shade_smooth>,
-      make_derived_write_attribute<MPoly, bool, get_shade_smooth, set_shade_smooth>,
-      nullptr);
+  static BuiltinCustomDataLayerProvider sharp_face("sharp_face",
+                                                   ATTR_DOMAIN_FACE,
+                                                   CD_PROP_BOOL,
+                                                   CD_PROP_BOOL,
+                                                   BuiltinAttributeProvider::Creatable,
+                                                   BuiltinAttributeProvider::Writable,
+                                                   BuiltinAttributeProvider::Deletable,
+                                                   face_access,
+                                                   make_array_read_attribute<bool>,
+                                                   make_array_write_attribute<bool>,
+                                                   nullptr);
 
   static BuiltinCustomDataLayerProvider crease(
       "crease",
@@ -1325,7 +1314,7 @@ static ComponentAttributeProviders create_attribute_providers_for_mesh()
   static CustomDataAttributeProvider face_custom_data(ATTR_DOMAIN_FACE, face_access);
 
   return ComponentAttributeProviders(
-      {&position, &id, &material_index, &shade_smooth, &normal, &crease},
+      {&position, &id, &material_index, &sharp_face, &normal, &crease},
       {&uvs,
        &corner_custom_data,
        &vertex_groups,
diff --git a/source/blender/blenkernel/intern/mball_tessellate.cc b/source/blender/blenkernel/intern/mball_tessellate.cc
index c2322da19cb..414b2e32ed0 100644
--- a/source/blender/blenkernel/intern/mball_tessellate.cc
+++ b/source/blender/blenkernel/intern/mball_tessellate.cc
@@ -1483,7 +1483,6 @@ Mesh *BKE_mball_polygonize(Depsgraph *depsgraph, Scene *scene, Object *ob)
     const int count = indices[2] != indices[3] ? 4 : 3;
     mpoly[i].loopstart = loop_offset;
     mpoly[i].totloop = count;
-    mpoly[i].flag = ME_SMOOTH;
 
     mloop[loop_offset].v = uint32_t(indices[0]);
     mloop[loop_offset + 1].v = uint32_t(indices[1]);
diff --git a/source/blender/blenkernel/intern/mesh.cc b/source/blender/blenkernel/intern/mesh.cc
index a7f1eb1df00..0468ec53a9e 100644
--- a/source/blender/blenkernel/intern/mesh.cc
+++ b/source/blender/blenkernel/intern/mesh.cc
@@ -1464,16 +1464,17 @@ void BKE_mesh_material_remap(Mesh *me, const uint *remap, uint remap_len)
 
 void BKE_mesh_smooth_flag_set(Mesh *me, const bool use_smooth)
 {
-  MutableSpan<MPoly> polys = me->polys_for_write();
+  using namespace blender;
+  using namespace blender::bke;
+  MutableAttributeAccessor attributes = me->attributes_for_write();
   if (use_smooth) {
-    for (MPoly &poly : polys) {
-      poly.flag |= ME_SMOOTH;
-    }
+    attributes.remove("sharp_face");
   }
   else {
-    for (MPoly &poly : polys) {
-      poly.flag &= ~ME_SMOOTH;
-    }
+    SpanAttributeWriter<bool> sharp_faces = attributes.lookup_or_add_for_write_only_span<bool>(
+        "sharp_face", ATTR_DOMAIN_FACE);
+    sharp_faces.span.fill(true);
+    sharp_faces.finish();
   }
 }
 
diff --git a/source/blender/blenkernel/intern/mesh_convert.cc b/source/blender/blenkernel/intern/mesh_convert.cc
index c59210d9d47..0276daff228 100644
--- a/source/blender/blenkernel/intern/mesh_convert.cc
+++ b/source/blender/blenkernel/intern/mesh_convert.cc
@@ -198,6 +198,9 @@ static Mesh *mesh_nurbs_displist_to_mesh(const Curve *cu, const ListBase *dispba
   MutableAttributeAccessor attributes = mesh->attributes_for_write();
   SpanAttributeWriter<int> material_indices = attributes.lookup_or_add_for_write_only_span<int>(
       "material_index", ATTR_DOMAIN_FACE);
+  SpanAttributeWriter<bool> sharp_faces = attributes.lookup_or_add_for_write_span<bool>(
+      "sharp_face", ATTR_DOMAIN_FACE);
+
   MLoopUV *mloopuv = static_cast<MLoopUV *>(CustomData_add_layer_named(
       &mesh->ldata, CD_MLOOPUV, CD_SET_DEFAULT, nullptr, mesh->totloop, DATA_("UVMap")));
 
@@ -283,8 +286,8 @@ static Mesh *mesh_nurbs_displist_to_mesh(const Curve *cu, const ListBase *dispba
           }
         }
 
-        if (is_smooth) {
-          polys[dst_poly].flag |= ME_SMOOTH;
+        if (!is_smooth) {
+          sharp_faces.span

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list