Commit: 8884d2d61b3d60d44d4f8aecaba1d0fd121b0bf3 Author: Johnny Matthews Date: Wed Jun 30 00:03:55 2021 -0500 Branches: master https://developer.blender.org/rB8884d2d61b3d60d44d4f8aecaba1d0fd121b0bf3
Geometry Nodes: Curve Primitive Bezier Segment Creates a Curve with 1 Bezier Spline from four positions (start, start handle, end handle, end) and a resolution. The handles are aligned and mirrored automatically. An "Offset" mode is also included to allow specifying the handles relative to the control points. The default settings recreate the existing default Bezier Curve in the 3D viewport add menu. Differential Revision: https://developer.blender.org/D11648 =================================================================== M release/scripts/startup/nodeitems_builtins.py M source/blender/blenkernel/BKE_node.h M source/blender/blenkernel/intern/node.cc M source/blender/makesdna/DNA_node_types.h M source/blender/makesrna/intern/rna_nodetree.c 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_bezier_segment.cc =================================================================== diff --git a/release/scripts/startup/nodeitems_builtins.py b/release/scripts/startup/nodeitems_builtins.py index 37dd4e635b5..4dff242bd9f 100644 --- a/release/scripts/startup/nodeitems_builtins.py +++ b/release/scripts/startup/nodeitems_builtins.py @@ -513,6 +513,7 @@ geometry_node_categories = [ NodeItem("GeometryNodeCurveStar"), NodeItem("GeometryNodeCurveSpiral"), NodeItem("GeometryNodeCurveQuadraticBezier"), + NodeItem("GeometryNodeCurvePrimitiveBezierSegment"), ]), GeometryNodeCategory("GEO_GEOMETRY", "Geometry", items=[ NodeItem("GeometryNodeBoundBox"), diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index daffd523161..27f9edac731 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -1442,6 +1442,7 @@ int ntreeTexExecTree(struct bNodeTree *ntree, #define GEO_NODE_CURVE_PRIMITIVE_STAR 1062 #define GEO_NODE_CURVE_PRIMITIVE_SPIRAL 1063 #define GEO_NODE_CURVE_PRIMITIVE_QUADRATIC_BEZIER 1064 +#define GEO_NODE_CURVE_PRIMITIVE_BEZIER_SEGMENT 1065 /** \} */ diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc index f23d6004824..87b069d7c50 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_bezier_segment(); register_node_type_geo_curve_primitive_quadratic_bezier(); register_node_type_geo_curve_primitive_spiral(); register_node_type_geo_curve_primitive_star(); diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h index 12625d3408d..480a8c03c41 100644 --- a/source/blender/makesdna/DNA_node_types.h +++ b/source/blender/makesdna/DNA_node_types.h @@ -1357,6 +1357,11 @@ typedef struct NodeSwitch { uint8_t input_type; } NodeSwitch; +typedef struct NodeGeometryCurvePrimitiveBezierSegment { + /* GeometryNodeCurvePrimitiveBezierSegmentMode. */ + uint8_t mode; +} NodeGeometryCurvePrimitiveBezierSegment; + typedef struct NodeGeometryCurveResample { /* GeometryNodeCurveSampleMode. */ uint8_t mode; @@ -1889,6 +1894,11 @@ typedef enum GeometryNodeMeshLineCountMode { GEO_NODE_MESH_LINE_COUNT_RESOLUTION = 1, } GeometryNodeMeshLineCountMode; +typedef enum GeometryNodeCurvePrimitiveBezierSegmentMode { + GEO_NODE_CURVE_PRIMITIVE_BEZIER_SEGMENT_POSITION = 0, + GEO_NODE_CURVE_PRIMITIVE_BEZIER_SEGMENT_OFFSET = 1, +} GeometryNodeCurvePrimitiveBezierSegmentMode; + typedef enum GeometryNodeCurveSampleMode { GEO_NODE_CURVE_SAMPLE_COUNT = 0, GEO_NODE_CURVE_SAMPLE_LENGTH = 1, diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c index 13abadf809b..b3f46509955 100644 --- a/source/blender/makesrna/intern/rna_nodetree.c +++ b/source/blender/makesrna/intern/rna_nodetree.c @@ -8967,6 +8967,33 @@ static void def_geo_boolean(StructRNA *srna) RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update"); } +static void def_geo_curve_primitive_bezier_segment(StructRNA *srna) +{ + static const EnumPropertyItem mode_items[] = { + + {GEO_NODE_CURVE_PRIMITIVE_BEZIER_SEGMENT_POSITION, + "POSITION", + ICON_NONE, + "Position", + "The start and end handles are fixed positions"}, + {GEO_NODE_CURVE_PRIMITIVE_BEZIER_SEGMENT_OFFSET, + "OFFSET", + ICON_NONE, + "Offset", + "The start and end handles are offsets from the spline's control points"}, + {0, NULL, 0, NULL, NULL}, + }; + + PropertyRNA *prop; + + RNA_def_struct_sdna_from(srna, "NodeGeometryCurvePrimitiveBezierSegment", "storage"); + + prop = RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_items(prop, mode_items); + RNA_def_property_ui_text(prop, "Mode", "Method used to determine control handles"); + RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update"); +} + static void def_geo_triangulate(StructRNA *srna) { PropertyRNA *prop; diff --git a/source/blender/nodes/CMakeLists.txt b/source/blender/nodes/CMakeLists.txt index 2576756571c..926a81e87fd 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_bezier_segment.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 diff --git a/source/blender/nodes/NOD_geometry.h b/source/blender/nodes/NOD_geometry.h index b3797c1834c..ba646e7654a 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_bezier_segment(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); diff --git a/source/blender/nodes/NOD_static_types.h b/source/blender/nodes/NOD_static_types.h index 5d2717b3bbd..19256f7383a 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_BEZIER_SEGMENT, def_geo_curve_primitive_bezier_segment, "CURVE_PRIMITIVE_BEZIER_SEGMENT", CurvePrimitiveBezierSegment, "Bezier Segment", "") 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", "") diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_bezier_segment.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_bezier_segment.cc new file mode 100644 index 00000000000..e167219ea6b --- /dev/null +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_bezier_segment.cc @@ -0,0 +1,149 @@ +/* + * 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 "UI_interface.h" +#include "UI_resources.h" + +#include "node_geometry_util.hh" + +static bNodeSocketTemplate geo_node_curve_primitive_bezier_segment_in[] = { + {SOCK_INT, N_("Resolution"), 16.0f, 0.0f, 0.0f, 0.0f, 1, 256, PROP_UNSIGNED}, + {SOCK_VECTOR, N_("Start"), -1.0f, 0.0f, 0.0f, 0.0f, -FLT_MAX, FLT_MAX, PROP_TRANSLATION}, + {SOCK_VECTOR, + N_("Start Handle"), + -0.5f, + 0.5f, + 0.0f, + 0.0f, + -FLT_MAX, + FLT_MAX, + PROP_TRANSLATION}, + {SOCK_VECTOR, N_("End Handle"), 0.0f, 0.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_bezier_segment_out[] = { + {SOCK_GEOMETRY, N_("Curve")}, + {-1, ""}, +}; +static void geo_node_curve_primitive_bezier_segment_layout(uiLayout *layout, + bContext *UNUSED(C), + PointerRNA *ptr) +{ + uiItemR(layout, ptr, "mode", UI_ITEM_R_EXPAND, nullptr, ICON_NONE); +} + +namespace blender::nodes { + +static void geo_node_curve_primitive_bezier_segment_init(bNodeTree *UNUSED(tree), bNode *node) +{ + NodeGeometryCurvePrimitiveBezierSegment *data = (NodeGeometryCurvePrimitiveBezierSegment *) + MEM_callocN(sizeof(NodeGeometryCurvePrimitiveBezierSegment), __func__); + + data->mode = GEO_NODE_CURVE_PRIMITIVE_BEZIER_SEGMENT_POSITION; + node->storage = data; +} + +static std::unique_ptr<CurveEval> create_bezier_segment_curve( + const float3 start, + const float3 start_handle_right, + const float3 end, + const float3 end_handle_left, + const int resolution, + const GeometryNodeCurvePrimitiveBezierSegmentMode mode) +{ + std::unique_ptr<CurveEval> curve = std::make_unique<CurveEval>(); + std::unique_ptr<BezierSpline> spline = std::make_unique<BezierSpline>(); + + if (mode == GEO_NODE_CURVE_PRIMITIVE_BEZIER_SEGMENT_POSITION) { + spline->add_point(start, + BezierSpline::HandleType::Align, + start - (start_handle_right - start) * -1.0f, + BezierSpline::HandleType::Align, + start_handle_right, + 1.0f, + 0.0f); + spline->add_point(end, + @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs