[Bf-blender-cvs] [6df669a0bd5] bevelv2: Refactor bevel calculation in bevel node.

Howard Trickey noreply at git.blender.org
Sun Oct 9 20:52:35 CEST 2022


Commit: 6df669a0bd573eb46b10b324bf21a5fbf6ac3760
Author: Howard Trickey
Date:   Sun Oct 9 14:51:31 2022 -0400
Branches: bevelv2
https://developer.blender.org/rB6df669a0bd573eb46b10b324bf21a5fbf6ac3760

Refactor bevel calculation in bevel node.

Unified the general calculation framework for each of vertex,
edge, and face bevels.

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

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 91898834baf..ab6b24515e6 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_bevel_mesh.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_bevel_mesh.cc
@@ -709,117 +709,130 @@ HalfEdge *BevelVertexData::find_half_edge(int edge) const
   return nullptr;
 }
 
-/** BevelData holds the global data needed for a bevel. */
-class BevelData {
-  /* BevelVertexData for just the affected vertices. */
-  Array<BevelVertexData> bevel_vert_data_;
-  /* A map from mesh vertex index to index in bevel_vert_data_.
-   * If we wanted  more speed at expense of space, we could also use
-   * an Array of size equal to the number of mesh vertices here.
-   */
-  Map<int, int> vert_to_bvd_index_;
-  /* All the BevelEdges, when edge beveling. */
-  Array<BevelEdge> bevel_edge_;
-  /* Map from mesh edge indiex inot bevel_edge_. */
-  Map<int, int> edge_to_bevel_edge_;
-
+/** BevelSpec holds the data the specifies what the user wants beveled.
+ * There will be a derived class for each type of bevel.
+ */
+class BevelSpec {
  public:
-  MeshTopology topo;
+  /* Are we beveling vertices, edges, or faces? */
+  GeometryNodeBevelMeshMode bevel_mode;
+  /* A mask over the elements of the beveled type, saying what is to bovel. */
+  IndexMask to_bevel;
 
-  BevelData(const Mesh &mesh) : topo(mesh)
-  {
-  }
-  ~BevelData()
+  BevelSpec(GeometryNodeBevelMeshMode mode, IndexMask to_bevel)
+      : bevel_mode(mode), to_bevel(to_bevel)
   {
   }
 
-  /* Initial calculation of vertex bevels. */
-  void calculate_vertex_bevels(const IndexMask to_bevel, VArray<float> amounts);
-
-  /* Calculation of edge bevels. */
-  void calculate_edge_bevels(const IndexMask to_bevel, VArray<float> amounts);
+  virtual void dump_spec() = 0;
+};
 
-  /* Sets up internal Map for fast access to the BevelVertexData for a given mesh vert. */
-  void setup_vert_map();
+class VertexBevelSpec : public BevelSpec {
+ public:
+  /* Indexed by Mesh vertex index, the amount to slide along all edges
+   * attached to the vertex. */
+  VArray<float> amount;
 
-  /* What is the BevelVertexData for mesh vertex `vert`? May return nullptr if `vert` isn't
-   * involved in beveling. */
-  BevelVertexData *bevel_vertex_data(int vert)
+  VertexBevelSpec(IndexMask to_bevel, VArray<float> amount)
+      : BevelSpec{GEO_NODE_BEVEL_MESH_VERTICES, to_bevel}, amount(amount)
   {
-    int slot = vert_to_bvd_index_.lookup_default(vert, -1);
-    if (slot != -1) {
-      return &bevel_vert_data_[slot];
-    }
-    return nullptr;
   }
 
-  Span<BevelVertexData> beveled_vertices_data() const
-  {
-    return bevel_vert_data_.as_span();
+  void dump_spec();
+};
+
+void VertexBevelSpec::dump_spec()
+{
+  std::cout << "VertexBevelSpec\n";
+  for (const int v : to_bevel.index_range()) {
+    if (to_bevel[v]) {
+      std::cout << v << ": " << amount[v] << "\n";
+    }
   }
+}
 
-  MutableSpan<BevelVertexData> mutable_beveled_vertices_data()
+class FaceBevelSpec : public BevelSpec {
+ public:
+  /* Indexed by Mesh poly index, the amount to inset the face by. */
+  VArray<float> amount;
+  /* Indexed by Mesh poly index, the slope to follow when insetting the face. */
+  VArray<float> slope;
+  bool use_regions;
+
+  FaceBevelSpec(IndexMask to_bevel, VArray<float> amount, VArray<float> slope, bool use_regions)
+      : BevelSpec{GEO_NODE_BEVEL_MESH_FACES, to_bevel},
+        amount(amount),
+        slope(slope),
+        use_regions(use_regions)
   {
-    return bevel_vert_data_.as_mutable_span();
   }
 
-  void print(const std::string &label) const;
+  void dump_spec();
 };
 
-/** Make a transation map from mesh vertex index to indices in bevel_vert_data_. */
-void BevelData::setup_vert_map()
+void FaceBevelSpec::dump_spec()
 {
-  vert_to_bvd_index_.reserve(bevel_vert_data_.size());
-  for (const int i : bevel_vert_data_.index_range()) {
-    vert_to_bvd_index_.add_new(bevel_vert_data_[i].vertex_cap().vert, i);
+  std::cout << "FaceBevelSpec\n";
+  if (use_regions) {
+    std::cout << "use regions\n";
+  }
+  for (const int f : to_bevel.index_range()) {
+    if (to_bevel[f]) {
+      std::cout << f << ": " << amount[f] << ", slope=" << slope[f] << "\n";
+    }
   }
 }
 
-void BevelData::print(const std::string &label) const
-{
-  if (label.size() > 0) {
-    std::cout << label << " ";
-  }
-  std::cout << "BevelData\n";
-  for (const BevelVertexData &bvd : bevel_vert_data_.as_span()) {
-    std::cout << bvd;
+class EdgeBevelSpec : public BevelSpec {
+ public:
+  /* Indexed by Mesh edge index, the amounts to bevel the edge.
+   * `left_amount[0]` is the left side amount for the source end and
+   * `right_amount[0]` is the right side amount for the source end,
+   * where "left" and "right" mean: those sides as you look
+   * along the edge to the source.
+   * Similarly, the 1-indexed elements of those arrays are for the
+   * destination end, with left and right as you look towards the dest end.
+   */
+  VArray<float> left_amount[2];
+  VArray<float> right_amount[2];
+
+  EdgeBevelSpec(IndexMask to_bevel, VArray<float> amount)
+      : BevelSpec(GEO_NODE_BEVEL_MESH_EDGES, to_bevel),
+        left_amount{amount, amount},
+        right_amount{amount, amount}
+  {
   }
-}
 
-/** 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());
+  EdgeBevelSpec(IndexMask to_bevel,
+                VArray<float> src_left_amount,
+                VArray<float> src_right_amount,
+                VArray<float> dst_left_amount,
+                VArray<float> dst_right_amount)
+      : BevelSpec(GEO_NODE_BEVEL_MESH_EDGES, to_bevel),
+        left_amount{src_left_amount, dst_left_amount},
+        right_amount{src_right_amount, dst_right_amount}
+  {
+  }
 
-  bevel_vert_data_.reinitialize(to_bevel.size());
-  threading::parallel_for(to_bevel.index_range(), 1024, [&](const IndexRange range) {
-    for (const int i : range) {
-      const int vert = to_bevel[i];
-      bevel_vert_data_[i].construct_vertex_bevel(vert, amounts[vert], topo);
-    }
-  });
-  setup_vert_map();
-}
+  void dump_spec();
+};
 
-/** Calculate the BevelData for an edge bevel off all the specified edges of the mesh.
- * `to_bevel` gives the mesh indics of the edges to be beveled.
- * `amounts` should have (virtual) length that matches the number of edges in the mesh,
- * and gives, per edge, the magnitude of the bevel for that edge.
- */
-void BevelData::calculate_edge_bevels(const IndexMask to_bevel, VArray<float> amounts)
+void EdgeBevelSpec::dump_spec()
 {
-  bevel_edge_.reinitialize(to_bevel.size());
-  Set<int> need_vert;
-  for (const int e : to_bevel) {
-    need_vert.add(topo.edge_v1(e));
-    need_vert.add(topo.edge_v2(e));
+  std::cout << "EdgeBevelSpec\n";
+  for (const int e : to_bevel.index_range()) {
+    if (to_bevel[e]) {
+      std::cout << e << ": ";
+      if (left_amount[0] == right_amount[0] && left_amount[0] == left_amount[1] &&
+          left_amount[1] == right_amount[1]) {
+        std::cout << left_amount[0][e] << "\n";
+      }
+      else {
+        std::cout << "0(" << left_amount[0][e] << ", " << right_amount[0][e] << ") 1("
+                  << left_amount[1][e] << ", " << right_amount[1][e] << ")\n";
+      }
+    }
   }
-  const int tot_need_vert = need_vert.size();
-  bevel_vert_data_.reinitialize(tot_need_vert);
 }
 
 /** IndexAlloc allocates sequential integers, starting from a given start value. */
@@ -1474,6 +1487,101 @@ void MeshDelta::print(const std::string &label) const
   std::cout << "\n";
 }
 
+/** BevelData holds the global data needed for a bevel. */
+class BevelData {
+  /* The specification of the bevel. */
+  const BevelSpec *spec_;
+  /* The original Mesh. */
+  const Mesh *mesh_;
+  /* Topology for mesh_. */
+  const MeshTopology *topo_;
+  /* Will accumulate delta from mesh_ to desired answer. */
+  MeshDelta mesh_delta_;
+  /* BevelVertexData for just the affected vertices. */
+  Array<BevelVertexData> bevel_vert_data_;
+  /* A map from mesh vertex index to index in bevel_vert_data_.
+   * If we wanted  more speed at expense of space, we could also use
+   * an Array of size equal to the number of mesh vertices here.
+   */
+  Map<int, int> vert_to_bvd_index_;
+  /* All the BevelEdges, when edge beveling. */
+  Array<BevelEdge> bevel_edge_;
+  /* Map from mesh edge indiex inot bevel_edge_. */
+  Map<int, int> edge_to_bevel_edge_;
+
+ public:
+  BevelData(const Mesh *mesh, const BevelSpec *spec, const MeshTopology *topo)
+      : spec_(spec), mesh_(mesh), topo_(topo), mesh_delta_(*mesh, *topo)
+  {
+  }
+  ~BevelData()
+  {
+  }
+
+  /* Calculate vertex bevels based on spec_, with answer in mesh_delta_. */
+  void calculate_vertex_bevel();
+  /* Calculate edge bevels based on spec_, with answer in mesh_delta_. */
+  void calculate_edge_bevel();
+  /* Calculate face bevels based on spec_, with answer in mesh_delta_. */
+  void calculate_face_bevel();
+
+  /* Return the Mesh that is the result of applying mesh_delta_ to mesh_. */
+  Mesh *get_output_mesh(GeometrySet geometry_set, const MeshComponent &component);
+
+ private:
+  /* Initial calculation of vertex bevels. */
+  void calculate_vertex_bevels(const IndexMask to_bevel, VArray<float> amounts);
+
+  /* Calculation of edge bevels. */
+  void calculate_edge_bevels(const IndexMask to_bevel, VArray<float> amounts);
+
+  /* Sets up internal Map for fast access to the BevelVertexData for a given mesh vert. */
+  void setup_vert_map();
+
+  /* What is the BevelVertexData for mesh vertex `vert`? May return nullptr if `vert` isn't
+   * involved in beveling. */
+  BevelVertexData *bevel_vertex_data(int vert)
+  {
+    int slot = vert_to_bvd_index_.lookup_default(vert, -1);
+    if (slot != -1) {
+      return &bevel_vert_data_[slot];
+  

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list