Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2021-08-30 18:13:46 +0300
committerJacques Lucke <jacques@blender.org>2021-08-30 18:23:05 +0300
commit1e69a25043120cc8dddc3f58622eb50e1443def1 (patch)
tree16bcb3eb98215dbbd5c54880cb3d14544e316d3f /source/blender/nodes/geometry/nodes/node_geo_curve_trim.cc
parente8684eff301d09e25b4e7ef6221a5289661da2e3 (diff)
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
Diffstat (limited to 'source/blender/nodes/geometry/nodes/node_geo_curve_trim.cc')
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_curve_trim.cc32
1 files changed, 14 insertions, 18 deletions
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<decl::Geometry>("Curve");
+ b.add_input<decl::Float>("Start").min(0.0f).max(1.0f).subtype(PROP_FACTOR);
+ b.add_input<decl::Float>("End").min(0.0f).max(1.0f).subtype(PROP_FACTOR);
+ b.add_input<decl::Float>("Start", "Start_001").min(0.0f).subtype(PROP_DISTANCE);
+ b.add_input<decl::Float>("End", "End_001").min(0.0f).subtype(PROP_DISTANCE);
+ b.add_output<decl::Geometry>("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);
}