27 const bNode *node =
b.node_or_null();
29 if (node !=
nullptr) {
34 value_declaration = &
b.add_input<
decl::Vector>(
"Value").default_value({1.0f, 1.0f, 1.0f});
37 value_declaration = &
b.add_input<
decl::Float>(
"Value").default_value(1.0f);
40 value_declaration = &
b.add_input<
decl::Int>(
"Value").default_value(1);
52 b.add_input<
decl::Int>(
"Group ID",
"Group Index")
54 .
description(
"An index used to group values together for multiple separate accumulations");
56 if (node !=
nullptr) {
58 b.add_output(data_type,
"Leading")
59 .field_source_reference_all()
61 "The running total of values in the corresponding group, starting at the first value");
62 b.add_output(data_type,
"Trailing")
63 .field_source_reference_all()
64 .description(
"The running total of values in the corresponding group, starting at zero");
65 b.add_output(data_type,
"Total")
66 .field_source_reference_all()
67 .description(
"The total of all of the values in the corresponding group");
81 data->domain =
int16_t(AttrDomain::Point);
89 switch (socket.
type) {
119 bNode &node =
params.add_node(
"GeometryNodeAccumulateField");
120 node_storage(node).data_type = *type;
121 params.update_and_connect_available_socket(node,
"Leading");
127 bNode &node =
params.add_node(
"GeometryNodeAccumulateField");
128 node_storage(node).data_type = *type;
129 params.update_and_connect_available_socket(node,
"Trailing");
135 bNode &node =
params.add_node(
"GeometryNodeAccumulateField");
136 node_storage(node).data_type = *type;
137 params.update_and_connect_available_socket(node,
"Total");
145 bNode &node =
params.add_node(
"GeometryNodeAccumulateField");
146 node_storage(node).data_type = *type;
147 params.update_and_connect_available_socket(node,
"Value");
155 if constexpr (std::is_same_v<T, float4x4>) {
165 if constexpr (std::is_same_v<T, float4x4>) {
178 AttrDomain source_domain_;
186 : bke::GeometryFieldInput(input.
cpp_type(),
"Accumulation"),
188 group_index_(group_index),
189 source_domain_(source_domain),
190 accumulation_mode_(accumulation_mode)
199 if (domain_size == 0) {
205 evaluator.
add(input_);
206 evaluator.add(group_index_);
207 evaluator.evaluate();
208 const GVArray g_values = evaluator.get_evaluated(0);
209 const VArray<int> group_indices = evaluator.get_evaluated<
int>(1);
214 using T = decltype(dummy);
215 if constexpr (is_same_any_v<T, int, float, float3, float4x4>) {
216 Array<T> outputs(domain_size);
217 const VArray<T> values = g_values.typed<T>();
219 if (group_indices.is_single()) {
220 T accumulation = AccumulationInfo<T>::initial_value;
221 if (accumulation_mode_ == AccumulationMode::Leading) {
222 for (const int i : values.index_range()) {
223 accumulation = AccumulationInfo<T>::accumulate(accumulation, values[i]);
224 outputs[i] = accumulation;
228 for (const int i : values.index_range()) {
229 outputs[i] = accumulation;
230 accumulation = AccumulationInfo<T>::accumulate(accumulation, values[i]);
235 Map<int, T> accumulations;
236 if (accumulation_mode_ == AccumulationMode::Leading) {
237 for (const int i : values.index_range()) {
238 T &accumulation_value = accumulations.lookup_or_add(
239 group_indices[i], AccumulationInfo<T>::initial_value);
240 accumulation_value = AccumulationInfo<T>::accumulate(accumulation_value, values[i]);
241 outputs[i] = accumulation_value;
245 for (const int i : values.index_range()) {
246 T &accumulation_value = accumulations.lookup_or_add(
247 group_indices[i], AccumulationInfo<T>::initial_value);
248 outputs[i] = accumulation_value;
249 accumulation_value = AccumulationInfo<T>::accumulate(accumulation_value, values[i]);
254 g_output = VArray<T>::ForContainer(std::move(outputs));
258 return attributes.adapt_domain(std::move(g_output), source_domain_, context.domain());
263 return get_default_hash(input_, group_index_, source_domain_, accumulation_mode_);
271 return input_ == other_accumulate->input_ &&
272 group_index_ == other_accumulate->group_index_ &&
273 source_domain_ == other_accumulate->source_domain_ &&
274 accumulation_mode_ == other_accumulate->accumulation_mode_;
282 return source_domain_;
290 AttrDomain source_domain_;
294 : bke::GeometryFieldInput(input.cpp_type(),
"Total Value"),
296 group_index_(group_index),
297 source_domain_(source_domain)
306 if (domain_size == 0) {
312 evaluator.
add(input_);
313 evaluator.add(group_index_);
314 evaluator.evaluate();
315 const GVArray g_values = evaluator.get_evaluated(0);
316 const VArray<int> group_indices = evaluator.get_evaluated<
int>(1);
320 bke::attribute_math::convert_to_static_type(g_values.
type(), [&](
auto dummy) {
321 using T = decltype(dummy);
322 if constexpr (is_same_any_v<T, int, float, float3, float4x4>) {
323 const VArray<T> values = g_values.typed<T>();
324 if (group_indices.is_single()) {
325 T accumulation = AccumulationInfo<T>::initial_value;
326 for (const int i : values.index_range()) {
327 accumulation = AccumulationInfo<T>::accumulate(accumulation, values[i]);
329 g_outputs = VArray<T>::ForSingle(accumulation, domain_size);
332 Map<int, T> accumulations;
333 for (const int i : values.index_range()) {
334 T &value = accumulations.lookup_or_add(group_indices[i],
335 AccumulationInfo<T>::initial_value);
336 value = AccumulationInfo<T>::accumulate(value, values[i]);
338 Array<T> outputs(domain_size);
339 for (const int i : values.index_range()) {
340 outputs[i] = accumulations.lookup(group_indices[i]);
342 g_outputs = VArray<T>::ForContainer(std::move(outputs));
347 return attributes.adapt_domain(std::move(g_outputs), source_domain_, context.domain());
358 return input_ == other_field->input_ && group_index_ == other_field->group_index_ &&
359 source_domain_ == other_field->source_domain_;
367 return source_domain_;
374 const AttrDomain source_domain = AttrDomain(storage.
domain);
378 if (
params.output_is_required(
"Leading")) {
381 GField{std::make_shared<AccumulateFieldInput>(
382 source_domain, input_field, group_index_field, AccumulationMode::Leading)});
384 if (
params.output_is_required(
"Trailing")) {
387 GField{std::make_shared<AccumulateFieldInput>(
388 source_domain, input_field, group_index_field, AccumulationMode::Trailing)});
390 if (
params.output_is_required(
"Total")) {
393 GField{std::make_shared<TotalFieldInput>(source_domain, input_field, group_index_field)});
400 {
CD_PROP_FLOAT,
"FLOAT", 0,
"Float",
"Add floating point values"},
402 {
CD_PROP_FLOAT3,
"FLOAT_VECTOR", 0,
"Vector",
"Add 3D vector values"},
403 {
CD_PROP_FLOAT4X4,
"TRANSFORM", 0,
"Transform",
"Multiply transformation matrices"},
404 {0,
nullptr, 0,
nullptr,
nullptr},
410 "Type of data that is accumulated",
421 int(AttrDomain::Point),
#define NODE_CLASS_CONVERTER
#define NODE_STORAGE_FUNCS(StorageT)
#define BLI_assert_unreachable()
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define NOD_storage_enum_accessors(member)
void uiItemR(uiLayout *layout, PointerRNA *ptr, const char *propname, eUI_Item_Flag flag, const char *name, int icon)
const CPPType & type() const
int domain_size(const AttrDomain domain) const
int add(GField field, GVArray *varray_ptr)
BaseSocketDeclarationBuilder & description(std::string value="")
BaseSocketDeclarationBuilder & supports_field()
Vector< SocketDeclaration * > inputs
local_group_size(16, 16) .push_constant(Type b
void convert_to_static_type(const CPPType &cpp_type, const Func &func)
void node_type_storage(bNodeType *ntype, const char *storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
void node_register_type(bNodeType *ntype)
static void node_layout(uiLayout *layout, bContext *, PointerRNA *ptr)
static void node_register()
static void node_declare(NodeDeclarationBuilder &b)
static void node_rna(StructRNA *srna)
static std::optional< eCustomDataType > node_type_from_other_socket(const bNodeSocket &socket)
static void node_init(bNodeTree *, bNode *node)
static void node_gather_link_searches(GatherLinkSearchOpParams ¶ms)
static void node_geo_exec(GeoNodeExecParams params)
void search_link_ops_for_declarations(GatherLinkSearchOpParams ¶ms, Span< SocketDeclaration * > declarations)
PropertyRNA * RNA_def_node_enum(StructRNA *srna, const char *identifier, const char *ui_name, const char *ui_description, const EnumPropertyItem *static_items, const EnumRNAAccessors accessors, std::optional< int > default_value, const EnumPropertyItemFunc item_func, const bool allow_animation)
uint64_t get_default_hash(const T &v)
void geo_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
void node_free_standard_storage(bNode *node)
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
const EnumPropertyItem rna_enum_attribute_domain_items[]
unsigned __int64 uint64_t
static MatBase identity()
void(* initfunc)(bNodeTree *ntree, bNode *node)
NodeGeometryExecFunction geometry_node_execute
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
NodeDeclareFunction declare
static const T initial_value
static T accumulate(const T &a, const T &b)