[Bf-blender-cvs] [17b8da71960] master: Geometry Nodes: Field version of mesh to curve node

Hans Goudey noreply at git.blender.org
Thu Oct 14 19:07:38 CEST 2021


Commit: 17b8da719606abfc9e3076555c626e6fc38dd7c5
Author: Hans Goudey
Date:   Thu Oct 14 12:06:48 2021 -0500
Branches: master
https://developer.blender.org/rB17b8da719606abfc9e3076555c626e6fc38dd7c5

Geometry Nodes: Field version of mesh to curve node

This commit adds a fields version of the mesh to curve node, with a
field for the input selection. In order to reduce code duplication,
it adds the mesh to curve conversion to the new geometry module
and calls that implementation from both places.

More details on the geometry module can be found here: T86869

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

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

M	release/scripts/startup/nodeitems_builtins.py
M	source/blender/CMakeLists.txt
M	source/blender/blenkernel/BKE_node.h
M	source/blender/blenkernel/intern/node.cc
A	source/blender/geometry/CMakeLists.txt
A	source/blender/geometry/GEO_mesh_to_curve.hh
A	source/blender/geometry/intern/mesh_to_curve_convert.cc
M	source/blender/nodes/CMakeLists.txt
M	source/blender/nodes/NOD_geometry.h
M	source/blender/nodes/NOD_static_types.h
M	source/blender/nodes/geometry/nodes/legacy/node_geo_mesh_to_curve.cc
A	source/blender/nodes/geometry/nodes/node_geo_mesh_to_curve.cc

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

diff --git a/release/scripts/startup/nodeitems_builtins.py b/release/scripts/startup/nodeitems_builtins.py
index b2faff56656..d4885f7bad8 100644
--- a/release/scripts/startup/nodeitems_builtins.py
+++ b/release/scripts/startup/nodeitems_builtins.py
@@ -145,6 +145,7 @@ def mesh_node_items(context):
 
     yield NodeItem("GeometryNodeEdgeSplit")
     yield NodeItem("GeometryNodeBoolean")
+    yield NodeItem("GeometryNodeMeshToCurve")
     yield NodeItem("GeometryNodeMeshToPoints")
     yield NodeItem("GeometryNodeMeshSubdivide")
     yield NodeItem("GeometryNodeTriangulate")
diff --git a/source/blender/CMakeLists.txt b/source/blender/CMakeLists.txt
index fbc0ec440cf..84d31bccc53 100644
--- a/source/blender/CMakeLists.txt
+++ b/source/blender/CMakeLists.txt
@@ -119,6 +119,7 @@ add_subdirectory(blenloader)
 add_subdirectory(depsgraph)
 add_subdirectory(ikplugin)
 add_subdirectory(simulation)
