25 const bNode *node =
b.node_or_null();
27 if (node !=
nullptr) {
29 b.add_input(data_type,
"Value")
31 .description(
"The values the mininum and maximum will be calculated from");
34 b.add_input<
decl::Int>(
"Group ID",
"Group Index")
37 .description(
"An index used to group values together for multiple separate operations");
39 if (node !=
nullptr) {
41 b.add_output(data_type,
"Min")
42 .field_source_reference_all()
43 .description(
"The lowest value in each group");
44 b.add_output(data_type,
"Max")
45 .field_source_reference_all()
46 .description(
"The highest value in each group");
59 node->
custom2 = int16_t(AttrDomain::Point);
66 switch (socket.
type) {
122 if constexpr (std::is_same_v<T, float3>) {
123 return float3(std::numeric_limits<float>::max());
126 return std::numeric_limits<T>::max();
131 if constexpr (std::is_same_v<T, float3>) {
132 return float3(std::numeric_limits<float>::lowest());
135 return std::numeric_limits<T>::lowest();
153 input_(std::move(
input)),
154 group_index_(std::move(group_index)),
155 source_domain_(source_domain),
156 operation_(operation)
165 if (domain_size == 0) {
171 evaluator.
add(input_);
172 evaluator.
add(group_index_);
180 using T = decltype(dummy);
181 if constexpr (is_same_any_v<T, int, float, float3>) {
182 const VArray<T> values = g_values.typed<T>();
184 if (operation_ == Operation::Min) {
185 if (group_indices.is_single()) {
186 T result = MinMaxInfo<T>::min_initial_value;
187 for (const int i : values.index_range()) {
188 result = math::min(result, values[i]);
190 g_outputs = VArray<T>::ForSingle(result, domain_size);
194 for (const int i : values.index_range()) {
195 T &value = results.lookup_or_add(group_indices[i], MinMaxInfo<T>::min_initial_value);
196 value = math::min(value, values[i]);
198 Array<T> outputs(domain_size);
199 for (const int i : values.index_range()) {
200 outputs[i] = results.lookup(group_indices[i]);
202 g_outputs = VArray<T>::ForContainer(std::move(outputs));
206 if (group_indices.is_single()) {
207 T result = MinMaxInfo<T>::max_initial_value;
208 for (const int i : values.index_range()) {
209 result = math::max(result, values[i]);
211 g_outputs = VArray<T>::ForSingle(result, domain_size);
215 for (const int i : values.index_range()) {
216 T &value = results.lookup_or_add(group_indices[i], MinMaxInfo<T>::max_initial_value);
217 value = math::max(value, values[i]);
219 Array<T> outputs(domain_size);
220 for (const int i : values.index_range()) {
221 outputs[i] = results.lookup(group_indices[i]);
223 g_outputs = VArray<T>::ForContainer(std::move(outputs));
229 return attributes.adapt_domain(std::move(g_outputs), source_domain_, context.domain());
234 input_.node().for_each_field_input_recursive(
fn);
235 group_index_.node().for_each_field_input_recursive(
fn);
246 return input_ == other_field->input_ && group_index_ == other_field->group_index_ &&
247 source_domain_ == other_field->source_domain_ &&
248 operation_ == other_field->operation_;
256 return source_domain_;
268 GField{std::make_shared<FieldMinMaxInput>(
273 GField{std::make_shared<FieldMinMaxInput>(
281 {
CD_PROP_FLOAT,
"FLOAT", 0,
"Float",
"Floating-point value"},
283 {
CD_PROP_FLOAT3,
"FLOAT_VECTOR", 0,
"Vector",
"3D vector with floating-point values"},
284 {0,
nullptr, 0,
nullptr,
nullptr},
290 "Type of data the outputs are calculated from",
301 int(AttrDomain::Point),
311 ntype.
ui_name =
"Field Min & Max";
312 ntype.
ui_description =
"Calculate the minimum and maximum of a given field";
#define NODE_CLASS_CONVERTER
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define NOD_inline_enum_accessors(member)
unsigned long long int uint64_t
const CPPType & type() const
int domain_size(const AttrDomain domain) const
int add(GField field, GVArray *varray_ptr)
const GVArray & get_evaluated(const int field_index) const
const bke::bNodeType & node_type() const
void add_item(std::string socket_name, SocketLinkOperation::LinkSocketFn fn, int weight=0)
const bNodeSocket & other_socket() const
eNodeSocketInOut in_out() const
T extract_input(StringRef identifier)
void set_output(StringRef identifier, T &&value)
bool output_is_required(StringRef identifier) const
const bNode & node() const
bNode & add_node(StringRef idname)
void update_and_connect_available_socket(bNode &new_node, StringRef socket_name)
Vector< SocketDeclaration * > inputs
void convert_to_static_type(const CPPType &cpp_type, const Func &func)
void node_register_type(bNodeType &ntype)
static void node_init(bNodeTree *, bNode *node)
static void node_rna(StructRNA *srna)
static std::optional< eCustomDataType > node_type_from_other_socket(const bNodeSocket &socket)
static void node_register()
static void node_gather_link_searches(GatherLinkSearchOpParams ¶ms)
static void node_declare(NodeDeclarationBuilder &b)
static void node_layout(uiLayout *layout, bContext *, PointerRNA *ptr)
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, const Args &...args)
VecBase< float, 3 > float3
void geo_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
const EnumPropertyItem rna_enum_attribute_domain_items[]
blender::nodes::NodeDeclaration * static_declaration
std::string ui_description
void(*) draw_buttons(uiLayout *, bContext *C, PointerRNA *ptr)
NodeGeometryExecFunction geometry_node_execute
void(*) initfunc(bNodeTree *ntree, bNode *node)
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
NodeDeclareFunction declare
static const T max_initial_value
static const T min_initial_value
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< blender::StringRef > name_opt, int icon, std::optional< blender::StringRef > placeholder=std::nullopt)