[Bf-blender-cvs] [3642e174284] master: Cleanup: Move curve to mesh node implementation to blenkernel

Hans Goudey noreply at git.blender.org
Tue Sep 21 18:57:16 CEST 2021


Commit: 3642e17428448e4e9760ca5a8900d02e0abe2df7
Author: Hans Goudey
Date:   Tue Sep 21 11:56:54 2021 -0500
Branches: master
https://developer.blender.org/rB3642e17428448e4e9760ca5a8900d02e0abe2df7

Cleanup: Move curve to mesh node implementation to blenkernel

I plan to use this for curve object data conversion to mesh in D12533,
and possibly for the implicit curve to mesh conversion in the curve
and text object modifier stack in the future.

Differential Revision: https://developer.blender.org/D12585

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

A	source/blender/blenkernel/BKE_curve_to_mesh.hh
M	source/blender/blenkernel/CMakeLists.txt
A	source/blender/blenkernel/intern/curve_to_mesh_convert.cc
M	source/blender/nodes/geometry/nodes/node_geo_curve_to_mesh.cc

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

diff --git a/source/blender/blenkernel/BKE_curve_to_mesh.hh b/source/blender/blenkernel/BKE_curve_to_mesh.hh
new file mode 100644
index 00000000000..cc1ef08908d
--- /dev/null
+++ b/source/blender/blenkernel/BKE_curve_to_mesh.hh
@@ -0,0 +1,31 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#pragma once
+
+struct Mesh;
+struct CurveEval;
+
+/** \file
+ * \ingroup geo
+ */
+
+namespace blender::bke {
+
+Mesh *curve_to_mesh_sweep(const CurveEval &curve, const CurveEval &profile);
+Mesh *curve_to_wire_mesh(const CurveEval &curve);
+
+}  // namespace blender::bke
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 0b082bf1c5a..de7864ef36a 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -116,6 +116,7 @@ set(SRC
   intern/curve_decimate.c
   intern/curve_deform.c
   intern/curve_eval.cc
+  intern/curve_to_mesh_convert.cc
   intern/curveprofile.c
   intern/customdata.c
   intern/customdata_file.c
@@ -332,6 +333,7 @@ set(SRC
   BKE_cryptomatte.h
   BKE_cryptomatte.hh
   BKE_curve.h
+  BKE_curve_to_mesh.hh
   BKE_curveprofile.h
   BKE_customdata.h
   BKE_customdata_file.h
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_to_mesh.cc b/source/blender/blenkernel/intern/curve_to_mesh_convert.cc
similarity index 93%
copy from source/blender/nodes/geometry/nodes/node_geo_curve_to_mesh.cc
copy to source/blender/blenkernel/intern/curve_to_mesh_convert.cc
index b8bdb3d71d6..5f2f945192c 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_curve_to_mesh.cc
+++ b/source/blender/blenkernel/intern/curve_to_mesh_convert.cc
@@ -15,29 +15,27 @@
  */
 
 #include "BLI_array.hh"
-#include "BLI_float4x4.hh"
+#include "BLI_set.hh"
 #include "BLI_task.hh"
 
 #include "DNA_mesh_types.h"
 #include "DNA_meshdata_types.h"
 
+#include "BKE_attribute_access.hh"
+#include "BKE_attribute_math.hh"
+#include "BKE_geometry_set.hh"
 #include "BKE_material.h"
 #include "BKE_mesh.h"
 #include "BKE_spline.hh"
 
-#include "UI_interface.h"
-#include "UI_resources.h"
+#include "BKE_curve_to_mesh.hh"
 
-#include "node_geometry_util.hh"
+using blender::fn::GMutableSpan;
+using blender::fn::GSpan;
+using blender::fn::GVArray_Typed;
+using blender::fn::GVArrayPtr;
 
-namespace blender::nodes {
-
-static void geo_node_curve_to_mesh_declare(NodeDeclarationBuilder &b)
-{
-  b.add_input<decl::Geometry>("Curve");
-  b.add_input<decl::Geometry>("Profile Curve");
-  b.add_output<decl::Geometry>("Mesh");
-}
+namespace blender::bke {
 
 /** Information about the creation of one curve spline and profile spline combination. */
 struct ResultInfo {
@@ -645,13 +643,16 @@ static void copy_spline_domain_attributes_to_mesh(const CurveEval &curve,
 }
 
 /**
+ * Extrude all splines in the profile curve along the path of every spline in the curve input.
+ * Transfer curve attributes to the mesh.
+ *
  * \note Normal calculation is by far the slowest part of calculations relating to the result mesh.
  * Although it would be a sensible decision to use the better topology information available while
  * generating the mesh to also generate the normals, that work may wasted if the output mesh is
  * changed anyway in a way that affects the normals. So currently this code uses the safer /
  * simpler solution of deferring normal calculation to the rest of Blender.
  */
-static Mesh *curve_to_mesh_calculate(const CurveEval &curve, const CurveEval &profile)
+Mesh *curve_to_mesh_sweep(const CurveEval &curve, const CurveEval &profile)
 {
   Span<SplinePtr> profiles = profile.splines();
   Span<SplinePtr> curves = curve.splines();
@@ -725,46 +726,14 @@ static CurveEval get_curve_single_vert()
   return curve;
 }
 
-static void geo_node_curve_to_mesh_exec(GeoNodeExecParams params)
+/**
+ * Create a loose-edge mesh based on the evaluated path of the curve's splines.
+ * Transfer curve attributes to the mesh.
+ */
+Mesh *curve_to_wire_mesh(const CurveEval &curve)
 {
-  GeometrySet curve_set = params.extract_input<GeometrySet>("Curve");
-  GeometrySet profile_set = params.extract_input<GeometrySet>("Profile Curve");
-
-  curve_set = bke::geometry_set_realize_instances(curve_set);
-  profile_set = bke::geometry_set_realize_instances(profile_set);
-
-  /* NOTE: Theoretically an "is empty" check would be more correct for errors. */
-  if (profile_set.has_mesh() && !profile_set.has_curve()) {
-    params.error_message_add(NodeWarningType::Warning,
-                             TIP_("No curve data available in profile input"));
-  }
-
-  if (!curve_set.has_curve()) {
-    if (curve_set.has_mesh()) {
-      params.error_message_add(NodeWarningType::Warning,
-                               TIP_("No curve data available in curve input"));
-    }
-    params.set_output("Mesh", GeometrySet());
-    return;
-  }
-
-  const CurveEval *profile_curve = profile_set.get_curve_for_read();
-
   static const CurveEval vert_curve = get_curve_single_vert();
-
-  Mesh *mesh = curve_to_mesh_calculate(*curve_set.get_curve_for_read(),
-                                       (profile_curve == nullptr) ? vert_curve : *profile_curve);
-  params.set_output("Mesh", GeometrySet::create_with_mesh(mesh));
+  return curve_to_mesh_sweep(curve, vert_curve);
 }
 
-}  // namespace blender::nodes
-
-void register_node_type_geo_curve_to_mesh()
-{
-  static bNodeType ntype;
-
-  geo_node_type_base(&ntype, GEO_NODE_CURVE_TO_MESH, "Curve to Mesh", NODE_CLASS_GEOMETRY, 0);
-  ntype.declare = blender::nodes::geo_node_curve_to_mesh_declare;
-  ntype.geometry_node_execute = blender::nodes::geo_node_curve_to_mesh_exec;
-  nodeRegisterType(&ntype);
-}
+}  // namespace blender::bke
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_to_mesh.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_to_mesh.cc
index b8bdb3d71d6..89ba635ff4b 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_curve_to_mesh.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_curve_to_mesh.cc
@@ -14,17 +14,10 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
-#include "BLI_array.hh"
-#include "BLI_float4x4.hh"
-#include "BLI_task.hh"
-
-#include "DNA_mesh_types.h"
-#include "DNA_meshdata_types.h"
-
-#include "BKE_material.h"
-#include "BKE_mesh.h"
 #include "BKE_spline.hh"
 
+#include "BKE_curve_to_mesh.hh"
+
 #include "UI_interface.h"
 #include "UI_resources.h"
 
@@ -39,692 +32,6 @@ static void geo_node_curve_to_mesh_declare(NodeDeclarationBuilder &b)
   b.add_output<decl::Geometry>("Mesh");
 }
 
-/** Information about the creation of one curve spline and profile spline combination. */
-struct ResultInfo {
-  const Spline &spline;
-  const Spline &profile;
-  int vert_offset;
-  int edge_offset;
-  int loop_offset;
-  int poly_offset;
-  int spline_vert_len;
-  int spline_edge_len;
-  int profile_vert_len;
-  int profile_edge_len;
-};
-
-static void vert_extrude_to_mesh_data(const Spline &spline,
-                                      const float3 profile_vert,
-                                      MutableSpan<MVert> r_verts,
-                                      MutableSpan<MEdge> r_edges,
-                                      const int vert_offset,
-                                      const int edge_offset)
-{
-  Span<float3> positions = spline.evaluated_positions();
-
-  for (const int i : IndexRange(positions.size() - 1)) {
-    MEdge &edge = r_edges[edge_offset + i];
-    edge.v1 = vert_offset + i;
-    edge.v2 = vert_offset + i + 1;
-    edge.flag = ME_LOOSEEDGE;
-  }
-
-  if (spline.is_cyclic() && spline.evaluated_edges_size() > 1) {
-    MEdge &edge = r_edges[edge_offset + spline.evaluated_edges_size() - 1];
-    edge.v1 = vert_offset;
-    edge.v2 = vert_offset + positions.size() - 1;
-    edge.flag = ME_LOOSEEDGE;
-  }
-
-  for (const int i : positions.index_range()) {
-    MVert &vert = r_verts[vert_offset + i];
-    copy_v3_v3(vert.co, positions[i] + profile_vert);
-  }
-}
-
-static void mark_edges_sharp(MutableSpan<MEdge> edges)
-{
-  for (MEdge &edge : edges) {
-    edge.flag |= ME_SHARP;
-  }
-}
-
-static void spline_extrude_to_mesh_data(const ResultInfo &info,
-                                        MutableSpan<MVert> r_verts,
-                                        MutableSpan<MEdge> r_edges,
-                                        MutableSpan<MLoop> r_loops,
-                                        MutableSpan<MPoly> r_polys)
-{
-  const Spline &spline = info.spline;
-  const Spline &profile = info.profile;
-  if (info.profile_vert_len == 1) {
-    vert_extrude_to_mesh_data(spline,
-                              profile.evaluated_positions()[0],
-                              r_verts,
-                              r_edges,
-                              info.vert_offset,
-                              info.edge_offset);
-    return;
-  }
-
-  /* Add the edges running along the length of the curve, starting at each profile vertex. */
-  const int spline_edges_start = info.edge_offset;
-  for (const int i_profile : IndexRange(info.profile_vert_len)) {
-    const int profile_edge_offset = spline_edges_start + i_profile * info.spline_edge_len;
-    for (const int i_ring : IndexRange(info.spline_edge_len)) {
-      const int i_next_ring = (i_ring == info.spline_vert_len - 1) ? 0 : i_ring + 1;
-
-      const int ring_vert_offset = info.vert_offset + info.profile_vert_len * i_ring;
-      const int next_ring_vert_offset = info.vert_offset + info.profile_vert_len * i_next_ring;
-
-      MEdge &edge = r_edges[profile_edge_offse

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list