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
This commit is contained in:
Johnny Matthews 2021-06-29 22:39:08 -05:00 committed by Hans Goudey
parent 21ebee2580
commit d3788207aa
Notes: blender-bot 2023-05-31 04:43:10 +02:00
Referenced by issue #89220, Curve Primitive Nodes
7 changed files with 88 additions and 0 deletions

View File

@ -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"),

View File

@ -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
/** \} */

View File

@ -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();

View File

@ -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

View File

@ -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);

View File

@ -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", "")

View File

@ -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);
}