[Bf-blender-cvs] [86c6769e203] master: Geometry Nodes: Curve Primitive Spiral

Johnny Matthews noreply at git.blender.org
Wed Jun 30 05:02:36 CEST 2021


Commit: 86c6769e203366d5f039869cb26e9f4d85ca205b
Author: Johnny Matthews
Date:   Tue Jun 29 22:00:29 2021 -0500
Branches: master
https://developer.blender.org/rB86c6769e203366d5f039869cb26e9f4d85ca205b

Geometry Nodes: Curve Primitive Spiral

This patch adds a Curve Primitives menu in Geometry nodes with an
initial entry of a star primitive.

The node is a basic star pattern node that outputs a poly spline.
Options control the inner and outer radius, the number of points,
and the twist of the valleys.

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

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

M	release/scripts/startup/nodeitems_builtins.py
M	source/blender/blenkernel/BKE_node.h
M	source/blender/blenkernel/intern/node.cc
M	source/blender/nodes/CMakeLists.txt
M	source/blender/nodes/NOD_geometry.h
M	source/blender/nodes/NOD_static_types.h
A	source/blender/nodes/geometry/nodes/node_geo_curve_primitive_star.cc

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

diff --git a/release/scripts/startup/nodeitems_builtins.py b/release/scripts/startup/nodeitems_builtins.py
index e7d991622e8..2a85246fe50 100644
--- a/release/scripts/startup/nodeitems_builtins.py
+++ b/release/scripts/startup/nodeitems_builtins.py
@@ -509,6 +509,9 @@ geometry_node_categories = [
         NodeItem("GeometryNodeCurveLength"),
         NodeItem("GeometryNodeCurveReverse"),
     ]),
