Blender V5.3
node_geo_edge_paths_to_curves.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "BKE_curves.hh"
6
7#include "DNA_mesh_types.h"
8
10#include "GEO_mesh_to_curve.hh"
11
12#include "node_geometry_util.hh"
13
15
17{
18 b.add_input<decl::Geometry>("Mesh"_ustr)
19 .supported_type(GeometryComponent::Type::Mesh)
20 .description("Edges to convert to curves");
21 b.add_input<decl::Bool>("Start Vertices"_ustr)
22 .default_value(true)
23 .hide_value()
24 .evaluated_geometry_field();
25 b.add_input<decl::Int>("Next Vertex Index"_ustr)
26 .default_value(-1)
27 .hide_value()
28 .evaluated_geometry_field();
29 b.add_output<decl::Geometry>("Curves"_ustr).propagate_all_geometry();
30}
31
33 const IndexMask &start_verts_mask,
34 const Span<int> next_indices,
35 const AttributeFilter &attribute_filter)
36{
37 Vector<int> vert_indices;
38 Vector<int> curve_offsets;
39 Array<bool> visited(mesh.verts_num, false);
40 start_verts_mask.foreach_index([&](const int first_vert) {
41 const int second_vert = next_indices[first_vert];
42 if (first_vert == second_vert) {
43 return;
44 }
45 if (second_vert < 0 || second_vert >= mesh.verts_num) {
46 return;
47 }
48
49 curve_offsets.append(vert_indices.size());
50
51 /* Iterate through path defined by #next_indices. */
52 int current_vert = first_vert;
53 while (!visited[current_vert]) {
54 visited[current_vert] = true;
55 vert_indices.append(current_vert);
56 const int next_vert = next_indices[current_vert];
57 if (next_vert < 0 || next_vert >= mesh.verts_num) {
58 break;
59 }
60 current_vert = next_vert;
61 }
62
63 /* Reset visited status. */
64 const int points_in_curve_num = vert_indices.size() - curve_offsets.last();
65 for (const int vert_in_curve : vert_indices.as_span().take_back(points_in_curve_num)) {
66 visited[vert_in_curve] = false;
67 }
68 });
69
70 if (vert_indices.is_empty()) {
71 return nullptr;
72 }
74 mesh.attributes(), vert_indices, curve_offsets, IndexRange(0), attribute_filter));
75 return curves_id;
76}
77
79{
80 GeometrySet geometry_set = params.extract_input<GeometrySet>("Mesh"_ustr);
81
82 geometry::foreach_real_geometry(geometry_set, [&](GeometrySet &geometry_set) {
83 const Mesh *mesh = geometry_set.get_mesh();
84 if (mesh == nullptr) {
86 return;
87 }
88
89 const bke::MeshFieldContext context{*mesh, AttrDomain::Point};
90 fn::FieldEvaluator evaluator{context, mesh->verts_num};
91 evaluator.add(params.get_input<Field<int>>("Next Vertex Index"_ustr));
92 evaluator.add(params.get_input<Field<bool>>("Start Vertices"_ustr));
93 evaluator.evaluate();
94 const VArraySpan<int> next_vert = evaluator.get_evaluated<int>(0);
95 IndexMask start_verts = evaluator.get_evaluated_as_mask(1);
96
97 if (start_verts.is_empty()) {
99 return;
100 }
101
103 *mesh, start_verts, next_vert, params.get_attribute_filter("Curves"_ustr)));
105 });
106
107 params.set_output("Curves"_ustr, std::move(geometry_set));
108}
109
110static void node_register()
111{
112 static bke::bNodeType ntype;
113
114 geo_node_type_base(&ntype, "GeometryNodeEdgePathsToCurves"_ustr, GEO_NODE_EDGE_PATHS_TO_CURVES);
115 ntype.ui_name = "Edge Paths to Curves";
116 ntype.ui_description = "Output curves following paths across mesh edges";
117 ntype.enum_name_legacy = "EDGE_PATHS_TO_CURVES";
119 ntype.declare = node_declare;
123}
125
126} // namespace blender::nodes::node_geo_edge_paths_to_curves_cc
Low-level operations for curves.
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:492
#define GEO_NODE_EDGE_PATHS_TO_CURVES
#define NOD_REGISTER_NODE(REGISTER_FUNC)
int64_t size() const
void append(const T &value)
const T & last(const int64_t n=0) const
bool is_empty() const
Span< T > as_span() const
int add(GField field, GVArray *varray_ptr)
IndexMask get_evaluated_as_mask(int field_index)
const GVArray & get_evaluated(const int field_index) const
void foreach_index(Fn &&fn, Mode mode=exec_mode::serial) const
NodeAttributeFilter get_attribute_filter(const UString output_identifier) const
T extract_input(const UString identifier)
T get_input(const UString identifier) const
void set_output(const UString identifier, T &&value)
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
Curves * curves_new_nomain(int points_num, int curves_num)
void foreach_real_geometry(bke::GeometrySet &geometry, FunctionRef< void(bke::GeometrySet &geometry_set)> fn)
bke::CurvesGeometry create_curve_from_vert_indices(const bke::AttributeAccessor &mesh_attributes, Span< int > vert_indices, Span< int > curve_offsets, IndexRange cyclic_curves, const bke::AttributeFilter &attribute_filter)
static Curves * edge_paths_to_curves_convert(const Mesh &mesh, const IndexMask &start_verts_mask, const Span< int > next_indices, const AttributeFilter &attribute_filter)
void geo_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
void keep_only(Span< GeometryComponent::Type > component_types)
void replace_curves(Curves *curves, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
const Mesh * get_mesh() const
static constexpr int _160
Definition BKE_node.hh:246
Defines a node type.
Definition BKE_node.hh:265
std::string ui_description
Definition BKE_node.hh:271
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:385
const char * enum_name_legacy
Definition BKE_node.hh:274
NodeDeclareFunction declare
Definition BKE_node.hh:393