+add_subdirectory(geometry)
 add_subdirectory(gpu)
 add_subdirectory(imbuf)
 add_subdirectory(nodes)
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index 19215e75d95..9429da9d6a0 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -1536,6 +1536,7 @@ int ntreeTexExecTree(struct bNodeTree *ntree,
 #define GEO_NODE_SCALE_INSTANCES 1121
 #define GEO_NODE_ROTATE_INSTANCES 1122
 #define GEO_NODE_EDGE_SPLIT 1123
+#define GEO_NODE_MESH_TO_CURVE 1124
 
 /** \} */
 
diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc
index cb51249ac27..e526475fa95 100644
--- a/source/blender/blenkernel/intern/node.cc
+++ b/source/blender/blenkernel/intern/node.cc
@@ -5714,6 +5714,7 @@ static void registerGeometryNodes()
   register_node_type_geo_legacy_attribute_randomize();
   register_node_type_geo_legacy_delete_geometry();
   register_node_type_geo_legacy_material_assign();
+  register_node_type_geo_legacy_mesh_to_curve();
   register_node_type_geo_legacy_points_to_volume();
   register_node_type_geo_legacy_select_by_material();
   register_node_type_geo_legacy_curve_spline_type();
diff --git a/source/blender/geometry/CMakeLists.txt b/source/blender/geometry/CMakeLists.txt
new file mode 100644
index 00000000000..4e7e0b1ea58
--- /dev/null
+++ b/source/blender/geometry/CMakeLists.txt
@@ -0,0 +1,42 @@
+# ***** BEGIN GPL LICENSE BLOCK *****
+#
+# 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.
+#
+# The Original Code is Copyright (C) 2006, Blender Foundation
+# All rights reserved.
+
+set(INC
+  .
+  ../blenkernel
+  ../blenlib
+  ../blentranslation
+  ../functions
+  ../makesdna
+  ../makesrna
+  ../../../intern/guardedalloc
+  ${CMAKE_BINARY_DIR}/source/blender/makesdna/intern
+)
+
+set(SRC
+  intern/mesh_to_curve_convert.cc
+  GEO_mesh_to_curve.hh
+)
+
+set(LIB
+  bf_blenkernel
+  bf_blenlib
+)
+
+blender_add_lib(bf_geometry "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")
diff --git a/source/blender/geometry/GEO_mesh_to_curve.hh b/source/blender/geometry/GEO_mesh_to_curve.hh
new file mode 100644
index 00000000000..66459ab79a9
--- /dev/null
+++ b/source/blender/geometry/GEO_mesh_to_curve.hh
@@ -0,0 +1,35 @@
+/*
+ * 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.
+ */
+
+#include "BLI_index_mask.hh"
+
+#include "BKE_spline.hh"
+
+#pragma once
+
+struct Mesh;
+class MeshComponent;
+
+/** \file
+ * \ingroup geo
+ */
+
+namespace blender::geometry {
+
+std::unique_ptr<CurveEval> mesh_to_curve_convert(const MeshComponent &mesh_component,
+                                                 const IndexMask selection);
+
+}  // namespace blender::geometry
diff --git a/source/blender/nodes/geometry/nodes/legacy/node_geo_mesh_to_curve.cc b/source/blender/geometry/intern/mesh_to_curve_convert.cc
similarity index 72%
copy from source/blender/nodes/geometry/nodes/legacy/node_geo_mesh_to_curve.cc
copy to source/blender/geometry/intern/mesh_to_curve_convert.cc
index 11349dc7d42..64b9fa5c01d 100644
--- a/source/blender/nodes/geometry/nodes/legacy/node_geo_mesh_to_curve.cc
+++ b/source/blender/geometry/intern/mesh_to_curve_convert.cc
@@ -15,26 +15,20 @@
  */
 
 #include "BLI_array.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_spline.hh"
 
-#include "node_geometry_util.hh"
+#include "GEO_mesh_to_curve.hh"
 
-using blender::Array;
-
-namespace blender::nodes {
-
-static void geo_node_mesh_to_curve_declare(NodeDeclarationBuilder &b)
-{
-  b.add_input<decl::Geometry>("Mesh");
-  b.add_input<decl::String>("Selection");
-  b.add_output<decl::Geometry>("Curve");
-}
+namespace blender::geometry {
 
 template<typename T>
 static void copy_attribute_to_points(const VArray<T> &source_data,
@@ -52,11 +46,11 @@ static void copy_attributes_to_points(CurveEval &curve,
                                       Span<Vector<int>> point_to_vert_maps)
 {
   MutableSpan<SplinePtr> splines = curve.splines();
-  Set<AttributeIDRef> source_attribute_ids = mesh_component.attribute_ids();
+  Set<bke::AttributeIDRef> source_attribute_ids = mesh_component.attribute_ids();
 
   /* Copy builtin control point attributes. */
   if (source_attribute_ids.contains("tilt")) {
-    const GVArray_Typed<float> tilt_attribute = mesh_component.attribute_get_for_read<float>(
+    const fn::GVArray_Typed<float> tilt_attribute = mesh_component.attribute_get_for_read<float>(
         "tilt", ATTR_DOMAIN_POINT, 0.0f);
     threading::parallel_for(splines.index_range(), 256, [&](IndexRange range) {
       for (const int i : range) {
@@ -67,7 +61,7 @@ static void copy_attributes_to_points(CurveEval &curve,
     source_attribute_ids.remove_contained("tilt");
   }
   if (source_attribute_ids.contains("radius")) {
-    const GVArray_Typed<float> radius_attribute = mesh_component.attribute_get_for_read<float>(
+    const fn::GVArray_Typed<float> radius_attribute = mesh_component.attribute_get_for_read<float>(
         "radius", ATTR_DOMAIN_POINT, 1.0f);
     threading::parallel_for(splines.index_range(), 256, [&](IndexRange range) {
       for (const int i : range) {
@@ -78,13 +72,22 @@ static void copy_attributes_to_points(CurveEval &curve,
     source_attribute_ids.remove_contained("radius");
   }
 
-  /* Don't copy other builtin control point attributes. */
-  source_attribute_ids.remove("position");
+  for (const bke::AttributeIDRef &attribute_id : source_attribute_ids) {
+    /* Don't copy attributes that are built-in on meshes but not on curves. */
+    if (mesh_component.attribute_is_builtin(attribute_id)) {
+      continue;
+    }
+
+    /* Don't copy anonymous attributes with no references anymore. */
+    if (attribute_id.is_anonymous()) {
+      const AnonymousAttributeID &anonymous_id = attribute_id.anonymous_id();
+      if (!BKE_anonymous_attribute_id_has_strong_references(&anonymous_id)) {
+        continue;
+      }
+    }
 
-  /* Copy dynamic control point attributes. */
-  for (const AttributeIDRef &attribute_id : source_attribute_ids) {
-    const GVArrayPtr mesh_attribute = mesh_component.attribute_try_get_for_read(attribute_id,
-                                                                                ATTR_DOMAIN_POINT);
+    const fn::GVArrayPtr mesh_attribute = mesh_component.attribute_try_get_for_read(
+        attribute_id, ATTR_DOMAIN_POINT);
     /* Some attributes might not exist if they were builtin attribute on domains that don't
      * have any elements, i.e. a face attribute on the output of the line primitive node. */
     if (!mesh_attribute) {
@@ -97,7 +100,7 @@ static void copy_attributes_to_points(CurveEval &curve,
       for (const int i : range) {
         /* Create attribute on the spline points. */
         splines[i]->attributes.create(attribute_id, data_type);
-        std::optional<GMutableSpan> spline_attribute = splines[i]->attributes.get_for_write(
+        std::optional<fn::GMutableSpan> spline_attribute = splines[i]->attributes.get_for_write(
             attribute_id);
         BLI_assert(spline_attribute);
 
@@ -119,7 +122,7 @@ struct CurveFromEdgesOutput {
   Vector<Vector<int>> point_to_vert_maps;
 };
 
-static CurveFromEdgesOutput mesh_to_curve(Span<MVert> verts, Span<std::pair<int, int>> edges)
+static CurveFromEdgesOutput edges_to_curve(Span<MVert> verts, Span<std::pair<int, int>> edges)
 {
   std::unique_ptr<CurveEval> curve = std::make_unique<CurveEval>();
   Vector<Vector<int>> point_to_vert_maps;
@@ -252,63 +255,29 @@ static CurveFromEdgesOutput mesh_to_curve(Span<MVert> verts, Span<std::pair<int,
  * This helps to make the above algorithm simpler by removing the need to check for selection
  * in many places.
  */
-static Vector<std::pair<int, int>> get_selected_edges(GeoNodeExecParams params,
-                                                      const MeshComponent

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list