+    GeometryNodeCategory("GEO_PRIMITIVES_CURVE", "Curve Primitives", items=[
+        NodeItem("GeometryNodeCurveStar"),
+    ]),
     GeometryNodeCategory("GEO_GEOMETRY", "Geometry", items=[
         NodeItem("GeometryNodeBoundBox"),
         NodeItem("GeometryNodeConvexHull"),
@@ -540,7 +543,7 @@ geometry_node_categories = [
         NodeItem("GeometryNodeSubdivisionSurface"),
         NodeItem("GeometryNodeSubdivide"),
     ]),
-    GeometryNodeCategory("GEO_PRIMITIVES", "Mesh Primitives", items=[
+    GeometryNodeCategory("GEO_PRIMITIVES_MESH", "Mesh Primitives", items=[
         NodeItem("GeometryNodeMeshCircle"),
         NodeItem("GeometryNodeMeshCone"),
         NodeItem("GeometryNodeMeshCube"),
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index a0f6be6b3e9..84b60d18ee0 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -1439,6 +1439,7 @@ int ntreeTexExecTree(struct bNodeTree *ntree,
 #define GEO_NODE_SEPARATE_COMPONENTS 1059
 #define GEO_NODE_CURVE_SUBDIVIDE 1060
 #define GEO_NODE_RAYCAST 1061
+#define GEO_NODE_CURVE_PRIMITIVE_STAR 1062
 
 /** \} */
 
diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc
index cf0dd75ea9d..7e8047c8e3f 100644
--- a/source/blender/blenkernel/intern/node.cc
+++ b/source/blender/blenkernel/intern/node.cc
@@ -5054,6 +5054,7 @@ static void registerGeometryNodes()
   register_node_type_geo_collection_info();
   register_node_type_geo_convex_hull();
   register_node_type_geo_curve_length();
+  register_node_type_geo_curve_primitive_star();
   register_node_type_geo_curve_to_mesh();
   register_node_type_geo_curve_to_points();
   register_node_type_geo_curve_resample();
diff --git a/source/blender/nodes/CMakeLists.txt b/source/blender/nodes/CMakeLists.txt
index 39f26737620..65490f98cbf 100644
--- a/source/blender/nodes/CMakeLists.txt
+++ b/source/blender/nodes/CMakeLists.txt
@@ -164,6 +164,7 @@ set(SRC
   geometry/nodes/node_geo_common.cc
   geometry/nodes/node_geo_convex_hull.cc
   geometry/nodes/node_geo_curve_length.cc  
+  geometry/nodes/node_geo_curve_primitive_star.cc
   geometry/nodes/node_geo_curve_to_mesh.cc
   geometry/nodes/node_geo_curve_to_points.cc
   geometry/nodes/node_geo_curve_resample.cc
diff --git a/source/blender/nodes/NOD_geometry.h b/source/blender/nodes/NOD_geometry.h
index fddaaf6e640..aee26d1444c 100644
--- a/source/blender/nodes/NOD_geometry.h
+++ b/source/blender/nodes/NOD_geometry.h
@@ -52,6 +52,7 @@ void register_node_type_geo_bounding_box(void);
 void register_node_type_geo_collection_info(void);
 void register_node_type_geo_convex_hull(void);
 void register_node_type_geo_curve_length(void);
+void register_node_type_geo_curve_primitive_star(void);
 void register_node_type_geo_curve_to_mesh(void);
 void register_node_type_geo_curve_to_points(void);
 void register_node_type_geo_curve_resample(void);
diff --git a/source/blender/nodes/NOD_static_types.h b/source/blender/nodes/NOD_static_types.h
index d79fa7bffb3..a7a69522421 100644
--- a/source/blender/nodes/NOD_static_types.h
+++ b/source/blender/nodes/NOD_static_types.h
@@ -291,6 +291,7 @@ DefNode(GeometryNode, GEO_NODE_BOUNDING_BOX, 0, "BOUNDING_BOX", BoundBox, "Bound
 DefNode(GeometryNode, GEO_NODE_COLLECTION_INFO, def_geo_collection_info, "COLLECTION_INFO", CollectionInfo, "Collection Info", "")
 DefNode(GeometryNode, GEO_NODE_CONVEX_HULL, 0, "CONVEX_HULL", ConvexHull, "Convex Hull", "")
 DefNode(GeometryNode, GEO_NODE_CURVE_LENGTH, 0, "CURVE_LENGTH", CurveLength, "Curve Length", "")
+DefNode(GeometryNode, GEO_NODE_CURVE_PRIMITIVE_STAR, 0, "CURVE_PRIMITIVE_STAR", CurveStar, "Star", "")
 DefNode(GeometryNode, GEO_NODE_CURVE_RESAMPLE, def_geo_curve_resample, "CURVE_RESAMPLE", CurveResample, "Resample Curve", "")
 DefNode(GeometryNode, GEO_NODE_CURVE_SUBDIVIDE, def_geo_curve_subdivide, "CURVE_SUBDIVIDE", CurveSubdivide, "Curve Subdivide", "")
 DefNode(GeometryNode, GEO_NODE_CURVE_TO_MESH, 0, "CURVE_TO_MESH", CurveToMesh, "Curve to Mesh", "")
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_star.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_star.cc
new file mode 100644
index 00000000000..367da3bc3c2
--- /dev/null
+++ b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_star.cc
@@ -0,0 +1,81 @@
+/*
+ * 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 "BKE_spline.hh"
+
+#include "node_geometry_util.hh"
+
+static bNodeSocketTemplate geo_node_curve_primitive_star_in[] = {
+    {SOCK_INT, N_("Points"), 8.0f, 0.0f, 0.0f, 0.0f, 4, 256, PROP_UNSIGNED},
+    {SOCK_FLOAT, N_("Inner Radius"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, FLT_MAX, PROP_DISTANCE},
+    {SOCK_FLOAT, N_("Outer Radius"), 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, FLT_MAX, PROP_DISTANCE},
+    {SOCK_FLOAT, N_("Twist"), 0.0f, 0.0f, 0.0f, 0.0f, -FLT_MAX, FLT_MAX, PROP_ANGLE},
+    {-1, ""},
+};
+
+static bNodeSocketTemplate geo_node_curve_primitive_star_out[] = {
+    {SOCK_GEOMETRY, N_("Curve")},
+    {-1, ""},
+};
+
+namespace blender::nodes {
+
+static std::unique_ptr<CurveEval> create_star_curve(const float inner_radius,
+                                                    const float outer_radius,
+                                                    const float twist,
+                                                    const int points)
+{
+  std::unique_ptr<CurveEval> curve = std::make_unique<CurveEval>();
+  std::unique_ptr<PolySpline> spline = std::make_unique<PolySpline>();
+
+  const float theta_step = (2.0f * M_PI) / float(points);
+  for (int i : IndexRange(points)) {
+    const float x = outer_radius * cos(theta_step * i);
+    const float y = outer_radius * sin(theta_step * i);
+    spline->add_point(float3(x, y, 0.0f), 1.0f, 0.0f);
+
+    const float inner_x = inner_radius * cos(theta_step * i + theta_step * 0.5f + twist);
+    const float inner_y = inner_radius * sin(theta_step * i + theta_step * 0.5f + twist);
+    spline->add_point(float3(inner_x, inner_y, 0.0f), 1.0f, 0.0f);
+  }
+  spline->set_cyclic(true);
+  spline->attributes.reallocate(spline->size());
+  curve->add_spline(std::move(spline));
+  curve->attributes.reallocate(curve->splines().size());
+  return curve;
+}
+
+static void geo_node_curve_primitive_star_exec(GeoNodeExecParams params)
+{
+  std::unique_ptr<CurveEval> curve = create_star_curve(
+      std::max(params.extract_input<float>("Inner Radius"), 0.0f),
+      std::max(params.extract_input<float>("Outer Radius"), 0.0f),
+      params.extract_input<float>("Twist"),
+      std::max(params.extract_input<int>("Points"), 4));
+  params.set_output("Curve", GeometrySet::create_with_curve(curve.release()));
+}
+
+}  // namespace blender::nodes
+
+void register_node_type_geo_curve_primitive_star()
+{
+  static bNodeType ntype;
+  geo_node_type_base(&ntype, GEO_NODE_CURVE_PRIMITIVE_STAR, "Star", NODE_CLASS_GEOMETRY, 0);
+  node_type_socket_templates(
+      &ntype, geo_node_curve_primitive_star_in, geo_node_curve_primitive_star_out);
+  ntype.geometry_node_execute = blender::nodes::geo_node_curve_primitive_star_exec;
+  nodeRegisterType(&ntype);
+}



More information about the Bf-blender-cvs mailing list