[Bf-blender-cvs] [ae8d54c1d1c] temp-geometry-nodes-extrude-mesh: Cleanup comments and improve use of mixers

Hans Goudey noreply at git.blender.org
Mon Jan 10 06:16:02 CET 2022


Commit: ae8d54c1d1cfc4c9071c0d656ecfd7eaffcbf683
Author: Hans Goudey
Date:   Sun Jan 9 23:15:55 2022 -0600
Branches: temp-geometry-nodes-extrude-mesh
https://developer.blender.org/rBae8d54c1d1cfc4c9071c0d656ecfd7eaffcbf683

Cleanup comments and improve use of mixers

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

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 f7e76f54404..7a6b2b89732 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_extrude_mesh.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_extrude_mesh.cc
@@ -73,7 +73,6 @@ static MutableSpan<MVert> mesh_verts(Mesh &mesh)
 {
   return {mesh.mvert, mesh.totvert};
 }
-
 static Span<MEdge> mesh_edges(const Mesh &mesh)
 {
   return {mesh.medge, mesh.totedge};
@@ -82,7 +81,6 @@ static MutableSpan<MEdge> mesh_edges(Mesh &mesh)
 {
   return {mesh.medge, mesh.totedge};
 }
-
 static Span<MPoly> mesh_polys(const Mesh &mesh)
 {
   return {mesh.mpoly, mesh.totpoly};
@@ -91,7 +89,6 @@ static MutableSpan<MPoly> mesh_polys(Mesh &mesh)
 {
   return {mesh.mpoly, mesh.totpoly};
 }
-
 static Span<MLoop> mesh_loops(const Mesh &mesh)
 {
   return {mesh.mloop, mesh.totloop};
@@ -191,6 +188,7 @@ static void extrude_mesh_vertices(MeshComponent &component,
   const IndexMask selection = evaluator.get_evaluated_selection_as_mask();
   const VArray<float3> offsets = evaluator.get_evaluated<float3>(0);
 
+  /* This allows parallelizing attribute mixing for new edges. */
   Array<Vector<int>> vert_to_edge_map = create_vert_to_edge_map(orig_vert_size, mesh_edges(mesh));
 
   expand_mesh_size(mesh, selection.size(), selection.size(), 0, 0);
@@ -219,6 +217,7 @@ static void extrude_mesh_vertices(MeshComponent &component,
       MutableSpan<T> data = attribute.as_span().typed<T>();
       switch (attribute.domain()) {
         case ATTR_DOMAIN_POINT: {
+          /* New vertices copy the attribute values from their source vertex. */
           MutableSpan<T> new_data = data.slice(new_vert_range);
           threading::parallel_for(selection.index_range(), 512, [&](const IndexRange range) {
             for (const int i : range) {
@@ -228,22 +227,17 @@ static void extrude_mesh_vertices(MeshComponent &component,
           break;
         }
         case ATTR_DOMAIN_EDGE: {
+          /* New edge values are mixed from of all the edges connected to the source vertex. */
           MutableSpan<T> new_data = data.slice(new_edge_range);
           threading::parallel_for(selection.index_range(), 512, [&](const IndexRange range) {
-            for (const int i : range) {
-              /* Create a separate mixer for every point to avoid allocating temporary
-               * buffers in the mixer the size of the result and to allow multi-threading. */
-              attribute_math::DefaultMixer<T> mixer{new_data.slice(i, 1)};
-
-              const int i_src_vert = selection[i];
-              Span<int> connected_edges = vert_to_edge_map[i_src_vert];
-
-              for (const int i_connected_edge : connected_edges) {
-                mixer.mix_in(0, data[i_connected_edge]);
+            attribute_math::DefaultMixer<T> mixer{new_data.slice(range)};
+            for (const int i : IndexRange(range.size())) {
+              const int i_src_vert = selection[range[i]];
+              for (const int i_connected_edge : vert_to_edge_map[i_src_vert]) {
+                mixer.mix_in(i, data[i_connected_edge]);
               }
-
-              mixer.finalize();
             }
+            mixer.finalize();
           });
           break;
         }
@@ -467,7 +461,7 @@ static void extrude_mesh_edges(MeshComponent &component,
                                    connect_edge_range[extrude_index_2]);
   }
 
-  /* Create a map of all of an index in the extruded vertices array to all of the indices of edges
+  /* Create a map of indices in the extruded vertices array to all of the indices of edges
    * in the duplicate edges array that connect to that vertex. This can be used to simplify the
    * mixing of attribute data for the connecting edges. */
   Array<Vector<int>> new_vert_to_duplicate_edge_map = create_vert_to_edge_map(
@@ -498,41 +492,38 @@ static void extrude_mesh_edges(MeshComponent &component,
           }
           MutableSpan<T> connect_data = data.slice(connect_edge_range);
           threading::parallel_for(connect_data.index_range(), 512, [&](const IndexRange range) {
-            for (const int i : range) {
-              /* Create a separate mixer for every point to avoid allocating temporary
-               * buffers in the mixer the size of the result and to allow multi-threading. */
-              attribute_math::DefaultMixer<T> mixer{connect_data.slice(i, 1)};
-
-              for (const int i_connected_duplicate_edge : new_vert_to_duplicate_edge_map[i]) {
-                /* Use the duplicate data because it's slightly simpler to access and was just
-                 * filled in the previous loop. */
-                mixer.mix_in(0, duplicate_data[i_connected_duplicate_edge]);
+            attribute_math::DefaultMixer<T> mixer{connect_data.slice(range)};
+            for (const int i : IndexRange(range.size())) {
+              const int i_new_vert = range[i];
+              for (const int i_duplicate_edge : new_vert_to_duplicate_edge_map[i_new_vert]) {
+                /* Use the duplicate data rather than the original edge's data because it's
+                 * slightly simpler to access and was just filled in the previous loop. */
+                mixer.mix_in(i, duplicate_data[i_duplicate_edge]);
               }
-
-              mixer.finalize();
             }
+            mixer.finalize();
           });
           break;
         }
         case ATTR_DOMAIN_FACE: {
+          /* Attribute values for new faces are a mix of the values of faces connected to the its
+           * original edge.  */
           MutableSpan<T> new_data = data.slice(new_poly_range);
           threading::parallel_for(edge_selection.index_range(), 512, [&](const IndexRange range) {
-            for (const int i : range) {
-              /* Create a separate mixer for every point to avoid allocating temporary
-               * buffers in the mixer the size of the result and to allow multi-threading. */
-              attribute_math::DefaultMixer<T> mixer{new_data.slice(i, 1)};
-
-              const int i_src_edge = edge_selection[i];
+            attribute_math::DefaultMixer<T> mixer{new_data.slice(range)};
+            for (const int i : IndexRange(range.size())) {
+              const int i_src_edge = edge_selection[range[i]];
               for (const int i_connected_poly : edge_to_poly_map[i_src_edge]) {
-                mixer.mix_in(0, data[i_connected_poly]);
+                mixer.mix_in(i, data[i_connected_poly]);
               }
-
-              mixer.finalize();
             }
+            mixer.finalize();
           });
           break;
         }
         case ATTR_DOMAIN_CORNER: {
+          /* New corners get the average value of all adjacent corners on original faces connected
+           * to the original edge. */
           MutableSpan<T> new_data = data.slice(new_loop_range);
           threading::parallel_for(edge_selection.index_range(), 256, [&](const IndexRange range) {
             for (const int i_edge_selection : range) {
@@ -546,8 +537,8 @@ static void extrude_mesh_edges(MeshComponent &component,
                 continue;
               }
 
-              /* Each corner at the same location if the offset is zero gets the same value,
-               * so there are two separate values for the corner data of this new polygon. */
+              /* Both corners on each vertical edge of the side polygon get the same value,
+               * so there are only two unique values to mix. */
               Array<T> side_poly_corner_data(2);
               attribute_math::DefaultMixer<T> mixer{side_poly_corner_data};
 
@@ -641,10 +632,10 @@ static void extrude_mesh_edges(MeshComponent &component,
   BLI_assert(BKE_mesh_is_valid(component.get_for_write()));
 }
 
-static void extrude_mesh_faces(MeshComponent &component,
-                               const Field<bool> &selection_field,
-                               const Field<float3> &offset_field,
-                               const AttributeOutputs &attribute_outputs)
+static void extrude_mesh_face_regions(MeshComponent &component,
+                                      const Field<bool> &selection_field,
+                                      const Field<float3> &offset_field,
+                                      const AttributeOutputs &attribute_outputs)
 {
   Mesh &mesh = *component.get_for_write();
   const int orig_vert_size = mesh.totvert;
@@ -814,7 +805,7 @@ static void extrude_mesh_faces(MeshComponent &component,
                                    connect_edge_range[extrude_index_2]);
   }
 
-  /* Create a map of all of an index in the extruded vertices array to all of the indices of edges
+  /* Create a map of indices in the extruded vertices array to all of the indices of edges
    * in the duplicate edges array that connect to that vertex. This can be used to simplify the
    * mixing of attribute data for the connecting edges. */
   Array<Vector<int>> new_vert_to_duplicate_edge_map = create_vert_to_edge_map(
@@ -832,6 +823,7 @@ static void extrude_mesh_faces(MeshComponent &component,
       MutableSpan<T> data = attribute.as_span().typed<T>();
       switch (attribute.domain()) {
         case ATTR_DOMAIN_POINT: {
+          /* New vertices copy the attributes from their original vertices. */
           MutableSpan<T> new_data = data.slice(new_vert_range);
           for (const int i : new_vert_orig_indices.index_range()) {
             new_data[i] = data[new_vert_orig_indices[i]];
@@ -839,29 +831,33 @@ static void extrude_mesh_faces(MeshComponent &component,
           break;
         }
         case ATTR_DOMAIN_EDGE: {
+          /* Two cases:
+           * - Edges parallel to original edges: Copy the edge attributes from the original edges.
+           * - Edges connected to original vertices: Mix values of selected edges that are
+           *   connected to the original vertex.
+           */
           MutableSpan<T> duplicate_data = data.slice(duplicate_edge_range);
           MutableSpan<T> connect_data = data.slice(connect_edge_range);
           for (const int i : edge_selection.index_range()) {
             duplicate_data[i] = data[edge_s

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list