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_mesh_primitive_cone.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_mesh_primitive_cone.cc')
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cone.cc31
1 files changed, 13 insertions, 18 deletions
diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cone.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cone.cc
index b834f5e2fa0..0d58476fc58 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cone.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cone.cc
@@ -25,18 +25,16 @@
#include "node_geometry_util.hh"
-static bNodeSocketTemplate geo_node_mesh_primitive_cone_in[] = {
- {SOCK_INT, N_("Vertices"), 32, 0.0f, 0.0f, 0.0f, 3, 4096},
- {SOCK_FLOAT, N_("Radius Top"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, FLT_MAX, PROP_DISTANCE},
- {SOCK_FLOAT, N_("Radius Bottom"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, FLT_MAX, PROP_DISTANCE},
- {SOCK_FLOAT, N_("Depth"), 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, FLT_MAX, PROP_DISTANCE},
- {-1, ""},
-};
-
-static bNodeSocketTemplate geo_node_mesh_primitive_cone_out[] = {
- {SOCK_GEOMETRY, N_("Geometry")},
- {-1, ""},
-};
+namespace blender::nodes {
+
+static void geo_node_mesh_primitive_cone_declare(NodeDeclarationBuilder &b)
+{
+ b.add_input<decl::Int>("Vertices").default_value(32).min(3);
+ b.add_input<decl::Float>("Radius Top").min(0.0f).subtype(PROP_DISTANCE);
+ b.add_input<decl::Float>("Radius Bottom").default_value(1.0f).min(0.0f).subtype(PROP_DISTANCE);
+ b.add_input<decl::Float>("Depth").default_value(2.0f).min(0.0f).subtype(PROP_DISTANCE);
+ b.add_output<decl::Geometry>("Geometry");
+}
static void geo_node_mesh_primitive_cone_layout(uiLayout *layout,
bContext *UNUSED(C),
@@ -57,8 +55,6 @@ static void geo_node_mesh_primitive_cone_init(bNodeTree *UNUSED(ntree), bNode *n
node->storage = node_storage;
}
-namespace blender::nodes {
-
static int vert_total(const GeometryNodeMeshCircleFillType fill_type,
const int verts_num,
const bool top_is_point,
@@ -575,12 +571,11 @@ void register_node_type_geo_mesh_primitive_cone()
static bNodeType ntype;
geo_node_type_base(&ntype, GEO_NODE_MESH_PRIMITIVE_CONE, "Cone", NODE_CLASS_GEOMETRY, 0);
- node_type_socket_templates(
- &ntype, geo_node_mesh_primitive_cone_in, geo_node_mesh_primitive_cone_out);
- node_type_init(&ntype, geo_node_mesh_primitive_cone_init);
+ node_type_init(&ntype, blender::nodes::geo_node_mesh_primitive_cone_init);
node_type_storage(
&ntype, "NodeGeometryMeshCone", node_free_standard_storage, node_copy_standard_storage);
ntype.geometry_node_execute = blender::nodes::geo_node_mesh_primitive_cone_exec;
- ntype.draw_buttons = geo_node_mesh_primitive_cone_layout;
+ ntype.draw_buttons = blender::nodes::geo_node_mesh_primitive_cone_layout;
+ ntype.declare = blender::nodes::geo_node_mesh_primitive_cone_declare;
nodeRegisterType(&ntype);
}