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:
authorJohnny Matthews <johnny.matthews@gmail.com>2022-10-03 23:50:21 +0300
committerJohnny Matthews <johnny.matthews@gmail.com>2022-10-03 23:50:21 +0300
commit748fda32ede88887e1baeccca5c119326e031dd6 (patch)
tree652739a7349b1ca901cb2dad8b049014e0e99b6c /source/blender/nodes/geometry
parentb475506cfbd35fe2d356ce43a6a3e1f93bd6602b (diff)
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
Diffstat (limited to 'source/blender/nodes/geometry')
-rw-r--r--source/blender/nodes/geometry/CMakeLists.txt1
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_set_curve_normal.cc73
2 files changed, 74 insertions, 0 deletions
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<decl::Geometry>(N_("Curve")).supported_type(GEO_COMPONENT_TYPE_CURVE);
+ b.add_input<decl::Bool>(N_("Selection")).default_value(true).hide_value().supports_field();
+ b.add_output<decl::Geometry>(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<bool> &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<NormalMode>(params.node().custom1);
+
+ GeometrySet geometry_set = params.extract_input<GeometrySet>("Curve");
+ Field<bool> selection_field = params.extract_input<Field<bool>>("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);
+}