From c1b4abf527f102ca20114e8179eca511d90784b3 Mon Sep 17 00:00:00 2001 From: Johnny Matthews Date: Mon, 11 Oct 2021 11:03:57 -0500 Subject: Geometry Nodes: Add Nodes to Get/Set Built-in Attributes This commit implements T91780, adding nodes to get and set builtin attributes. Individual set nodes are used so that the values can be exposed for direct editing, which is useful for attributes like shade smooth and spline resolution. Individual input nodes are used to allow reusing nodes for multiple components, and to allow grouping multiple outputs conceptually in the same node in the future. Input Nodes - Radius - Curve Tilt - Curve Handle Positions - Is Shade Smooth - Spline Resolution - Is Spline Cyclic 'Set' Nodes - Curve Radius - Point Radius - Curve Tilt - Curve Handle Positions - Is Shade Smooth - Spline Resolution - Is Spline Cyclic Using hardcoded categories is necessary to add separators to the node menu. Differential Revision: https://developer.blender.org/D12687 --- .../geometry/nodes/node_geo_set_curve_tilt.cc | 78 ++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc (limited to 'source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc') diff --git a/source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc b/source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc new file mode 100644 index 00000000000..ee88b24fb04 --- /dev/null +++ b/source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc @@ -0,0 +1,78 @@ +/* + * 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 "node_geometry_util.hh" + +namespace blender::nodes { + +static void geo_node_set_curve_tilt_declare(NodeDeclarationBuilder &b) +{ + b.add_input("Geometry"); + b.add_input("Tilt").subtype(PROP_ANGLE).supports_field(); + b.add_input("Selection").default_value(true).hide_value().supports_field(); + b.add_output("Geometry"); +} + +static void set_tilt_in_component(GeometryComponent &component, + const Field &selection_field, + const Field &tilt_field) +{ + GeometryComponentFieldContext field_context{component, ATTR_DOMAIN_POINT}; + const int domain_size = component.attribute_domain_size(ATTR_DOMAIN_POINT); + if (domain_size == 0) { + return; + } + + fn::FieldEvaluator selection_evaluator{field_context, domain_size}; + selection_evaluator.add(selection_field); + selection_evaluator.evaluate(); + const IndexMask selection = selection_evaluator.get_evaluated_as_mask(0); + + OutputAttribute_Typed tilts = component.attribute_try_get_for_output_only( + "tilt", ATTR_DOMAIN_POINT); + fn::FieldEvaluator tilt_evaluator{field_context, &selection}; + tilt_evaluator.add_with_destination(tilt_field, tilts.varray()); + tilt_evaluator.evaluate(); + tilts.save(); +} + +static void geo_node_set_curve_tilt_exec(GeoNodeExecParams params) +{ + GeometrySet geometry_set = params.extract_input("Geometry"); + Field selection_field = params.extract_input>("Selection"); + Field tilt_field = params.extract_input>("Tilt"); + + geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) { + if (geometry_set.has_curve()) { + set_tilt_in_component( + geometry_set.get_component_for_write(), selection_field, tilt_field); + } + }); + + params.set_output("Geometry", std::move(geometry_set)); +} + +} // namespace blender::nodes + +void register_node_type_geo_set_curve_tilt() +{ + static bNodeType ntype; + + geo_node_type_base(&ntype, GEO_NODE_SET_CURVE_TILT, "Set Tilt", NODE_CLASS_GEOMETRY, 0); + ntype.geometry_node_execute = blender::nodes::geo_node_set_curve_tilt_exec; + ntype.declare = blender::nodes::geo_node_set_curve_tilt_declare; + nodeRegisterType(&ntype); +} -- cgit v1.2.3 From 2055ef107a7cb4e5aeeffb5ccc8a2908a59cd7d0 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Thu, 14 Oct 2021 15:36:24 -0500 Subject: Geometry Nodes: Order selection inputs after geometry inputs While there may be arguments for different positions of the selection inputs, it's important to be consistent, and putting them right after the corresponding geometry works well when there are multiple geometry inputs. Addresses T91646. --- source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc') diff --git a/source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc b/source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc index ee88b24fb04..113149613ef 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc @@ -21,8 +21,8 @@ namespace blender::nodes { static void geo_node_set_curve_tilt_declare(NodeDeclarationBuilder &b) { b.add_input("Geometry"); - b.add_input("Tilt").subtype(PROP_ANGLE).supports_field(); b.add_input("Selection").default_value(true).hide_value().supports_field(); + b.add_input("Tilt").subtype(PROP_ANGLE).supports_field(); b.add_output("Geometry"); } -- cgit v1.2.3 From 0bfae1b12078ef278a56c6e932c13be5bc9781aa Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Tue, 26 Oct 2021 20:00:03 +0200 Subject: Geometry Nodes: geometry component type warning system Previously, every node had to create warnings for unsupported input geometry manually. Now this is automated. Nodes just have to specify the geometry types they support in the node declaration. Differential Revision: https://developer.blender.org/D12899 --- source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc') diff --git a/source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc b/source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc index 113149613ef..2018b1668eb 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc @@ -20,7 +20,7 @@ namespace blender::nodes { static void geo_node_set_curve_tilt_declare(NodeDeclarationBuilder &b) { - b.add_input("Geometry"); + b.add_input("Geometry").supported_type(GEO_COMPONENT_TYPE_CURVE); b.add_input("Selection").default_value(true).hide_value().supports_field(); b.add_input("Tilt").subtype(PROP_ANGLE).supports_field(); b.add_output("Geometry"); -- cgit v1.2.3 From 87470169e07bfa9a06ea49232b78ca1f5da32fc3 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Wed, 27 Oct 2021 09:33:50 -0500 Subject: Geometry Nodes: Rename more geometry sockets This is a followup to rB827d7e7d252d48. After this we should be consistent everywhere with the hints in the names of geometry sockets. --- source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc') diff --git a/source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc b/source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc index 2018b1668eb..670d396dbc6 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc @@ -20,10 +20,10 @@ namespace blender::nodes { static void geo_node_set_curve_tilt_declare(NodeDeclarationBuilder &b) { - b.add_input("Geometry").supported_type(GEO_COMPONENT_TYPE_CURVE); + b.add_input("Curve").supported_type(GEO_COMPONENT_TYPE_CURVE); b.add_input("Selection").default_value(true).hide_value().supports_field(); b.add_input("Tilt").subtype(PROP_ANGLE).supports_field(); - b.add_output("Geometry"); + b.add_output("Curve"); } static void set_tilt_in_component(GeometryComponent &component, @@ -51,7 +51,7 @@ static void set_tilt_in_component(GeometryComponent &component, static void geo_node_set_curve_tilt_exec(GeoNodeExecParams params) { - GeometrySet geometry_set = params.extract_input("Geometry"); + GeometrySet geometry_set = params.extract_input("Curve"); Field selection_field = params.extract_input>("Selection"); Field tilt_field = params.extract_input>("Tilt"); @@ -62,7 +62,7 @@ static void geo_node_set_curve_tilt_exec(GeoNodeExecParams params) } }); - params.set_output("Geometry", std::move(geometry_set)); + params.set_output("Curve", std::move(geometry_set)); } } // namespace blender::nodes -- cgit v1.2.3 From 2383628ee11b6e90d34cd010f742c6d0356f5e11 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Fri, 29 Oct 2021 09:41:08 -0500 Subject: Nodes: Add translation markers to new socket names and descriptions As part of the refactor to the node declaration builders, we had hoped to add a regular expression specifically for these socket names, but recent discussions have revealed that using the translation marker macros is the preferred solution. If the names and descriptions were exposed to RNA, these would not be necessary. However, that may be quite complicated, since sockets are all instances of the same RNA types. Differential Revision: https://developer.blender.org/D13033 --- source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc') diff --git a/source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc b/source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc index 670d396dbc6..dde6d0bab92 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc @@ -20,10 +20,10 @@ namespace blender::nodes { static void geo_node_set_curve_tilt_declare(NodeDeclarationBuilder &b) { - b.add_input("Curve").supported_type(GEO_COMPONENT_TYPE_CURVE); - b.add_input("Selection").default_value(true).hide_value().supports_field(); - b.add_input("Tilt").subtype(PROP_ANGLE).supports_field(); - b.add_output("Curve"); + b.add_input(N_("Curve")).supported_type(GEO_COMPONENT_TYPE_CURVE); + b.add_input(N_("Selection")).default_value(true).hide_value().supports_field(); + b.add_input(N_("Tilt")).subtype(PROP_ANGLE).supports_field(); + b.add_output(N_("Curve")); } static void set_tilt_in_component(GeometryComponent &component, -- cgit v1.2.3 From 11392829adfebd95286586362323ed6a39c31a5c Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Tue, 2 Nov 2021 17:38:58 -0500 Subject: Fix T92316: Inconsistent name for Set Curve Tilt node --- source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc') diff --git a/source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc b/source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc index dde6d0bab92..a861c35f738 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc @@ -71,7 +71,7 @@ void register_node_type_geo_set_curve_tilt() { static bNodeType ntype; - geo_node_type_base(&ntype, GEO_NODE_SET_CURVE_TILT, "Set Tilt", NODE_CLASS_GEOMETRY, 0); + geo_node_type_base(&ntype, GEO_NODE_SET_CURVE_TILT, "Set Curve Tilt", NODE_CLASS_GEOMETRY, 0); ntype.geometry_node_execute = blender::nodes::geo_node_set_curve_tilt_exec; ntype.declare = blender::nodes::geo_node_set_curve_tilt_declare; nodeRegisterType(&ntype); -- cgit v1.2.3 From 1df8abff257030ba79bc23dc321f35494f4d91c5 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Tue, 23 Nov 2021 14:56:01 +0100 Subject: Geometry Nodes: add namespace for every file This puts all static functions in geometry node files into a new namespace. This allows using unity build which can improve compile times significantly (P2578). * The name space name is derived from the file name. That makes it possible to write some tooling that checks the names later on. The file name extension (`cc`) is added to the namespace name as well. This also possibly simplifies tooling but also makes it more obvious that this namespace is specific to a file. * In the register function of every node, I added a namespace alias `namespace file_ns = blender::nodes::node_geo_*_cc;`. This avoids some duplication of the file name and may also simplify tooling, because this line is easy to detect. The name `file_ns` stands for "file namespace" and also indicates that this namespace corresponds to the current file. In the beginning I used `node_ns` but `file_ns` is more generic which may make it more suitable when we want to use unity builds outside of the nodes modules in the future. * Some node files contain code that is actually shared between different nodes. For now I left that code in the `blender::nodes` namespace and moved it to the top of the file (couldn't move it to the bottom in all cases, so I just moved it to the top everywhere). As a separate cleanup step, this shared code should actually be moved to a separate file. Differential Revision: https://developer.blender.org/D13330 --- source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc') diff --git a/source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc b/source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc index a861c35f738..12440d5241f 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc @@ -16,7 +16,7 @@ #include "node_geometry_util.hh" -namespace blender::nodes { +namespace blender::nodes::node_geo_set_curve_tilt_cc { static void geo_node_set_curve_tilt_declare(NodeDeclarationBuilder &b) { @@ -65,14 +65,16 @@ static void geo_node_set_curve_tilt_exec(GeoNodeExecParams params) params.set_output("Curve", std::move(geometry_set)); } -} // namespace blender::nodes +} // namespace blender::nodes::node_geo_set_curve_tilt_cc void register_node_type_geo_set_curve_tilt() { + namespace file_ns = blender::nodes::node_geo_set_curve_tilt_cc; + static bNodeType ntype; geo_node_type_base(&ntype, GEO_NODE_SET_CURVE_TILT, "Set Curve Tilt", NODE_CLASS_GEOMETRY, 0); - ntype.geometry_node_execute = blender::nodes::geo_node_set_curve_tilt_exec; - ntype.declare = blender::nodes::geo_node_set_curve_tilt_declare; + ntype.geometry_node_execute = file_ns::geo_node_set_curve_tilt_exec; + ntype.declare = file_ns::geo_node_set_curve_tilt_declare; nodeRegisterType(&ntype); } -- cgit v1.2.3 From fab39440e94d94b0a6ea8ef7771312adbab98e66 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Tue, 23 Nov 2021 10:55:51 -0500 Subject: Cleanup: Simplify geometry node function names With this commit, we no longer use the prefixes for every node type function like `geo_node_translate_instances_`. They just added more places to change when adding a new node, for no real benefit. Differential Revision: https://developer.blender.org/D13337 --- source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc') diff --git a/source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc b/source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc index 12440d5241f..653ae39b4fa 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc @@ -18,7 +18,7 @@ namespace blender::nodes::node_geo_set_curve_tilt_cc { -static void geo_node_set_curve_tilt_declare(NodeDeclarationBuilder &b) +static void node_declare(NodeDeclarationBuilder &b) { b.add_input(N_("Curve")).supported_type(GEO_COMPONENT_TYPE_CURVE); b.add_input(N_("Selection")).default_value(true).hide_value().supports_field(); @@ -49,7 +49,7 @@ static void set_tilt_in_component(GeometryComponent &component, tilts.save(); } -static void geo_node_set_curve_tilt_exec(GeoNodeExecParams params) +static void node_geo_exec(GeoNodeExecParams params) { GeometrySet geometry_set = params.extract_input("Curve"); Field selection_field = params.extract_input>("Selection"); @@ -74,7 +74,7 @@ void register_node_type_geo_set_curve_tilt() static bNodeType ntype; geo_node_type_base(&ntype, GEO_NODE_SET_CURVE_TILT, "Set Curve Tilt", NODE_CLASS_GEOMETRY, 0); - ntype.geometry_node_execute = file_ns::geo_node_set_curve_tilt_exec; - ntype.declare = file_ns::geo_node_set_curve_tilt_declare; + ntype.geometry_node_execute = file_ns::node_geo_exec; + ntype.declare = file_ns::node_declare; nodeRegisterType(&ntype); } -- cgit v1.2.3 From 8e2c9f2dd3118bfdb69ccf0ab2b9f968a854aae4 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Tue, 14 Dec 2021 15:40:16 +0100 Subject: Geometry Nodes: simplify using selection when evaluating fields We often had to use two `FieldEvaluator` instances to first evaluate the selection and then the remaining fields. Now both can be done with a single `FieldEvaluator`. This results in less boilerplate code in many cases. Performance is not affected by this change. In a separate patch we could improve performance by reusing evaluated sub-fields that are used by the selection and the other fields. Differential Revision: https://developer.blender.org/D13571 --- .../nodes/geometry/nodes/node_geo_set_curve_tilt.cc | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc') diff --git a/source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc b/source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc index 653ae39b4fa..447310e1ad7 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc @@ -36,16 +36,14 @@ static void set_tilt_in_component(GeometryComponent &component, return; } - fn::FieldEvaluator selection_evaluator{field_context, domain_size}; - selection_evaluator.add(selection_field); - selection_evaluator.evaluate(); - const IndexMask selection = selection_evaluator.get_evaluated_as_mask(0); - OutputAttribute_Typed tilts = component.attribute_try_get_for_output_only( "tilt", ATTR_DOMAIN_POINT); - fn::FieldEvaluator tilt_evaluator{field_context, &selection}; - tilt_evaluator.add_with_destination(tilt_field, tilts.varray()); - tilt_evaluator.evaluate(); + + fn::FieldEvaluator evaluator{field_context, domain_size}; + evaluator.set_selection(selection_field); + evaluator.add_with_destination(tilt_field, tilts.varray()); + evaluator.evaluate(); + tilts.save(); } -- cgit v1.2.3 From d3ad04172de2b928aeb561b74a58996586b1db1c Mon Sep 17 00:00:00 2001 From: Aaron Carlisle Date: Mon, 3 Jan 2022 19:32:33 -0500 Subject: Cleanup: Remove bNodeType flag from base registration functions This flag is only used a few small cases, so instead of setting the flag for every node only set the required flag for the nodes that require it. Mostly the flag is used to set `ntype.flag = NODE_PREVIEW` For nodes that should have previews by default which is only some compositor nodes and some texture nodes. The frame node also sets the `NODE_BACKGROUND` flag. All other nodes were setting a flag of 0 which has no purpose. Reviewed By: JacquesLucke Differential Revision: https://developer.blender.org/D13699 --- source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc') diff --git a/source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc b/source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc index 447310e1ad7..0854d0a4549 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc @@ -71,7 +71,7 @@ void register_node_type_geo_set_curve_tilt() static bNodeType ntype; - geo_node_type_base(&ntype, GEO_NODE_SET_CURVE_TILT, "Set Curve Tilt", NODE_CLASS_GEOMETRY, 0); + geo_node_type_base(&ntype, GEO_NODE_SET_CURVE_TILT, "Set Curve Tilt", NODE_CLASS_GEOMETRY); ntype.geometry_node_execute = file_ns::node_geo_exec; ntype.declare = file_ns::node_declare; nodeRegisterType(&ntype); -- cgit v1.2.3