Geometry Nodes: Select by Handle Type Node
Just like the "Select by Material" node, this node outputs a boolean attribute for control points that have a matching handle type. By default left and right handles are considered, but it's possible to only check one side with the toggle in the node. Differential Revision: https://developer.blender.org/D12135
This commit is contained in:
parent
bc0d55e724
commit
1f8485ae82
|
@ -512,6 +512,7 @@ geometry_node_categories = [
|
|||
NodeItem("GeometryNodeCurveReverse"),
|
||||
NodeItem("GeometryNodeCurveSplineType"),
|
||||
NodeItem("GeometryNodeCurveSetHandles"),
|
||||
NodeItem("GeometryNodeCurveSelectHandles"),
|
||||
]),
|
||||
GeometryNodeCategory("GEO_PRIMITIVES_CURVE", "Curve Primitives", items=[
|
||||
NodeItem("GeometryNodeCurvePrimitiveLine"),
|
||||
|
|
|
@ -1476,6 +1476,7 @@ int ntreeTexExecTree(struct bNodeTree *ntree,
|
|||
#define GEO_NODE_CURVE_TRIM 1071
|
||||
#define GEO_NODE_CURVE_SET_HANDLES 1072
|
||||
#define GEO_NODE_CURVE_SPLINE_TYPE 1073
|
||||
#define GEO_NODE_CURVE_SELECT_HANDLES 1074
|
||||
|
||||
/** \} */
|
||||
|
||||
|
|
|
@ -5181,6 +5181,7 @@ static void registerGeometryNodes()
|
|||
register_node_type_geo_points_to_volume();
|
||||
register_node_type_geo_raycast();
|
||||
register_node_type_geo_sample_texture();
|
||||
register_node_type_geo_select_by_handle_type();
|
||||
register_node_type_geo_select_by_material();
|
||||
register_node_type_geo_separate_components();
|
||||
register_node_type_geo_subdivision_surface();
|
||||
|
|
|
@ -1367,6 +1367,13 @@ typedef struct NodeGeometryCurveSetHandles {
|
|||
uint8_t mode;
|
||||
} NodeGeometryCurveSetHandles;
|
||||
|
||||
typedef struct NodeGeometryCurveSelectHandles {
|
||||
/* GeometryNodeCurveHandleType. */
|
||||
uint8_t handle_type;
|
||||
/* GeometryNodeCurveHandleMode. */
|
||||
uint8_t mode;
|
||||
} NodeGeometryCurveSelectHandles;
|
||||
|
||||
typedef struct NodeGeometryCurvePrimitiveLine {
|
||||
/* GeometryNodeCurvePrimitiveLineMode. */
|
||||
uint8_t mode;
|
||||
|
|
|
@ -439,6 +439,34 @@ static const EnumPropertyItem rna_node_geometry_attribute_randomize_operation_it
|
|||
{0, NULL, 0, NULL, NULL},
|
||||
};
|
||||
|
||||
static const EnumPropertyItem rna_node_geometry_curve_handle_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 rna_node_geometry_curve_handle_side_items[] = {
|
||||
{GEO_NODE_CURVE_HANDLE_LEFT, "LEFT", ICON_NONE, "Left", "Use the left handles"},
|
||||
{GEO_NODE_CURVE_HANDLE_RIGHT, "RIGHT", ICON_NONE, "Right", "Use the right handles"},
|
||||
{0, NULL, 0, NULL, NULL}};
|
||||
|
||||
#ifndef RNA_RUNTIME
|
||||
static const EnumPropertyItem node_sampler_type_items[] = {
|
||||
{0, "NEAREST", 0, "Nearest", ""},
|
||||
|
@ -9460,50 +9488,40 @@ static void def_geo_curve_spline_type(StructRNA *srna)
|
|||
|
||||
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_enum_items(prop, rna_node_geometry_curve_handle_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_enum_items(prop, rna_node_geometry_curve_handle_side_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_select_handles(StructRNA *srna)
|
||||
{
|
||||
PropertyRNA *prop;
|
||||
|
||||
RNA_def_struct_sdna_from(srna, "NodeGeometryCurveSelectHandles", "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, rna_node_geometry_curve_handle_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, rna_node_geometry_curve_handle_side_items);
|
||||
RNA_def_property_ui_text(prop, "Mode", "Whether to check the type of 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_select_by_handle_type.cc
|
||||
geometry/nodes/node_geo_curve_set_handles.cc
|
||||
geometry/nodes/node_geo_curve_spline_type.cc
|
||||
geometry/nodes/node_geo_curve_subdivide.cc
|
||||
|
|
|
@ -95,6 +95,7 @@ void register_node_type_geo_point_translate(void);
|
|||
void register_node_type_geo_points_to_volume(void);
|
||||
void register_node_type_geo_raycast(void);
|
||||
void register_node_type_geo_sample_texture(void);
|
||||
void register_node_type_geo_select_by_handle_type(void);
|
||||
void register_node_type_geo_select_by_material(void);
|
||||
void register_node_type_geo_separate_components(void);
|
||||
void register_node_type_geo_subdivision_surface(void);
|
||||
|
|
|
@ -303,6 +303,7 @@ DefNode(GeometryNode, GEO_NODE_CURVE_PRIMITIVE_STAR, 0, "CURVE_PRIMITIVE_STAR",
|
|||
DefNode(GeometryNode, GEO_NODE_CURVE_RESAMPLE, def_geo_curve_resample, "CURVE_RESAMPLE", CurveResample, "Resample Curve", "")
|
||||
DefNode(GeometryNode, GEO_NODE_CURVE_REVERSE, 0, "CURVE_REVERSE", CurveReverse, "Curve Reverse", "")
|
||||
DefNode(GeometryNode, GEO_NODE_CURVE_SET_HANDLES, def_geo_curve_set_handles, "CURVE_SET_HANDLES", CurveSetHandles, "Set Handle Type", "")
|
||||
DefNode(GeometryNode, GEO_NODE_CURVE_SELECT_HANDLES, def_geo_curve_select_handles, "CURVE_SELECT_HANDLES", CurveSelectHandles, "Select by Handle Type", "")
|
||||
DefNode(GeometryNode, GEO_NODE_CURVE_SPLINE_TYPE, def_geo_curve_spline_type, "CURVE_SPLINE_TYPE", CurveSplineType, "Set Spline 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", "")
|
||||
|
|
|
@ -0,0 +1,147 @@
|
|||
/*
|
||||
* 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 "BLI_task.hh"
|
||||
|
||||
#include "BKE_spline.hh"
|
||||
|
||||
#include "UI_interface.h"
|
||||
#include "UI_resources.h"
|
||||
|
||||
#include "node_geometry_util.hh"
|
||||
|
||||
static bNodeSocketTemplate geo_node_select_by_handle_type_in[] = {
|
||||
{SOCK_GEOMETRY, N_("Geometry")},
|
||||
{SOCK_STRING, N_("Selection")},
|
||||
{-1, ""},
|
||||
};
|
||||
|
||||
static bNodeSocketTemplate geo_node_select_by_handle_type_out[] = {
|
||||
{SOCK_GEOMETRY, N_("Geometry")},
|
||||
{-1, ""},
|
||||
};
|
||||
|
||||
static void geo_node_curve_select_by_handle_type_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);
|
||||
}
|
||||
|
||||
static void geo_node_curve_select_by_handle_type_init(bNodeTree *UNUSED(tree), bNode *node)
|
||||
{
|
||||
NodeGeometryCurveSelectHandles *data = (NodeGeometryCurveSelectHandles *)MEM_callocN(
|
||||
sizeof(NodeGeometryCurveSelectHandles), __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(const 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;
|
||||
}
|
||||
|
||||
namespace blender::nodes {
|
||||
|
||||
static void select_curve_by_handle_type(const CurveEval &curve,
|
||||
const BezierSpline::HandleType type,
|
||||
const GeometryNodeCurveHandleMode mode,
|
||||
const MutableSpan<bool> r_selection)
|
||||
{
|
||||
const Array<int> offsets = curve.control_point_offsets();
|
||||
Span<SplinePtr> splines = curve.splines();
|
||||
threading::parallel_for(splines.index_range(), 128, [&](IndexRange range) {
|
||||
for (const int i_spline : range) {
|
||||
const Spline &spline = *splines[i_spline];
|
||||
if (spline.type() == Spline::Type::Bezier) {
|
||||
const BezierSpline &bezier_spline = static_cast<const BezierSpline &>(spline);
|
||||
Span<BezierSpline::HandleType> types_left = bezier_spline.handle_types_left();
|
||||
Span<BezierSpline::HandleType> types_right = bezier_spline.handle_types_right();
|
||||
for (const int i_point : IndexRange(bezier_spline.size())) {
|
||||
r_selection[offsets[i_spline] + i_point] = (mode & GEO_NODE_CURVE_HANDLE_LEFT &&
|
||||
types_left[i_point] == type) ||
|
||||
(mode & GEO_NODE_CURVE_HANDLE_RIGHT &&
|
||||
types_right[i_point] == type);
|
||||
}
|
||||
}
|
||||
else {
|
||||
r_selection.slice(offsets[i_spline], offsets[i_spline + 1]).fill(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static void geo_node_select_by_handle_type_exec(GeoNodeExecParams params)
|
||||
{
|
||||
const NodeGeometryCurveSelectHandles *storage =
|
||||
(const NodeGeometryCurveSelectHandles *)params.node().storage;
|
||||
const BezierSpline::HandleType handle_type = handle_type_from_input_type(
|
||||
(GeometryNodeCurveHandleType)storage->handle_type);
|
||||
const GeometryNodeCurveHandleMode mode = (GeometryNodeCurveHandleMode)storage->mode;
|
||||
|
||||
GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry");
|
||||
geometry_set = bke::geometry_set_realize_instances(geometry_set);
|
||||
|
||||
CurveComponent &curve_component = geometry_set.get_component_for_write<CurveComponent>();
|
||||
const CurveEval *curve = curve_component.get_for_read();
|
||||
|
||||
if (curve != nullptr) {
|
||||
const std::string selection_name = params.extract_input<std::string>("Selection");
|
||||
OutputAttribute_Typed<bool> selection =
|
||||
curve_component.attribute_try_get_for_output_only<bool>(selection_name, ATTR_DOMAIN_POINT);
|
||||
if (selection) {
|
||||
select_curve_by_handle_type(*curve, handle_type, mode, selection.as_span());
|
||||
selection.save();
|
||||
}
|
||||
}
|
||||
|
||||
params.set_output("Geometry", std::move(geometry_set));
|
||||
}
|
||||
|
||||
} // namespace blender::nodes
|
||||
|
||||
void register_node_type_geo_select_by_handle_type()
|
||||
{
|
||||
static bNodeType ntype;
|
||||
|
||||
geo_node_type_base(
|
||||
&ntype, GEO_NODE_CURVE_SELECT_HANDLES, "Select by Handle Type", NODE_CLASS_GEOMETRY, 0);
|
||||
node_type_socket_templates(
|
||||
&ntype, geo_node_select_by_handle_type_in, geo_node_select_by_handle_type_out);
|
||||
ntype.geometry_node_execute = blender::nodes::geo_node_select_by_handle_type_exec;
|
||||
node_type_init(&ntype, geo_node_curve_select_by_handle_type_init);
|
||||
node_type_storage(&ntype,
|
||||
"NodeGeometryCurveSelectHandles",
|
||||
node_free_standard_storage,
|
||||
node_copy_standard_storage);
|
||||
ntype.draw_buttons = geo_node_curve_select_by_handle_type_layout;
|
||||
|
||||
nodeRegisterType(&ntype);
|
||||
}
|
Loading…
Reference in New Issue