Blender  V3.3
node_fn_float_to_int.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #include <cmath>
4 
5 #include "BLI_noise.hh"
6 #include "BLI_string.h"
7 
8 #include "RNA_enum_types.h"
9 
10 #include "UI_interface.h"
11 #include "UI_resources.h"
12 
13 #include "node_function_util.hh"
14 
16 
18 {
19  b.is_function_node();
20  b.add_input<decl::Float>(N_("Float"));
21  b.add_output<decl::Int>(N_("Integer"));
22 }
23 
25 {
26  uiItemR(layout, ptr, "rounding_mode", 0, "", ICON_NONE);
27 }
28 
30  const bNode *node,
31  char *label,
32  int maxlen)
33 {
34  const char *name;
35  bool enum_label = RNA_enum_name(rna_enum_node_float_to_int_items, node->custom1, &name);
36  if (!enum_label) {
37  name = "Unknown";
38  }
39  BLI_strncpy(label, IFACE_(name), maxlen);
40 }
41 
43 {
44  static auto exec_preset = fn::CustomMF_presets::AllSpanOrSingle();
45  static fn::CustomMF_SI_SO<float, int> round_fn{
46  "Round", [](float a) { return (int)round(a); }, exec_preset};
47  static fn::CustomMF_SI_SO<float, int> floor_fn{
48  "Floor", [](float a) { return (int)floor(a); }, exec_preset};
49  static fn::CustomMF_SI_SO<float, int> ceil_fn{
50  "Ceiling", [](float a) { return (int)ceil(a); }, exec_preset};
51  static fn::CustomMF_SI_SO<float, int> trunc_fn{
52  "Truncate", [](float a) { return (int)trunc(a); }, exec_preset};
53 
54  switch (static_cast<FloatToIntRoundingMode>(bnode.custom1)) {
56  return &round_fn;
58  return &floor_fn;
60  return &ceil_fn;
62  return &trunc_fn;
63  }
64 
66  return nullptr;
67 }
68 
70 {
71  const fn::MultiFunction *fn = get_multi_function(builder.node());
72  builder.set_matching_fn(fn);
73 }
74 
75 } // namespace blender::nodes::node_fn_float_to_int_cc
76 
78 {
79  namespace file_ns = blender::nodes::node_fn_float_to_int_cc;
80 
81  static bNodeType ntype;
82 
83  fn_node_type_base(&ntype, FN_NODE_FLOAT_TO_INT, "Float to Integer", NODE_CLASS_CONVERTER);
88  nodeRegisterType(&ntype);
89 }
#define NODE_CLASS_CONVERTER
Definition: BKE_node.h:351
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1357
#define FN_NODE_FLOAT_TO_INT
Definition: BKE_node.h:1524
#define BLI_assert_unreachable()
Definition: BLI_assert.h:93
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_NONNULL()
Definition: string.c:64
#define UNUSED(x)
#define IFACE_(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
void uiItemR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int flag, const char *name, int icon)
void set_matching_fn(const MultiFunction *fn)
OperationNode * node
const char * label
bNodeTree * ntree
ccl_device_inline float3 ceil(const float3 &a)
Definition: math_float3.h:363
static unsigned a[3]
Definition: RandGen.cpp:78
T floor(const T &a)
static void fn_node_float_to_int_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
static void fn_node_float_to_int_declare(NodeDeclarationBuilder &b)
static const fn::MultiFunction * get_multi_function(bNode &bnode)
static void node_float_to_int_label(const bNodeTree *UNUSED(ntree), const bNode *node, char *label, int maxlen)
static void fn_node_float_to_int_build_multi_function(NodeMultiFunctionBuilder &builder)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
void register_node_type_fn_float_to_int()
void fn_node_type_base(bNodeType *ntype, int type, const char *name, short nclass)
bool RNA_enum_name(const EnumPropertyItem *item, const int value, const char **r_name)
Definition: rna_access.c:1692
const EnumPropertyItem rna_enum_node_float_to_int_items[]
Definition: rna_nodetree.c:385
Defines a node type.
Definition: BKE_node.h:226
void(* labelfunc)(const struct bNodeTree *ntree, const struct bNode *node, char *label, int maxlen)
Definition: BKE_node.h:256
void(* draw_buttons)(struct uiLayout *, struct bContext *C, struct PointerRNA *ptr)
Definition: BKE_node.h:244
NodeMultiFunctionBuildFunction build_multi_function
Definition: BKE_node.h:313
NodeDeclareFunction declare
Definition: BKE_node.h:324
short custom1
#define N_(msgid)
PointerRNA * ptr
Definition: wm_files.c:3480