Blender V4.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
11#include "node_geometry_util.hh"
12
14
16{
17 b.add_input<decl::Geometry>("Mesh").supported_type(GeometryComponent::Type::Mesh);
18 b.add_input<decl::Bool>("Start Vertices").default_value(true).hide_value().field_on_all();
19 b.add_input<decl::Int>("Next Vertex Index").default_value(-1).hide_value().field_on_all();
20 b.add_output<decl::Geometry>("Curves").propagate_all();
21}
22
24 const IndexMask &start_verts_mask,
25 const Span<int> next_indices,
26 const AttributeFilter &attribute_filter)
27{
28 Vector<int> vert_indices;
29 Vector<int> curve_offsets;
30 Array<bool> visited(mesh.verts_num, false);
31 start_verts_mask.foreach_index([&](const int first_vert) {
32 const int second_vert = next_indices[first_vert];
33 if (first_vert == second_vert) {
34 return;
35 }
36 if (second_vert < 0 || second_vert >= mesh.verts_num) {
37 return;
38 }
39
40 curve_offsets.append(vert_indices.size());
41
42 /* Iterate through path defined by #next_indices. */
43 int current_vert = first_vert;
44 while (!visited[current_vert]) {
45 visited[current_vert] = true;
46 vert_indices.append(current_vert);
47 const int next_vert = next_indices[current_vert];
48 if (next_vert < 0 || next_vert >= mesh.verts_num) {
49 break;
50 }
51 current_vert = next_vert;
52 }
53
54 /* Reset visited status. */
55 const int points_in_curve_num = vert_indices.size() - curve_offsets.last();
56 for (const int vert_in_curve : vert_indices.as_span().take_back(points_in_curve_num)) {
57 visited[vert_in_curve] = false;
58 }
59 });
60
61 if (vert_indices.is_empty()) {
62 return nullptr;
63 }
65 mesh.attributes(), vert_indices, curve_offsets, IndexRange(0), attribute_filter));
66 return curves_id;
67}
68
70{
71 GeometrySet geometry_set = params.extract_input<GeometrySet>("Mesh");
72
73 geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
74 const Mesh *mesh = geometry_set.get_mesh();
75 if (mesh == nullptr) {
77 return;
78 }
79
80 const bke::MeshFieldContext context{*mesh, AttrDomain::Point};
81 fn::FieldEvaluator evaluator{context, mesh->verts_num};
82 evaluator.add(params.get_input<Field<int>>("Next Vertex Index"));
83 evaluator.add(params.get_input<Field<bool>>("Start Vertices"));
84 evaluator.evaluate();
85 const VArraySpan<int> next_vert = evaluator.get_evaluated<int>(0);
86 IndexMask start_verts = evaluator.get_evaluated_as_mask(1);
87
88 if (start_verts.is_empty()) {
90 return;
91 }
92
94 *mesh, start_verts, next_vert, params.get_attribute_filter("Curves")));
96 });
97
98 params.set_output("Curves", std::move(geometry_set));
99}
100
101static void node_register()
102{
103 static blender::bke::bNodeType ntype;
104
106 &ntype, GEO_NODE_EDGE_PATHS_TO_CURVES, "Edge Paths to Curves", NODE_CLASS_GEOMETRY);
107 ntype.declare = node_declare;
110}
112
113} // namespace blender::nodes::node_geo_edge_paths_to_curves_cc
Low-level operations for curves.
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:418
#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)
Definition field.cc:756
void foreach_index(Fn &&fn) const
local_group_size(16, 16) .push_constant(Type b
Set< ComponentNode * > visited
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
Curves * curves_new_nomain(int points_num, int curves_num)
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(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
void keep_only(Span< GeometryComponent::Type > component_types)
void replace_curves(Curves *curves, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
const Mesh * get_mesh() const
void modify_geometry_sets(ForeachSubGeometryCallback callback)
Defines a node type.
Definition BKE_node.hh:218
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:339
NodeDeclareFunction declare
Definition BKE_node.hh:347