Geometry Nodes: Set Bezier Handle Type Node
This node takes a curve and a point selection and allows you to set the specified (or all) points left/right or both handles to a given type. Differential Revision: https://developer.blender.org/D11992
This commit is contained in:
parent
320f34af86
commit
0e8d1c6bcf
@ -510,6 +510,7 @@ geometry_node_categories = [
|
||||
NodeItem("GeometryNodeCurveTrim"),
|
||||
NodeItem("GeometryNodeCurveLength"),
|
||||
NodeItem("GeometryNodeCurveReverse"),
|
||||
NodeItem("GeometryNodeCurveSetHandles"),
|
||||
]),
|
||||
GeometryNodeCategory("GEO_PRIMITIVES_CURVE", "Curve Primitives", items=[
|
||||
NodeItem("GeometryNodeCurvePrimitiveLine"),
|
||||
|
@ -1465,6 +1465,7 @@ int ntreeTexExecTree(struct bNodeTree *ntree,
|
||||
#define GEO_NODE_CURVE_ENDPOINTS 1069
|
||||
#define GEO_NODE_CURVE_PRIMITIVE_QUADRILATERAL 1070
|
||||
#define GEO_NODE_CURVE_TRIM 1071
|
||||
#define GEO_NODE_CURVE_SET_HANDLES 1072
|
||||
|
||||
/** \} */
|
||||
|
||||
|
@ -5119,6 +5119,7 @@ static void registerGeometryNodes()
|
||||
register_node_type_geo_curve_primitive_star();
|
||||
register_node_type_geo_curve_resample();
|
||||
register_node_type_geo_curve_reverse();
|
||||
register_node_type_geo_curve_set_handles();
|
||||
register_node_type_geo_curve_subdivide();
|
||||
register_node_type_geo_curve_to_mesh();
|
||||
register_node_type_geo_curve_to_points();
|
||||
|
@ -1355,6 +1355,13 @@ typedef struct NodeSwitch {
|
||||
uint8_t input_type;
|
||||
} NodeSwitch;
|
||||
|
||||
typedef struct NodeGeometryCurveSetHandles {
|
||||
/* GeometryNodeCurveHandleType. */
|
||||
uint8_t handle_type;
|
||||
/* GeometryNodeCurveHandleMode. */
|
||||
uint8_t mode;
|
||||
} NodeGeometryCurveSetHandles;
|
||||
|
||||
typedef struct NodeGeometryCurvePrimitiveLine {
|
||||
/* GeometryNodeCurvePrimitiveLineMode. */
|
||||
uint8_t mode;
|
||||
@ -1826,6 +1833,18 @@ typedef enum GeometryNodeCurvePrimitiveCircleMode {
|
||||
GEO_NODE_CURVE_PRIMITIVE_CIRCLE_TYPE_RADIUS = 1
|
||||
} GeometryNodeCurvePrimitiveCircleMode;
|
||||
|
||||
typedef enum GeometryNodeCurveHandleType {
|
||||
GEO_NODE_CURVE_HANDLE_FREE = 0,
|
||||
GEO_NODE_CURVE_HANDLE_AUTO = 1,
|
||||
GEO_NODE_CURVE_HANDLE_VECTOR = 2,
|
||||
GEO_NODE_CURVE_HANDLE_ALIGN = 3
|
||||
} GeometryNodeCurveHandleType;
|
||||
|
||||
typedef enum GeometryNodeCurveHandleMode {
|
||||
GEO_NODE_CURVE_HANDLE_LEFT = (1 << 0),
|
||||
GEO_NODE_CURVE_HANDLE_RIGHT = (1 << 1)
|
||||
} GeometryNodeCurveHandleMode;
|
||||
|
||||
typedef enum GeometryNodeTriangulateNGons {
|
||||
GEO_NODE_TRIANGULATE_NGON_BEAUTY = 0,
|
||||
GEO_NODE_TRIANGULATE_NGON_EARCLIP = 1,
|
||||
|
@ -9441,6 +9441,52 @@ static void def_geo_attribute_vector_rotate(StructRNA *srna)
|
||||
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update");
|
||||
}
|
||||
|
||||
static void def_geo_curve_set_handles(StructRNA *srna)
|
||||
{
|
||||
static const EnumPropertyItem type_items[] = {
|
||||
{GEO_NODE_CURVE_HANDLE_FREE,
|
||||
"FREE",
|
||||
ICON_HANDLE_FREE,
|
||||
"Free",
|
||||
"The handle can be moved anywhere, and doesn't influence the point's other handle"},
|
||||
{GEO_NODE_CURVE_HANDLE_AUTO,
|
||||
"AUTO",
|
||||
ICON_HANDLE_AUTO,
|
||||
"Auto",
|
||||
"The location is automatically calculated to be smooth"},
|
||||
{GEO_NODE_CURVE_HANDLE_VECTOR,
|
||||
"VECTOR",
|
||||
ICON_HANDLE_VECTOR,
|
||||
"Vector",
|
||||
"The location is calculated to point to the next/previous control point"},
|
||||
{GEO_NODE_CURVE_HANDLE_ALIGN,
|
||||
"ALIGN",
|
||||
ICON_HANDLE_ALIGNED,
|
||||
"Align",
|
||||
"The location is constrained to point in the opposite direction as the other handle"},
|
||||
{0, NULL, 0, NULL, NULL}};
|
||||
|
||||
static const EnumPropertyItem mode_items[] = {
|
||||
{GEO_NODE_CURVE_HANDLE_LEFT, "LEFT", ICON_NONE, "Left", "Update the left handles"},
|
||||
{GEO_NODE_CURVE_HANDLE_RIGHT, "RIGHT", ICON_NONE, "Right", "Update the right handles"},
|
||||
{0, NULL, 0, NULL, NULL}};
|
||||
|
||||
PropertyRNA *prop;
|
||||
|
||||
RNA_def_struct_sdna_from(srna, "NodeGeometryCurveSetHandles", "storage");
|
||||
|
||||
prop = RNA_def_property(srna, "handle_type", PROP_ENUM, PROP_NONE);
|
||||
RNA_def_property_enum_sdna(prop, NULL, "handle_type");
|
||||
RNA_def_property_enum_items(prop, type_items);
|
||||
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update");
|
||||
|
||||
prop = RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE);
|
||||
RNA_def_property_enum_items(prop, mode_items);
|
||||
RNA_def_property_ui_text(prop, "Mode", "Whether to update left and right handles");
|
||||
RNA_def_property_flag(prop, PROP_ENUM_FLAG);
|
||||
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update");
|
||||
}
|
||||
|
||||
static void def_geo_curve_primitive_circle(StructRNA *srna)
|
||||
{
|
||||
static const EnumPropertyItem mode_items[] = {
|
||||
|
@ -175,6 +175,7 @@ set(SRC
|
||||
geometry/nodes/node_geo_curve_primitive_star.cc
|
||||
geometry/nodes/node_geo_curve_resample.cc
|
||||
geometry/nodes/node_geo_curve_reverse.cc
|
||||
geometry/nodes/node_geo_curve_set_handles.cc
|
||||
geometry/nodes/node_geo_curve_subdivide.cc
|
||||
geometry/nodes/node_geo_curve_to_mesh.cc
|
||||
geometry/nodes/node_geo_curve_to_points.cc
|
||||
|
@ -62,6 +62,7 @@ void register_node_type_geo_curve_primitive_spiral(void);
|
||||
void register_node_type_geo_curve_primitive_star(void);
|
||||
void register_node_type_geo_curve_resample(void);
|
||||
void register_node_type_geo_curve_reverse(void);
|
||||
void register_node_type_geo_curve_set_handles(void);
|
||||
void register_node_type_geo_curve_subdivide(void);
|
||||
void register_node_type_geo_curve_to_mesh(void);
|
||||
void register_node_type_geo_curve_to_points(void);
|
||||
|
@ -300,6 +300,7 @@ DefNode(GeometryNode, GEO_NODE_CURVE_PRIMITIVE_QUADRATIC_BEZIER, 0, "CURVE_PRIMI
|
||||
DefNode(GeometryNode, GEO_NODE_CURVE_PRIMITIVE_STAR, 0, "CURVE_PRIMITIVE_STAR", CurveStar, "Star", "")
|
||||
DefNode(GeometryNode, GEO_NODE_CURVE_PRIMITIVE_SPIRAL, 0, "CURVE_PRIMITIVE_SPIRAL", CurveSpiral, "Curve Spiral", "")
|
||||
DefNode(GeometryNode, GEO_NODE_CURVE_RESAMPLE, def_geo_curve_resample, "CURVE_RESAMPLE", CurveResample, "Resample Curve", "")
|
||||
DefNode(GeometryNode, GEO_NODE_CURVE_SET_HANDLES, def_geo_curve_set_handles, "CURVE_SET_HANDLES", CurveSetHandles, "Set Handle Type", "")
|
||||
DefNode(GeometryNode, GEO_NODE_CURVE_SUBDIVIDE, def_geo_curve_subdivide, "CURVE_SUBDIVIDE", CurveSubdivide, "Curve Subdivide", "")
|
||||
DefNode(GeometryNode, GEO_NODE_CURVE_TO_MESH, 0, "CURVE_TO_MESH", CurveToMesh, "Curve to Mesh", "")
|
||||
DefNode(GeometryNode, GEO_NODE_CURVE_TRIM, def_geo_curve_trim, "CURVE_TRIM", CurveTrim, "Curve Trim", "")
|
||||
|
@ -0,0 +1,143 @@
|
||||
/*
|
||||
* 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 "BKE_spline.hh"
|
||||
|
||||
#include "UI_interface.h"
|
||||
#include "UI_resources.h"
|
||||
|
||||
#include "node_geometry_util.hh"
|
||||
|
||||
static bNodeSocketTemplate geo_node_curve_set_handles_in[] = {
|
||||
{SOCK_GEOMETRY, N_("Curve")},
|
||||
{SOCK_STRING, N_("Selection")},
|
||||
{-1, ""},
|
||||
};
|
||||
|
||||
static bNodeSocketTemplate geo_node_curve_set_handles_out[] = {
|
||||
{SOCK_GEOMETRY, N_("Curve")},
|
||||
{-1, ""},
|
||||
};
|
||||
|
||||
static void geo_node_curve_set_handles_layout(uiLayout *layout,
|
||||
bContext *UNUSED(C),
|
||||
PointerRNA *ptr)
|
||||
{
|
||||
uiItemR(layout, ptr, "mode", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
|
||||
uiItemR(layout, ptr, "handle_type", 0, "", ICON_NONE);
|
||||
}
|
||||
|
||||
namespace blender::nodes {
|
||||
|
||||
static void geo_node_curve_set_handles_init(bNodeTree *UNUSED(tree), bNode *node)
|
||||
{
|
||||
NodeGeometryCurveSetHandles *data = (NodeGeometryCurveSetHandles *)MEM_callocN(
|
||||
sizeof(NodeGeometryCurveSetHandles), __func__);
|
||||
|
||||
data->handle_type = GEO_NODE_CURVE_HANDLE_AUTO;
|
||||
data->mode = GEO_NODE_CURVE_HANDLE_LEFT | GEO_NODE_CURVE_HANDLE_RIGHT;
|
||||
node->storage = data;
|
||||
}
|
||||
|
||||
static BezierSpline::HandleType handle_type_from_input_type(GeometryNodeCurveHandleType type)
|
||||
{
|
||||
switch (type) {
|
||||
case GEO_NODE_CURVE_HANDLE_AUTO:
|
||||
return BezierSpline::HandleType::Auto;
|
||||
case GEO_NODE_CURVE_HANDLE_ALIGN:
|
||||
return BezierSpline::HandleType::Align;
|
||||
case GEO_NODE_CURVE_HANDLE_FREE:
|
||||
return BezierSpline::HandleType::Free;
|
||||
case GEO_NODE_CURVE_HANDLE_VECTOR:
|
||||
return BezierSpline::HandleType::Vector;
|
||||
}
|
||||
BLI_assert_unreachable();
|
||||
return BezierSpline::HandleType::Auto;
|
||||
}
|
||||
|
||||
static void geo_node_curve_set_handles_exec(GeoNodeExecParams params)
|
||||
{
|
||||
const NodeGeometryCurveSetHandles *node_storage =
|
||||
(NodeGeometryCurveSetHandles *)params.node().storage;
|
||||
const GeometryNodeCurveHandleType type = (GeometryNodeCurveHandleType)node_storage->handle_type;
|
||||
const GeometryNodeCurveHandleMode mode = (GeometryNodeCurveHandleMode)node_storage->mode;
|
||||
|
||||
GeometrySet geometry_set = params.extract_input<GeometrySet>("Curve");
|
||||
geometry_set = bke::geometry_set_realize_instances(geometry_set);
|
||||
if (!geometry_set.has_curve()) {
|
||||
params.set_output("Curve", geometry_set);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Retrieve data for write access so we can avoid new allocations for the handles data. */
|
||||
CurveComponent &curve_component = geometry_set.get_component_for_write<CurveComponent>();
|
||||
CurveEval &curve = *curve_component.get_for_write();
|
||||
MutableSpan<SplinePtr> splines = curve.splines();
|
||||
|
||||
const std::string selection_name = params.extract_input<std::string>("Selection");
|
||||
GVArray_Typed<bool> selection = curve_component.attribute_get_for_read(
|
||||
selection_name, ATTR_DOMAIN_POINT, true);
|
||||
|
||||
const BezierSpline::HandleType new_handle_type = handle_type_from_input_type(type);
|
||||
int point_index = 0;
|
||||
bool has_bezier_spline = false;
|
||||
for (SplinePtr &spline : splines) {
|
||||
if (spline->type() != Spline::Type::Bezier) {
|
||||
point_index += spline->positions().size();
|
||||
continue;
|
||||
}
|
||||
|
||||
BezierSpline &bezier_spline = static_cast<BezierSpline &>(*spline);
|
||||
has_bezier_spline = true;
|
||||
for (int i_point : IndexRange(bezier_spline.size())) {
|
||||
if (selection[point_index]) {
|
||||
if (mode & GEO_NODE_CURVE_HANDLE_LEFT) {
|
||||
bezier_spline.handle_types_left()[i_point] = new_handle_type;
|
||||
}
|
||||
if (mode & GEO_NODE_CURVE_HANDLE_RIGHT) {
|
||||
bezier_spline.handle_types_right()[i_point] = new_handle_type;
|
||||
}
|
||||
}
|
||||
point_index++;
|
||||
}
|
||||
bezier_spline.mark_cache_invalid();
|
||||
}
|
||||
|
||||
if (!has_bezier_spline) {
|
||||
params.error_message_add(NodeWarningType::Info, TIP_("No Bezier splines in input curve"));
|
||||
}
|
||||
|
||||
params.set_output("Curve", geometry_set);
|
||||
}
|
||||
} // namespace blender::nodes
|
||||
|
||||
void register_node_type_geo_curve_set_handles()
|
||||
{
|
||||
static bNodeType ntype;
|
||||
geo_node_type_base(
|
||||
&ntype, GEO_NODE_CURVE_SET_HANDLES, "Set Handle Type", NODE_CLASS_GEOMETRY, 0);
|
||||
node_type_socket_templates(
|
||||
&ntype, geo_node_curve_set_handles_in, geo_node_curve_set_handles_out);
|
||||
ntype.geometry_node_execute = blender::nodes::geo_node_curve_set_handles_exec;
|
||||
node_type_init(&ntype, blender::nodes::geo_node_curve_set_handles_init);
|
||||
node_type_storage(&ntype,
|
||||
"NodeGeometryCurveSetHandles",
|
||||
node_free_standard_storage,
|
||||
node_copy_standard_storage);
|
||||
ntype.draw_buttons = geo_node_curve_set_handles_layout;
|
||||
|
||||
nodeRegisterType(&ntype);
|
||||
}
|
Loading…
Reference in New Issue
Block a user