22 .structure_type(StructureType::Field);
29 .structure_type(StructureType::Field)
30 .propagate_references();
44 selection_field_(std::move(selection_field)),
45 position_field_(std::move(position_field)),
46 min_distance_(min_distance)
70 point_evaluator.
add(position_field_);
81 const int2 edge = edges[edge_i];
82 const int2 edge_clusters(vertex_cluster.find_root(edge[0]),
83 vertex_cluster.find_root(edge[1]));
84 if (edge_clusters[0] == edge_clusters[1]) {
88 const float3 vert_a_cluster = vert_cluster_center[edge_clusters[0]];
89 const float3 vert_b_cluster = vert_cluster_center[edge_clusters[1]];
96 const int new_cluster_root = vertex_cluster.join(edge[0], edge[1]);
98 const int new_cluster_size = vert_cluster_size[edge_clusters[0]] +
99 vert_cluster_size[edge_clusters[1]];
102 vert_cluster_size[edge_clusters[1]] /
103 float(new_cluster_size));
105 vert_cluster_center[new_cluster_root] = new_cluster_center;
106 vert_cluster_size[new_cluster_root] = new_cluster_size;
111 for (const int i : range) {
112 cluster_indices[i] = std::as_const(vertex_cluster).find_root(i);
116 return mesh.attributes().adapt_domain<
int>(
124 fn(selection_field_);
130 static constexpr int8_t id = 0;
132 hash.add(deep_hash_cache.
ensure(selection_field_));
133 hash.add(deep_hash_cache.
ensure(position_field_));
134 hash.add(min_distance_);
140 return AttrDomain::Point;
158 ntype.
ui_name =
"Cluster by Connected";
160 "Group mesh vertices connected by edges when they are within a specified distance";
#define NODE_CLASS_CONVERTER
#define NOD_REGISTER_NODE(REGISTER_FUNC)
MutableSpan< T > as_mutable_span()
constexpr IndexRange()=default
static VArray from_container(ContainerT container)
void set_selection(Field< bool > selection)
int add(GField field, GVArray *varray_ptr)
IndexMask get_evaluated_selection_as_mask() const
const GVArray & get_evaluated(const int field_index) const
void foreach_index(Fn &&fn, Mode mode=exec_mode::serial) const
static Field from_input(Args &&...args)
T extract_input(const UString identifier)
void set_output(const UString identifier, T &&value)
StructureType structure_type
float distance(float, float) RET
void copy(const GVArray &src, GMutableSpan dst, exec_mode::Mode mode=exec_mode::parallel)
void node_register_type(bNodeType &ntype)
T distance(const T &a, const T &b)
T interpolate(const T &a, const T &b, const FactorT &t)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
VecBase< int32_t, 2 > int2
@ NODE_DEFAULT_INPUT_POSITION_FIELD
VecBase< float, 3 > float3
void geo_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
static constexpr int _160
std::string ui_description
NodeGeometryExecFunction geometry_node_execute
NodeDeclareFunction declare
UniqueHash ensure(const GFieldRef &field)