Blender V4.3
node_fn_float_to_int.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 <cmath>
6
7#include "BLI_noise.hh"
8#include "BLI_string.h"
9#include "BLI_string_utf8.h"
10
11#include "RNA_enum_types.hh"
12
13#include "UI_interface.hh"
14#include "UI_resources.hh"
15
16#include "node_function_util.hh"
17
19
21{
22 b.is_function_node();
23 b.add_input<decl::Float>("Float");
24 b.add_output<decl::Int>("Integer");
25}
26
27static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
28{
29 uiItemR(layout, ptr, "rounding_mode", UI_ITEM_NONE, "", ICON_NONE);
30}
31
32static void node_label(const bNodeTree * /*tree*/,
33 const bNode *node,
34 char *label,
35 int label_maxncpy)
36{
37 const char *name;
38 bool enum_label = RNA_enum_name(rna_enum_node_float_to_int_items, node->custom1, &name);
39 if (!enum_label) {
40 name = CTX_N_(BLT_I18NCONTEXT_ID_NODETREE, "Unknown");
41 }
43}
44
45static const mf::MultiFunction *get_multi_function(const bNode &bnode)
46{
47 static auto exec_preset = mf::build::exec_presets::AllSpanOrSingle();
48 static auto round_fn = mf::build::SI1_SO<float, int>(
49 "Round", [](float a) { return int(round(a)); }, exec_preset);
50 static auto floor_fn = mf::build::SI1_SO<float, int>(
51 "Floor", [](float a) { return int(floor(a)); }, exec_preset);
52 static auto ceil_fn = mf::build::SI1_SO<float, int>(
53 "Ceiling", [](float a) { return int(ceil(a)); }, exec_preset);
54 static auto trunc_fn = mf::build::SI1_SO<float, int>(
55 "Truncate", [](float a) { return int(trunc(a)); }, exec_preset);
56
57 switch (static_cast<FloatToIntRoundingMode>(bnode.custom1)) {
59 return &round_fn;
61 return &floor_fn;
63 return &ceil_fn;
65 return &trunc_fn;
66 }
67
69 return nullptr;
70}
71
73{
74 const mf::MultiFunction *fn = get_multi_function(builder.node());
75 builder.set_matching_fn(fn);
76}
77
78static void node_register()
79{
80 static blender::bke::bNodeType ntype;
81
82 fn_node_type_base(&ntype, FN_NODE_FLOAT_TO_INT, "Float to Integer", NODE_CLASS_CONVERTER);
83 ntype.declare = node_declare;
84 ntype.labelfunc = node_label;
88}
90
91} // namespace blender::nodes::node_fn_float_to_int_cc
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:410
#define BLI_assert_unreachable()
Definition BLI_assert.h:97
char * BLI_strncpy_utf8(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
#define CTX_N_(context, msgid)
#define BLT_I18NCONTEXT_ID_NODETREE
#define CTX_IFACE_(context, msgid)
FloatToIntRoundingMode
@ FN_NODE_FLOAT_TO_INT_TRUNCATE
@ FN_NODE_FLOAT_TO_INT_CEIL
@ FN_NODE_FLOAT_TO_INT_ROUND
@ FN_NODE_FLOAT_TO_INT_FLOOR
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define UI_ITEM_NONE
void uiItemR(uiLayout *layout, PointerRNA *ptr, const char *propname, eUI_Item_Flag flag, const char *name, int icon)
void set_matching_fn(const mf::MultiFunction *fn)
local_group_size(16, 16) .push_constant(Type b
const char * label
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
ccl_device_inline float2 floor(const float2 a)
ccl_device_inline float3 ceil(const float3 a)
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
static void node_label(const bNodeTree *, const bNode *node, char *label, int label_maxncpy)
static void node_declare(NodeDeclarationBuilder &b)
static void node_layout(uiLayout *layout, bContext *, PointerRNA *ptr)
static const mf::MultiFunction * get_multi_function(const bNode &bnode)
static void node_build_multi_function(NodeMultiFunctionBuilder &builder)
void fn_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
bool RNA_enum_name(const EnumPropertyItem *item, const int value, const char **r_name)
const EnumPropertyItem rna_enum_node_float_to_int_items[]
int16_t custom1
Defines a node type.
Definition BKE_node.hh:218
void(* labelfunc)(const bNodeTree *ntree, const bNode *node, char *label, int label_maxncpy)
Definition BKE_node.hh:249
NodeMultiFunctionBuildFunction build_multi_function
Definition BKE_node.hh:336
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:238
NodeDeclareFunction declare
Definition BKE_node.hh:347
PointerRNA * ptr
Definition wm_files.cc:4126