[Bf-blender-cvs] [3556fa2742c] bevelv2: The MeshDelta class can create a new Mesh.

Howard Trickey noreply at git.blender.org
Sat Jul 16 23:01:39 CEST 2022


Commit: 3556fa2742c364b17f29556c3252ad1c895f17c5
Author: Howard Trickey
Date:   Sat Jul 16 16:12:15 2022 -0400
Branches: bevelv2
https://developer.blender.org/rB3556fa2742c364b17f29556c3252ad1c895f17c5

The MeshDelta class can create a new Mesh.

This means that vertex bevel does something now.
Nothing has been done about UVs yet, and nothing about
edge and face bevels yet.

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

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

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

diff --git a/source/blender/nodes/geometry/nodes/node_geo_bevel_mesh.cc b/source/blender/nodes/geometry/nodes/node_geo_bevel_mesh.cc
index 7de1138760c..ee0f5c4c00a 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_bevel_mesh.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_bevel_mesh.cc
@@ -3,6 +3,7 @@
 #include "DNA_mesh_types.h"
 #include "DNA_meshdata_types.h"
 
+#include "BKE_attribute_math.hh"
 #include "BKE_mesh.h"
 #include "BKE_mesh_mapping.h"
 #include "BKE_mesh_runtime.h"
@@ -53,7 +54,7 @@ static void node_update(bNodeTree *UNUSED(ntree), bNode *UNUSED(node))
 {
 }
 
-/* MeshTopology encapsulates data needed to answer topological queries about a mesh,
+/** MeshTopology encapsulates data needed to answer topological queries about a mesh,
  * such as "which edges are adjacent to a given vertex?".
  * While Mesh uses the term 'poly' for polygon, most of Blender uses the term 'face',
  * so we'll go with 'face' in this code except in the final to/from mesh routines.
@@ -227,7 +228,7 @@ float3 MeshTopology::edge_dir_from_vert_normalized(int e, int v) const
   return math::normalize(edge_dir_from_vert(e, v));
 }
 
-/* A Vertex Cap consists of a vertex in a mesh and an CCW ordering of
+/** A Vertex Cap consists of a vertex in a mesh and an CCW ordering of
  * alternating edges and faces around it, as viewed from the face's
  * normal side. Some faces may be missing (i.e., gaps).
  * (If there are other edges and faces attached to the vertex that
@@ -304,7 +305,7 @@ class VertexCap {
   }
 };
 
-/* Construct and return the VertexCap for vertex vert. */
+/** Construct and return the VertexCap for vertex `vert`. */
 void VertexCap::init_from_topo(const int vert, const MeshTopology &topo)
 {
   this->vert = vert;
@@ -441,7 +442,7 @@ static std::ostream &operator<<(std::ostream &os, const BoundaryVert &bv)
   return os;
 }
 
-/* The different types of BoundaryEdges (see below). */
+/** The different types of BoundaryEdges (see below). */
 typedef enum eBoundaryEdgeType {
   BE_UNBEVELED = 0,
   BE_BEVELED = 1,
@@ -454,7 +455,7 @@ typedef enum eBoundaryEdgeType {
 static const char *be_type_name[6] = {
     "unbev", "bev", "facebev_both", "facebev_l", "facebev_r", "other"};
 
-/* A BoundaryEdge is one end of an edge, attached to a vertex in a VertexCap.
+/** A BoundaryEdge is one end of an edge, attached to a vertex in a VertexCap.
  * This data describes how it is involved in beveling, and how it is attached
  * to BoundaryVerts.
  * Note: when the descriptors "left" and "right" are used to refer to sides of
@@ -476,11 +477,37 @@ class BoundaryEdge {
   /* The boundary vertex index where the left half of a BE_BEVELED,
    * BE_FACE_BEVEL_BOTH, or BE_FACE_BEVEL_RIGHT attached. */
   int bv_right_index;
+  /* The index of this edge, if unbeveled, in output mesh. */
+  int mesh_index;
   /* The type of this BoundaryEdge. */
   eBoundaryEdgeType type;
 
   BoundaryEdge()
-      : edge(-1), vc_index(-1), bv_index(-1), bv_left_index(-1), bv_right_index(-1), type(BE_OTHER)
+      : edge(-1),
+        vc_index(-1),
+        bv_index(-1),
+        bv_left_index(-1),
+        bv_right_index(-1),
+        mesh_index(-1),
+        type(BE_OTHER)
+  {
+  }
+};
+
+/** A BoundaryConnector has the vertices and edges in the output mesh
+ * of the connection between two successive BoundaryVerts.
+ */
+class BoundaryConnector {
+ public:
+  /* Temporary: for now, just one edge. Will eventually be array
+   * of vertices with intervening edges. */
+  int edge;
+
+  BoundaryConnector() : edge(-1)
+  {
+  }
+
+  BoundaryConnector(int e) : edge(e)
   {
   }
 };
@@ -492,14 +519,18 @@ static std::ostream &operator<<(std::ostream &os, const BoundaryEdge &be)
      << "vc#=" << be.vc_index << " "
      << "bv#=" << be.bv_index << " "
      << "bvl#=" << be.bv_left_index << " "
-     << "bvr#=" << be.bv_right_index << "}";
+     << "bvr#=" << be.bv_right_index << " "
+     << "eout=" << be.mesh_index << "}";
   return os;
 }
 
