[Bf-blender-cvs] [8e0693379f2] temp-geometry-nodes-extrude-mesh: Cleanup: Simplify attribute transfer

Hans Goudey noreply at git.blender.org
Thu Dec 30 23:37:20 CET 2021


Commit: 8e0693379f2d8b28e748a5f336cb9eae452dec58
Author: Hans Goudey
Date:   Thu Dec 30 16:35:53 2021 -0600
Branches: temp-geometry-nodes-extrude-mesh
https://developer.blender.org/rB8e0693379f2d8b28e748a5f336cb9eae452dec58

Cleanup: Simplify attribute transfer

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

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

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

diff --git a/source/blender/nodes/geometry/nodes/node_geo_extrude_mesh.cc b/source/blender/nodes/geometry/nodes/node_geo_extrude_mesh.cc
index 5728e511365..9a257553197 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_extrude_mesh.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_extrude_mesh.cc
@@ -313,38 +313,48 @@ static void extrude_mesh_edges(MeshComponent &component,
   }
 
   component.attribute_foreach([&](const AttributeIDRef &id, const AttributeMetaData meta_data) {
-    if (meta_data.domain == ATTR_DOMAIN_POINT) {
-      OutputAttribute attribute = component.attribute_try_get_for_output(
-          id, ATTR_DOMAIN_POINT, meta_data.data_type);
-
-      attribute_math::convert_to_static_type(meta_data.data_type, [&](auto dummy) {
-        using T = decltype(dummy);
-        MutableSpan<T> data = attribute.as_span().typed<T>();
-        MutableSpan<T> new_data = data.slice(extrude_vert_range);
-
-        for (const int i : extrude_vert_orig_indices.index_range()) {
-          new_data[i] = data[extrude_vert_orig_indices[i]];
-        }
-      });
-
-      attribute.save();
+    OutputAttribute attribute = component.attribute_try_get_for_output(
+        id, meta_data.domain, meta_data.data_type);
+    if (!attribute) {
+      return true; /* Impossible to write the "normal" attribute. */
     }
-    else if (meta_data.domain == ATTR_DOMAIN_EDGE) {
-      OutputAttribute attribute = component.attribute_try_get_for_output(
-          id, ATTR_DOMAIN_EDGE, meta_data.data_type);
 
-      attribute_math::convert_to_static_type(meta_data.data_type, [&](auto dummy) {
-        using T = decltype(dummy);
-        MutableSpan<T> data = attribute.as_span().typed<T>();
-        MutableSpan<T> duplicate_data = data.slice(duplicate_edge_range);
-
-        for (const int i : selection.index_range()) {
-          duplicate_data[i] = data[selection[i]];
+    attribute_math::convert_to_static_type(meta_data.data_type, [&](auto dummy) {
+      using T = decltype(dummy);
+      MutableSpan<T> data = attribute.as_span().typed<T>();
+      switch (attribute.domain()) {
+        case ATTR_DOMAIN_POINT: {
+          MutableSpan<T> new_data = data.slice(extrude_vert_range);
+          for (const int i : new_vert_orig_indices.index_range()) {
+            new_data[i] = data[extrude_vert_orig_indices[i]];
+          }
+          break;
         }
-      });
+        case ATTR_DOMAIN_EDGE: {
+          MutableSpan<T> duplicate_data = data.slice(duplicate_edge_range);
+          MutableSpan<T> connect_data = data.slice(extrude_edge_range);
+          connect_data.fill(T());
+          for (const int i : selection.index_range()) {
+            duplicate_data[i] = data[selection[i]];
+          }
+          break;
+        }
+        case ATTR_DOMAIN_FACE: {
+          MutableSpan<T> new_data = data.take_back(selection.size());
+          new_data.fill(T());
+          break;
+        }
+        case ATTR_DOMAIN_CORNER: {
+          MutableSpan<T> new_data = data.take_back(new_loop_size);
+          new_data.fill(T());
+          break;
+        }
+        default:
+          BLI_assert_unreachable();
+      }
+    });
 
-      attribute.save();
-    }
+    attribute.save();
     return true;
   });



More information about the Bf-blender-cvs mailing list