From 1e69a25043120cc8dddc3f58622eb50e1443def1 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Mon, 30 Aug 2021 17:13:46 +0200 Subject: Nodes: add more flexible method to declare sockets of a node Previously, built-in nodes had to implement "socket templates" (`bNodeSocketTemplate`) to tell Blender which sockets they have. It was nice that this was declarative, but this approach was way too rigid and was cumbersome to use in many cases. This commit starts to move us away from this rigid structure by letting nodes implement a function that declares the sockets the node has. Right now this is used as a direct replacement of the "socket template" approach to keep the refactor smaller. It's just a bit easier to read and write. In the future we want to support more complex features like dynamic numbers of sockets and type inferencing. Those features will be easier to build on this new approach. This new approach can live side by side with `bNodeSocketTemplate` for a while. That makes it easier to update nodes one by one. Note: In `bNodeSocketTemplate` socket identifiers were made unique automatically. In this new approach, one has to specify unique identifiers manually (unless the name is unique already). Differential Revision: https://developer.blender.org/D12335 --- .../nodes/geometry/nodes/node_geo_curve_trim.cc | 32 ++++++++++------------ 1 file changed, 14 insertions(+), 18 deletions(-) (limited to 'source/blender/nodes/geometry/nodes/node_geo_curve_trim.cc') diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_trim.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_trim.cc index f9415c6d27b..578f0298a19 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_trim.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_trim.cc @@ -24,19 +24,17 @@ using blender::attribute_math::mix2; -static bNodeSocketTemplate geo_node_curve_trim_in[] = { - {SOCK_GEOMETRY, N_("Curve")}, - {SOCK_FLOAT, N_("Start"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, - {SOCK_FLOAT, N_("End"), 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, PROP_FACTOR}, - {SOCK_FLOAT, N_("Start"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 10000.0f, PROP_DISTANCE}, - {SOCK_FLOAT, N_("End"), 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 10000.0f, PROP_DISTANCE}, - {-1, ""}, -}; +namespace blender::nodes { -static bNodeSocketTemplate geo_node_curve_trim_out[] = { - {SOCK_GEOMETRY, N_("Curve")}, - {-1, ""}, -}; +static void geo_node_curve_trim_declare(NodeDeclarationBuilder &b) +{ + b.add_input("Curve"); + b.add_input("Start").min(0.0f).max(1.0f).subtype(PROP_FACTOR); + b.add_input("End").min(0.0f).max(1.0f).subtype(PROP_FACTOR); + b.add_input("Start", "Start_001").min(0.0f).subtype(PROP_DISTANCE); + b.add_input("End", "End_001").min(0.0f).subtype(PROP_DISTANCE); + b.add_output("Curve"); +} static void geo_node_curve_trim_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { @@ -69,8 +67,6 @@ static void geo_node_curve_trim_update(bNodeTree *UNUSED(ntree), bNode *node) nodeSetSocketAvailability(end_len, mode == GEO_NODE_CURVE_INTERPOLATE_LENGTH); } -namespace blender::nodes { - struct TrimLocation { /* Control point index at the start side of the trim location. */ int left_index; @@ -399,12 +395,12 @@ void register_node_type_geo_curve_trim() { static bNodeType ntype; geo_node_type_base(&ntype, GEO_NODE_CURVE_TRIM, "Curve Trim", NODE_CLASS_GEOMETRY, 0); - node_type_socket_templates(&ntype, geo_node_curve_trim_in, geo_node_curve_trim_out); ntype.geometry_node_execute = blender::nodes::geo_node_curve_trim_exec; - ntype.draw_buttons = geo_node_curve_trim_layout; + ntype.draw_buttons = blender::nodes::geo_node_curve_trim_layout; + ntype.declare = blender::nodes::geo_node_curve_trim_declare; node_type_storage( &ntype, "NodeGeometryCurveTrim", node_free_standard_storage, node_copy_standard_storage); - node_type_init(&ntype, geo_node_curve_trim_init); - node_type_update(&ntype, geo_node_curve_trim_update); + node_type_init(&ntype, blender::nodes::geo_node_curve_trim_init); + node_type_update(&ntype, blender::nodes::geo_node_curve_trim_update); nodeRegisterType(&ntype); } -- cgit v1.2.3