+/** BevelVertexData holds the data used to bevel around a vertex. */
 class BevelVertexData {
   VertexCap vertex_cap_;
   Array<BoundaryVert> boundary_vert_;
   Array<BoundaryEdge> boundary_edge_;
+  /* boundary_conn_[i] goes from boundary_vert_[i] to the following one. */
+  Array<BoundaryConnector> boundary_conn_;
 
  public:
   BevelVertexData()
@@ -521,15 +552,50 @@ class BevelVertexData {
     return vertex_cap_;
   }
 
+  const int beveled_vert() const
+  {
+    return vertex_cap_.vert;
+  }
+
   Span<BoundaryVert> boundary_verts() const
   {
     return boundary_vert_.as_span();
   }
 
+  MutableSpan<BoundaryVert> mutable_boundary_verts()
+  {
+    return boundary_vert_.as_mutable_span();
+  }
+
   Span<BoundaryEdge> boundary_edges() const
   {
     return boundary_edge_.as_span();
   }
+
+  const BoundaryVert &boundary_vert(int boundary_vert_pos) const
+  {
+    return boundary_vert_[boundary_vert_pos];
+  }
+
+  const BoundaryVert &next_boundary_vert(int boundary_vert_pos) const
+  {
+    int n = (boundary_vert_pos + 1) % boundary_vert_.size();
+    return boundary_vert_[n];
+  }
+
+  void set_boundary_connection(int boundary_vert_pos, const BoundaryConnector conn)
+  {
+    boundary_conn_[boundary_vert_pos] = conn;
+  }
+
+  const int boundary_connector_edge(int boundary_vert_pos, int edge_index) const
+  {
+    BLI_assert(edge_index == 0);  // Temporary
+    return boundary_conn_[boundary_vert_pos].edge;
+  }
+
+  /* Find the BoundaryEdge for `edge`, returning nullptr if not found. */
+  BoundaryEdge *find_boundary_edge(int edge) const;
 };
 
 static std::ostream &operator<<(std::ostream &os, const BevelVertexData &bvd)
@@ -550,7 +616,7 @@ static std::ostream &operator<<(std::ostream &os, const BevelVertexData &bvd)
   return os;
 }
 
-/* Calculate the BevelVertexData for one vertex, `vert`, by the given `amount`.
+/** Calculate the `BevelVertexData` for one vertex, `vert`, by the given `amount`.
  * This doesn't calculate limits to the bevel caused by collisions with vertex bevels
  * at adjacent vertices; that needs to done after all of these are calculated,
  * so that this operation can be done in parallel with all other vertex constructions.
@@ -564,6 +630,7 @@ void BevelVertexData::construct_vertex_bevel(int vert, float amount, const MeshT
   /* There will be one boundary vertex on each edge attached to `vert`. */
   boundary_edge_.reinitialize(num_edges);
   boundary_vert_.reinitialize(num_edges);
+  boundary_conn_.reinitialize(num_edges);
 
   const float3 vert_co = topo.vert_co(vertex_cap().vert);
   for (const int i : IndexRange(num_edges)) {
@@ -582,6 +649,19 @@ void BevelVertexData::construct_vertex_bevel(int vert, float amount, const MeshT
   }
 }
 
+BoundaryEdge *BevelVertexData::find_boundary_edge(int edge) const
+{
+  for (int i : boundary_edge_.index_range()) {
+    if (boundary_edge_[i].edge == edge) {
+      /* There's no non-const rvalue subscripting in Array. */
+      BoundaryEdge *be = const_cast<BoundaryEdge *>(&boundary_edge_[i]);
+      return be;
+    }
+  }
+  return nullptr;
+}
+
+/** BevelData holds the global data needed for a bevel. */
 class BevelData {
   /* BevelVertexData for just the affected vertices. */
   Array<BevelVertexData> bevel_vert_data_;
@@ -618,10 +698,20 @@ class BevelData {
     return nullptr;
   }
 
+  Span<BevelVertexData> beveled_vertices_data() const
+  {
+    return bevel_vert_data_.as_span();
+  }
+
+  MutableSpan<BevelVertexData> mutable_beveled_vertices_data()
+  {
+    return bevel_vert_data_.as_mutable_span();
+  }
+
   void print(const std::string &label) const;
 };
 
-/* Make a transation map from mesh vertex index to indices in bevel_vert_data_. */
+/** Make a transation map from mesh vertex index to indices in bevel_vert_data_. */
 void BevelData::setup_vert_map()
 {
   vert_to_bvd_index_.reserve(bevel_vert_data_.size());
@@ -641,14 +731,14 @@ void BevelData::print(const std::string &label) const
   }
 }
 
-/* Calculate the BevelData for a vertex bevel of all specified vertices of the mesh.
+/** Calculate the BevelData for a vertex bevel of all specified vertices of the mesh.
  * `to_bevel` gives the mesh indices of vertices to be beveled.
  * `amounts` should have (virtual) length that matches the number of vertices in the mesh,
  * and gives, per vertex, the magnitude of the bevel at that vertex.
  */
 void BevelData::calculate_vertex_bevels(const IndexMask to_bevel, VArray<float> amounts)
 {
-  BLI_assert(amounts.size() == topo.num_verts());
+  // BLI_assert(amounts.size() == topo.num_verts());
 
   bevel_vert_data_.reinitialize(to_bevel.size());
   threading::parallel_for(to_bevel.index_range(), 1024, [&](const IndexRange range) {
@@ -660,7 +750,7 @@ void BevelData::calculate_vertex_bevels(const IndexMask to_bevel, VArray<float>
   setup_vert_map();
 }
 
-/* IndexAlloc allocates sequential integers, starting from a given start value. */
+/** IndexAlloc allocates sequential integers, starting from a given start value. */
 class IndexAlloc {
   int start_;
   int first_free_;
@@ -684,11 +774,11 @@ class IndexAlloc {
   }
 };
 
-/* MeshDelta represents a delta to a Mesh: additions and deletions
+/** MeshDelta represents a delta to a Mesh: additions and deletions
  * of Mesh elements.
  */
 class MeshDelta {
-  Mesh &mesh_;
+  const Mesh &mesh_;
   IndexAlloc vert_alloc_;
   IndexAlloc edge_alloc_;
   IndexAlloc poly_alloc_;
@@ -701,15 +791,19 @@ class MeshDelta {
   Vector<MEdge> new_edges_;
   Vector<MPoly> new_polys_;
   Vector<MLoop> new_loops_;
+  Vector<int> new_vert_rep_;
+  Vector<int> new_edge_rep_;
+  Vector<int> new_poly_rep_;
+  Vector<int> new_loop_rep_;
 
  public:
-  MeshDelta(Mesh &mesh);
+  MeshDelta(const Mesh &mesh);
 
-  /* TODO: provide arguments or methods to set the attributes. */
-  int new_vert(const float3 &co);
-  int new_edge(int v1, int v2);
-  int new_loop(int v, int e);
-  int new_face(int loopstart, int totloop);
+  /* In the following, `rep` is the index of the old mesh element to base attributes on.  */
+  int new_vert(const float3 &co, int rep);
+  int new_edge(int v1, int v2, int rep);
+  int new_loop(int v, int e, int rep);
+  int new_face(int loopstart, int totloop, int rep);
 
   void delete_vert(int v)
   {
@@ -721,12 +81

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list