[Bf-blender-cvs] [7244c8ded62] temp-geometry-nodes-extrude-mesh: More cleanup, all attributes transfers implemented for individual mode

Hans Goudey noreply at git.blender.org
Mon Jan 3 06:22:49 CET 2022


Commit: 7244c8ded621881424bc2bcea10e86f74e2ba88d
Author: Hans Goudey
Date:   Sun Jan 2 23:22:42 2022 -0600
Branches: temp-geometry-nodes-extrude-mesh
https://developer.blender.org/rB7244c8ded621881424bc2bcea10e86f74e2ba88d

More cleanup, all attributes transfers implemented for individual mode

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

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 c204ab6f506..c819cc26e69 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_extrude_mesh.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_extrude_mesh.cc
@@ -32,10 +32,6 @@ namespace blender::nodes::node_geo_extrude_mesh_cc {
 
 NODE_STORAGE_FUNCS(NodeGeometryExtrudeMesh)
 
-/* TODO: Decide whether to transfer attributes by topology proximity to new faces, corners, and
- * edges. */
-/* TODO: Deduplicate edge extrusion between edge and face modes. */
-
 static void node_declare(NodeDeclarationBuilder &b)
 {
   b.add_input<decl::Geometry>("Mesh").supported_type(GEO_COMPONENT_TYPE_MESH);
@@ -126,6 +122,10 @@ static void expand_mesh_size(Mesh &mesh,
     CustomData_realloc(&mesh.ldata, mesh.totloop);
   }
   BKE_mesh_update_customdata_pointers(&mesh, false);
+
+  for (MVert &vert : bke::mesh_verts(mesh).take_back(vert_expand)) {
+    vert.flag = 0;
+  }
 }
 
 static void extrude_mesh_vertices(MeshComponent &component,
@@ -216,6 +216,32 @@ static void extrude_mesh_vertices(MeshComponent &component,
   BLI_assert(BKE_mesh_is_valid(component.get_for_write()));
 }
 
+/**
+ * The resulting vector maps from the index in the added vertices to the original vertex they were
+ * extruded from.
+ */
+static Vector<int> extrude_vert_orig_indices_from_edges(const IndexMask edge_selection,
+                                                        const Mesh &mesh,
+                                                        MutableSpan<int> new_vert_indices)
+{
+  Vector<int> new_vert_orig_indices;
+  new_vert_orig_indices.reserve(edge_selection.size());
+  for (const int i_edge : edge_selection) {
+    const MEdge &edge = bke::mesh_edges(mesh)[i_edge];
+
+    if (new_vert_indices[edge.v1] == -1) {
+      new_vert_indices[edge.v1] = mesh.totvert + new_vert_orig_indices.size();
+      new_vert_orig_indices.append(edge.v1);
+    }
+
+    if (new_vert_indices[edge.v2] == -1) {
+      new_vert_indices[edge.v2] = mesh.totvert + new_vert_orig_indices.size();
+      new_vert_orig_indices.append(edge.v2);
+    }
+  }
+  return new_vert_orig_indices;
+}
+
 static void extrude_mesh_edges(MeshComponent &component,
                                const Field<bool> &selection_field,
                                const Field<float3> &offset_field,
@@ -223,8 +249,8 @@ static void extrude_mesh_edges(MeshComponent &component,
 {
   Mesh &mesh = *component.get_for_write();
   const int orig_vert_size = mesh.totvert;
-  Span<MEdge> orig_edges{mesh.medge, mesh.totedge};
-  Span<MPoly> orig_polys{mesh.mpoly, mesh.totpoly};
+  Span<MEdge> orig_edges = bke::mesh_edges(mesh);
+  Span<MPoly> orig_polys = bke::mesh_polys(mesh);
   const int orig_loop_size = mesh.totloop;
 
   GeometryComponentFieldContext edge_context{component, ATTR_DOMAIN_EDGE};
@@ -233,24 +259,9 @@ static void extrude_mesh_edges(MeshComponent &component,
   edge_evaluator.evaluate();
   const IndexMask edge_selection = edge_evaluator.get_evaluated_as_mask(0);
 
-  /* Maps vertex indices in the original mesh to the corresponding extruded vertices. */
-  Array<int> new_vert_indices(mesh.totvert, -1);
-  /* Maps from the index in the added vertices to the original vertex they were extruded from. */
-  Vector<int> new_vert_orig_indices;
-  new_vert_orig_indices.reserve(edge_selection.size());
-  for (const int i_edge : edge_selection) {
-    const MEdge &edge = orig_edges[i_edge];
-
-    if (new_vert_indices[edge.v1] == -1) {
-      new_vert_indices[edge.v1] = orig_vert_size + new_vert_orig_indices.size();
-      new_vert_orig_indices.append(edge.v1);
-    }
-
-    if (new_vert_indices[edge.v2] == -1) {
-      new_vert_indices[edge.v2] = orig_vert_size + new_vert_orig_indices.size();
-      new_vert_orig_indices.append(edge.v2);
-    }
-  }
+  Array<int> new_vert_indices(orig_vert_size, -1);
+  Vector<int> new_vert_orig_indices = extrude_vert_orig_indices_from_edges(
+      edge_selection, mesh, new_vert_indices);
 
   Array<float3> offsets(orig_vert_size);
   GeometryComponentFieldContext point_context{component, ATTR_DOMAIN_POINT};
@@ -281,10 +292,6 @@ static void extrude_mesh_edges(MeshComponent &component,
   MutableSpan<MPoly> new_polys = bke::mesh_polys(mesh).slice(new_poly_range);
   MutableSpan<MLoop> new_loops = bke::mesh_loops(mesh).slice(new_loop_range);
 
-  for (MVert &vert : new_verts) {
-    vert.flag = 0;
-  }
-
   for (const int i : connect_edges.index_range()) {
     MEdge &edge = connect_edges[i];
     edge.v1 = new_vert_orig_indices[i];
@@ -433,22 +440,6 @@ static IndexMask index_mask_from_selection(const VArray<bool> &selection,
   return IndexMask(r_indices);
 }
 
-static Array<Vector<int, 2>> mesh_calculate_polys_of_edge(const Mesh &mesh,
-                                                          const IndexMask poly_selection)
-{
-  Span<MPoly> polys{mesh.mpoly, mesh.totpoly};
-  Span<MLoop> loops{mesh.mloop, mesh.totloop};
-  Array<Vector<int, 2>> polys_of_edge(mesh.totedge);
-
-  for (const int poly_index : poly_selection) {
-    const MPoly &poly = polys[poly_index];
-    for (const MLoop &loop : loops.slice(poly.loopstart, poly.totloop)) {
-      polys_of_edge[loop.e].append(poly_index);
-    }
-  }
-  return polys_of_edge;
-}
-
 static void extrude_mesh_faces(MeshComponent &component,
                                const Field<bool> &selection_field,
                                const Field<float3> &offset_field,
@@ -456,9 +447,9 @@ static void extrude_mesh_faces(MeshComponent &component,
 {
   Mesh &mesh = *component.get_for_write();
   const int orig_vert_size = mesh.totvert;
-  const int orig_edge_size = mesh.totedge;
-  Span<MPoly> orig_polys{mesh.mpoly, mesh.totpoly};
-  Span<MLoop> orig_loops{mesh.mloop, mesh.totloop};
+  Span<MEdge> orig_edges = bke::mesh_edges(mesh);
+  Span<MPoly> orig_polys = bke::mesh_polys(mesh);
+  Span<MLoop> orig_loops = bke::mesh_loops(mesh);
 
   GeometryComponentFieldContext poly_context{component, ATTR_DOMAIN_FACE};
   FieldEvaluator poly_evaluator{poly_context, mesh.totpoly};
@@ -479,35 +470,12 @@ static void extrude_mesh_faces(MeshComponent &component,
   vert_evaluator.add_with_destination(offset_field, offsets.as_mutable_span());
   vert_evaluator.evaluate();
 
-  // Array<Vector<int, 2>> orig_edge_to_poly_map = mesh_calculate_polys_of_edge(mesh,
-  // poly_selection);
-
-  // Vector<int> in_between_edges;
-  // /* The extruded face corresponding to each extruded edge. */
-  // Vector<int> edge_orig_face_indices;
-  // Vector<int64_t> selected_edges_orig_indices;
-  // for (const int i_edge : IndexRange(orig_edge_size)) {
-  //   const int edge_selected_poly_count = orig_edge_to_poly_map[i_edge].size();
-  //   if (edge_selected_poly_count == 1) {
-  //     /* If the edge is only connected to a single selected polygon, it is extruded. */
-  //     selected_edges_orig_indices.append(i_edge);
-  //     edge_orig_face_indices.append(orig_edge_to_poly_map[i_edge].first());
-  //   }
-  //   else if (edge_selected_poly_count > 1) {
-  //     /* If the edge is connected to more than one selected polygon, it isn't extruded, but it
-  //     does
-  //      * need to be considered for reconnection to extruded vertices */
-  //     in_between_edges.append(i_edge);
-  //   }
-  // }
-  // const IndexMask edge_selection{selected_edges_orig_indices};
-
   /* Keep track of the selected face that each edge corresponds to. Only edges with one selected
    * face will have a single associated face. However, we need to keep track of a value for every
    * face in the mesh at this point, because we don't know how many edges will be selected for
    * extrusion in the end. */
-  Array<int> edge_face_indices(orig_edge_size, -1);
-  Array<int> edge_neighbor_count(orig_edge_size, 0);
+  Array<int> edge_face_indices(orig_edges.size(), -1);
+  Array<int> edge_neighbor_count(orig_edges.size(), 0);
   for (const int i_poly : poly_selection) {
     const MPoly &poly = orig_polys[i_poly];
     for (const MLoop &loop : orig_loops.slice(poly.loopstart, poly.totloop)) {
@@ -520,7 +488,7 @@ static void extrude_mesh_faces(MeshComponent &component,
   /* The extruded face corresponding to each extruded edge. */
   Vector<int> edge_orig_face_indices;
   Vector<int64_t> selected_edges_orig_indices;
-  for (const int i_edge : IndexRange(orig_edge_size)) {
+  for (const int i_edge : IndexRange(orig_edges.size())) {
     if (edge_neighbor_count[i_edge] == 1) {
       selected_edges_orig_indices.append(i_edge);
       edge_orig_face_indices.append(edge_face_indices[i_edge]);
@@ -532,33 +500,18 @@ static void extrude_mesh_faces(MeshComponent &component,
   const IndexMask edge_selection{selected_edges_orig_indices};
 
   /* Indices into the `duplicate_edges` span for each original selected edge. */
-  Array<int> duplicate_edge_indices(orig_edge_size, -1);
+  Array<int> duplicate_edge_indices(orig_edges.size(), -1);
   for (const int i : edge_selection.index_range()) {
     duplicate_edge_indices[edge_selection[i]] = i;
   }
 
-  /* Maps vertex indices in the original mesh to the corresponding extruded vertices. */
-  Array<int> new_vert_indices(mesh.totvert, -1);
-  /* Maps from the index in the added vertices to the original vertex they were newed from. */
-  Vector<int> new_vert_orig_indices;
-  new_vert_orig_indices.reserve(edge_selection.size());
-  for (const int i_edge : edge_selection) {
-    const MEdge &edge = mesh.medge[i_edge];
-
-    if (new_vert_indices[edge.v1] == -1) {
-      new_vert_indices[edge.v1] = orig_vert_size + new_vert_orig_indices.size();
-      new_vert_orig_indices.append(edge.v1);
-    }
-
-    if (new_vert_indices[edge.v2] == -1) {
-      new_vert_indices[edge.v2] = orig_vert_size + new_vert_orig_indices.size();
-      new_vert_orig_indices.append(edge.v2);
-    }
-  }
+  Array<int> new_vert_indices(orig_vert_size, -1);
+  Vector<int> new_vert_orig_indices = extrude_vert_orig_indices_from_edges(
+      edge_selection, mesh, new_vert_indices);
 
   const IndexRange new_vert_range{orig_vert_size, new_vert_orig_indices.size()};
   /* One edge connects each selected vertex to a new vertex on the extruded polygons.

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list