[Bf-blender-cvs] [4c30b950b66] refactor-mesh-sharp-face-generic: Remove attribute in set shade smooth node

Hans Goudey noreply at git.blender.org
Thu Jan 5 20:47:24 CET 2023


Commit: 4c30b950b66a26bf00f29affcd73c62ea56a3072
Author: Hans Goudey
Date:   Thu Jan 5 14:43:55 2023 -0500
Branches: refactor-mesh-sharp-face-generic
https://developer.blender.org/rB4c30b950b66a26bf00f29affcd73c62ea56a3072

Remove attribute in set shade smooth node

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

M	source/blender/nodes/geometry/nodes/node_geo_set_shade_smooth.cc

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

diff --git a/source/blender/nodes/geometry/nodes/node_geo_set_shade_smooth.cc b/source/blender/nodes/geometry/nodes/node_geo_set_shade_smooth.cc
index cab21db2493..b2171677538 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_set_shade_smooth.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_set_shade_smooth.cc
@@ -14,6 +14,30 @@ static void node_declare(NodeDeclarationBuilder &b)
   b.add_output<decl::Geometry>(N_("Geometry")).propagate_all();
 }
 
+/**
+ * When the `sharp_face` attribute doesn't exist, all faces are considered smooth. If all faces
+ * are selected and the sharp value is a constant false value, we can remove the attribute instead,
+ * as an optimization to avoid propagating and storing it in the future.
+ */
+static bool try_removing_sharp_attribute(Mesh &mesh,
+                                         const Field<bool> &selection_field,
+                                         const Field<bool> &sharp_field)
+{
+  if (selection_field.node().depends_on_input() || sharp_field.node().depends_on_input()) {
+    return false;
+  }
+  const bool selection = fn::evaluate_constant_field(selection_field);
+  if (!selection) {
+    return true;
+  }
+  const bool sharp = fn::evaluate_constant_field(sharp_field);
+  if (sharp) {
+    return false;
+  }
+  mesh.attributes_for_write().remove("sharp_face");
+  return true;
+}
+
 static void set_smooth(Mesh &mesh,
                        const Field<bool> &selection_field,
                        const Field<bool> &sharp_field)
@@ -22,6 +46,10 @@ static void set_smooth(Mesh &mesh,
     return;
   }
 
+  if (try_removing_sharp_attribute(mesh, selection_field, sharp_field)) {
+    return;
+  }
+
   MutableAttributeAccessor attributes = mesh.attributes_for_write();
   AttributeWriter<bool> sharp_faces = attributes.lookup_or_add_for_write<bool>("sharp_face",
                                                                                ATTR_DOMAIN_FACE);
@@ -43,7 +71,6 @@ static void node_geo_exec(GeoNodeExecParams params)
 
   geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
     if (Mesh *mesh = geometry_set.get_mesh_for_write()) {
-      /* TODO: Do this with nodes instead. */
       set_smooth(*mesh, selection_field, fn::invert_boolean_field(smooth_field));
     }
   });



More information about the Bf-blender-cvs mailing list