[Bf-blender-cvs] [d3788207aae] master: Geometry Nodes: Curve Primitive Quadratic Bezier Segment

Johnny Matthews noreply at git.blender.org
Wed Jun 30 05:39:46 CEST 2021


Commit: d3788207aae6e7a3546850a5d6e71ed552030cc0
Author: Johnny Matthews
Date:   Tue Jun 29 22:39:08 2021 -0500
Branches: master
https://developer.blender.org/rBd3788207aae6e7a3546850a5d6e71ed552030cc0

Geometry Nodes: Curve Primitive Quadratic Bezier Segment

This patch is for a node that creates a poly spline from a
3 point quadratic Bezier. Resolution is also specified.

Curve primitives design task: T89220

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

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

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_quadratic_bezier.cc

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

diff --git a/release/scripts/startup/nodeitems_builtins.py b/release/scripts/startup/nodeitems_builtins.py
index c963509938a..37dd4e635b5 100644
--- a/release/scripts/startup/nodeitems_builtins.py
+++ b/release/scripts/startup/nodeitems_builtins.py
@@ -512,6 +512,7 @@ geometry_node_categories = [
     GeometryNodeCategory("GEO_PRIMITIVES_CURVE", "Curve Primitives", items=[
         NodeItem("GeometryNodeCurveStar"),
         NodeItem("GeometryNodeCurveSpiral"),
+        NodeItem("GeometryNodeCurveQuadraticBezier"),
     ]),
     GeometryNodeCategory("GEO_GEOMETRY", "Geometry", items=[
         NodeItem("GeometryNodeBoundBox"),
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index 919a907cec8..daffd523161 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -1441,6 +1441,7 @@ int ntreeTexExecTree(struct bNodeTree *ntree,
 #define GEO_NODE_RAYCAST 1061
 #define GEO_NODE_CURVE_PRIMITIVE_STAR 1062
 #define GEO_NODE_CURVE_PRIMITIVE_SPIRAL 1063
+#define GEO_NODE_CURVE_PRIMITIVE_QUADRATIC_BEZIER 1064
 
 /** \} */
 
diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc
index b528a8a3e49..f23d6004824 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_quadratic_bezier();
   register_node_type_geo_curve_primitive_spiral();
   register_node_type_geo_curve_primitive_star();
   register_node_type_geo_curve_to_mesh();
diff --git a/source/blender/nodes/CMakeLists.txt b/source/blender/nodes/CMakeLists.txt
index eda8be582b6..2576756571c 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_quadratic_bezier.cc
   geometry/nodes/node_geo_curve_primitive_spiral.cc
   geometry/nodes/node_geo_curve_primitive_star.cc
   geometry/nodes/node_geo_curve_to_mesh.cc
diff --git a/source/blender/nodes/NOD_geometry.h b/source/blender/nodes/NOD_geometry.h
index f0e1ca4ec84..b3797c1834c 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_quadratic_bezier(void);
 void register_node_type_geo_curve_primitive_spiral(void);
 void register_node_type_geo_curve_primitive_star(void);
 void register_node_type_geo_curve_to_mesh(void);
diff --git a/source/blender/nodes/NOD_static_types.h b/source/blender/nodes/NOD_static_types.h
index 4c63c1627a1..5d2717b3bbd 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_QUADRATIC_BEZIER, 0, "CURVE_PRIMITIVE_QUADRATIC_BEZIER", CurveQuadraticBezier, "Quadratic Bezier", "")
 DefNode(GeometryNode, GEO_NODE_CURVE_PRIMITIVE_STAR, 0, "CURVE_PRIMITIVE_STAR", CurveStar, "Star", "")
 DefNode(GeometryNode, GEO_NODE_CURVE_PRIMITIVE_SPIRAL, 0, "CURVE_PRIMITIVE_SPIRAL", CurveSpiral, "Curve Spiral", "")
 DefNode(GeometryNode, GEO_NODE_CURVE_RESAMPLE, def_geo_curve_resample, "CURVE_RESAMPLE", CurveResample, "Resample Curve", "")
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadratic_bezier.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadratic_bezier.cc
new file mode 100644
index 00000000000..10211cb2287
--- /dev/null
+++ b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadratic_bezier.cc
@@ -0,0 +1,82 @@
+/*
+ * 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_quadratic_bezier_in[] = {
+    {SOCK_INT, N_("Resolution"), 16.0f, 0.0f, 0.0f, 0.0f, 3, 256, PROP_UNSIGNED},
+    {SOCK_VECTOR, N_("Start"), -1.0f, 0.0f, 0.0f, 0.0f, -FLT_MAX, FLT_MAX, PROP_TRANSLATION},
+    {SOCK_VECTOR, N_("Middle"), 0.0f, 2.0f, 0.0f, 0.0f, -FLT_MAX, FLT_MAX, PROP_TRANSLATION},
+    {SOCK_VECTOR, N_("End"), 1.0f, 0.0f, 0.0f, 0.0f, -FLT_MAX, FLT_MAX, PROP_TRANSLATION},
+    {-1, ""},
+};
+
+static bNodeSocketTemplate geo_node_curve_primitive_quadratic_bezier_out[] = {
+    {SOCK_GEOMETRY, N_("Curve")},
+    {-1, ""},
+};
+
+namespace blender::nodes {
+
+static std::unique_ptr<CurveEval> create_quadratic_bezier_curve(const float3 p1,
+                                                                const float3 p2,
+                                                                const float3 p3,
+                                                                const int resolution)
+{
+  std::unique_ptr<CurveEval> curve = std::make_unique<CurveEval>();
+  std::unique_ptr<PolySpline> spline = std::make_unique<PolySpline>();
+
+  const float step = 1.0f / resolution;
+  for (int i : IndexRange(resolution + 1)) {
+    const float factor = step * i;
+    const float3 q1 = float3::interpolate(p1, p2, factor);
+    const float3 q2 = float3::interpolate(p2, p3, factor);
+    const float3 out = float3::interpolate(q1, q2, factor);
+    spline->add_point(out, 1.0f, 0.0f);
+  }
+  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_quadratic_bezier_exec(GeoNodeExecParams params)
+{
+  std::unique_ptr<CurveEval> curve = create_quadratic_bezier_curve(
+      params.extract_input<float3>("Start"),
+      params.extract_input<float3>("Middle"),
+      params.extract_input<float3>("End"),
+      std::max(params.extract_input<int>("Resolution"), 3));
+  params.set_output("Curve", GeometrySet::create_with_curve(curve.release()));
+}
+
+}  // namespace blender::nodes
+
+void register_node_type_geo_curve_primitive_quadratic_bezier()
+{
+  static bNodeType ntype;
+  geo_node_type_base(&ntype,
+                     GEO_NODE_CURVE_PRIMITIVE_QUADRATIC_BEZIER,
+                     "Quadratic Bezier",
+                     NODE_CLASS_GEOMETRY,
+                     0);
+  node_type_socket_templates(&ntype,
+                             geo_node_curve_primitive_quadratic_bezier_in,
+                             geo_node_curve_primitive_quadratic_bezier_out);
+  ntype.geometry_node_execute = blender::nodes::geo_node_curve_primitive_quadratic_bezier_exec;
+  nodeRegisterType(&ntype);
+}



More information about the Bf-blender-cvs mailing list