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
This commit is contained in:
Johnny Matthews 2022-10-03 15:50:21 -05:00
parent b475506cfb
commit 748fda32ed
10 changed files with 98 additions and 0 deletions

View File

@ -62,6 +62,7 @@ class NODE_MT_geometry_node_GEO_CURVE(Menu):
node_add_menu.add_node_type(layout, "GeometryNodeSplineParameter")
node_add_menu.add_node_type(layout, "GeometryNodeInputSplineResolution")
layout.separator()
node_add_menu.add_node_type(layout, "GeometryNodeSetCurveNormal")
node_add_menu.add_node_type(layout, "GeometryNodeSetCurveRadius")
node_add_menu.add_node_type(layout, "GeometryNodeSetCurveTilt")
node_add_menu.add_node_type(layout, "GeometryNodeSetCurveHandlePositions")

View File

@ -1542,6 +1542,7 @@ struct TexResult;
#define GEO_NODE_MESH_TOPOLOGY_FACE_OF_CORNER 1185
#define GEO_NODE_MESH_TOPOLOGY_VERTEX_OF_CORNER 1186
#define GEO_NODE_SAMPLE_UV_SURFACE 1187
#define GEO_NODE_SET_CURVE_NORMAL 1188
/** \} */

View File

@ -4820,6 +4820,7 @@ static void registerGeometryNodes()
register_node_type_geo_separate_geometry();
register_node_type_geo_self_object();
register_node_type_geo_set_curve_handles();
register_node_type_geo_set_curve_normal();
register_node_type_geo_set_curve_radius();
register_node_type_geo_set_curve_tilt();
register_node_type_geo_set_id();

View File

@ -230,6 +230,7 @@ DEF_ENUM(rna_enum_transform_orientation_items)
DEF_ENUM(rna_enum_velocity_unit_items)
DEF_ENUM(rna_enum_curves_types)
DEF_ENUM(rna_enum_curve_normal_modes)
/* Not available to RNA pre-processing (`makesrna`).
* Defined in editors for example. */

View File

@ -26,6 +26,12 @@ const EnumPropertyItem rna_enum_curves_types[] = {
{0, NULL, 0, NULL, NULL},
};
const EnumPropertyItem rna_enum_curve_normal_modes[] = {
{NORMAL_MODE_MINIMUM_TWIST, "MINIMUM_TWIST", ICON_NONE, "Minimum Twist", ""},
{NORMAL_MODE_Z_UP, "Z_UP", ICON_NONE, "Z Up", ""},
{0, NULL, 0, NULL, NULL},
};
#ifdef RNA_RUNTIME
# include "BLI_math_vector.h"

View File

@ -13,6 +13,7 @@
#include "BLT_translation.h"
#include "DNA_curves_types.h"
#include "DNA_material_types.h"
#include "DNA_mesh_types.h"
#include "DNA_modifier_types.h"
@ -9698,6 +9699,17 @@ static void def_geo_curve_set_handle_positions(StructRNA *srna)
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update");
}
static void def_geo_set_curve_normal(StructRNA *srna)
{
PropertyRNA *prop;
prop = RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "custom1");
RNA_def_property_enum_items(prop, rna_enum_curve_normal_modes);
RNA_def_property_ui_text(prop, "Mode", "Mode for curve normal evaluation");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
}
static void def_geo_curve_handle_type_selection(StructRNA *srna)
{
PropertyRNA *prop;

View File

@ -139,6 +139,7 @@ void register_node_type_geo_separate_components(void);
void register_node_type_geo_separate_geometry(void);
void register_node_type_geo_self_object(void);
void register_node_type_geo_set_curve_handles(void);
void register_node_type_geo_set_curve_normal(void);
void register_node_type_geo_set_curve_radius(void);
void register_node_type_geo_set_curve_tilt(void);
void register_node_type_geo_set_id(void);

View File

@ -398,6 +398,7 @@ DefNode(GeometryNode, GEO_NODE_SEPARATE_COMPONENTS, 0, "SEPARATE_COMPONENTS",Sep
DefNode(GeometryNode, GEO_NODE_SEPARATE_GEOMETRY, def_geo_separate_geometry,"SEPARATE_GEOMETRY", SeparateGeometry, "Separate Geometry", "Split a geometry into two geometry outputs based on a selection")
DefNode(GeometryNode, GEO_NODE_SELF_OBJECT, 0, "SELF_OBJECT", SelfObject, "Self Object", "Retrieve the object that contains the geometry nodes modifier currently being executed")
DefNode(GeometryNode, GEO_NODE_SET_CURVE_HANDLES, def_geo_curve_set_handle_positions, "SET_CURVE_HANDLES", SetCurveHandlePositions, "Set Handle Positions", "Set the positions for the handles of Bézier curves")
DefNode(GeometryNode, GEO_NODE_SET_CURVE_NORMAL, def_geo_set_curve_normal, "SET_CURVE_NORMAL", SetCurveNormal, "Set Curve Normal", "Set the evaluation mode for curve normals")
DefNode(GeometryNode, GEO_NODE_SET_CURVE_RADIUS, 0, "SET_CURVE_RADIUS", SetCurveRadius, "Set Curve Radius", "Set the radius of the curve at each control point")
DefNode(GeometryNode, GEO_NODE_SET_CURVE_TILT, 0, "SET_CURVE_TILT", SetCurveTilt, "Set Curve Tilt", "Set the tilt angle at each curve control point")
DefNode(GeometryNode, GEO_NODE_SET_ID, 0, "SET_ID", SetID, "Set ID", "Set the id attribute on the input geometry, mainly used internally for randomizing")

View File

@ -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

View File

@ -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);
}