From 748fda32ede88887e1baeccca5c119326e031dd6 Mon Sep 17 00:00:00 2001 From: Johnny Matthews Date: Mon, 3 Oct 2022 15:50:21 -0500 Subject: Geometry Nodes: Set Curve Normal This node allows for curves to have their evaluated normal mode changed between MINIMUM_TWIST and Z_UP. A selection input allows for choosing which spline in the curves object will be affected. Differential Revision: D16118 --- source/blender/nodes/geometry/CMakeLists.txt | 1 + .../geometry/nodes/node_geo_set_curve_normal.cc | 73 ++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 source/blender/nodes/geometry/nodes/node_geo_set_curve_normal.cc (limited to 'source/blender/nodes/geometry') diff --git a/source/blender/nodes/geometry/CMakeLists.txt b/source/blender/nodes/geometry/CMakeLists.txt index a81bbec071b..d8391871571 100644 --- a/source/blender/nodes/geometry/CMakeLists.txt +++ b/source/blender/nodes/geometry/CMakeLists.txt @@ -148,6 +148,7 @@ set(SRC nodes/node_geo_separate_components.cc nodes/node_geo_separate_geometry.cc nodes/node_geo_set_curve_handles.cc + nodes/node_geo_set_curve_normal.cc nodes/node_geo_set_curve_radius.cc nodes/node_geo_set_curve_tilt.cc nodes/node_geo_set_id.cc diff --git a/source/blender/nodes/geometry/nodes/node_geo_set_curve_normal.cc b/source/blender/nodes/geometry/nodes/node_geo_set_curve_normal.cc new file mode 100644 index 00000000000..bac15622c2a --- /dev/null +++ b/source/blender/nodes/geometry/nodes/node_geo_set_curve_normal.cc @@ -0,0 +1,73 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include "BKE_curves.hh" + +#include "UI_interface.h" +#include "UI_resources.h" + +#include "node_geometry_util.hh" + +namespace blender::nodes::node_geo_set_curve_normal_cc { + +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(); + b.add_output(N_("Curve")); +} + +static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) +{ + uiItemR(layout, ptr, "mode", 0, nullptr, ICON_NONE); +} + +static void node_init(bNodeTree *UNUSED(tree), bNode *node) +{ + node->custom1 = NORMAL_MODE_MINIMUM_TWIST; +} + +static void set_normal_mode(bke::CurvesGeometry &curves, + const NormalMode mode, + const Field &selection_field) +{ + bke::CurvesFieldContext field_context{curves, ATTR_DOMAIN_CURVE}; + fn::FieldEvaluator evaluator{field_context, curves.curves_num()}; + evaluator.set_selection(selection_field); + evaluator.evaluate(); + const IndexMask selection = evaluator.get_evaluated_selection_as_mask(); + curves.normal_mode_for_write().fill_indices(selection, mode); + curves.tag_normals_changed(); +} + +static void node_geo_exec(GeoNodeExecParams params) +{ + const NormalMode mode = static_cast(params.node().custom1); + + GeometrySet geometry_set = params.extract_input("Curve"); + Field selection_field = params.extract_input>("Selection"); + + geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) { + if (Curves *curves_id = geometry_set.get_curves_for_write()) { + bke::CurvesGeometry &curves = bke::CurvesGeometry::wrap(curves_id->geometry); + set_normal_mode(curves, mode, selection_field); + } + }); + + params.set_output("Curve", std::move(geometry_set)); +} + +} // namespace blender::nodes::node_geo_set_curve_normal_cc + +void register_node_type_geo_set_curve_normal() +{ + namespace file_ns = blender::nodes::node_geo_set_curve_normal_cc; + + static bNodeType ntype; + geo_node_type_base(&ntype, GEO_NODE_SET_CURVE_NORMAL, "Set Curve Normal", NODE_CLASS_GEOMETRY); + ntype.declare = file_ns::node_declare; + ntype.geometry_node_execute = file_ns::node_geo_exec; + node_type_init(&ntype, file_ns::node_init); + ntype.draw_buttons = file_ns::node_layout; + + nodeRegisterType(&ntype); +} -- cgit v1.2.3