Blender  V3.3
node_geo_interpolate_domain.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #include "node_geometry_util.hh"
4 
5 #include "UI_interface.h"
6 #include "UI_resources.h"
7 
8 #include "BKE_attribute_math.hh"
9 
10 #include "BLI_task.hh"
11 
13 
15 
17 {
18  b.add_input<decl::Float>(N_("Value"), "Value_Float").supports_field();
19  b.add_input<decl::Int>(N_("Value"), "Value_Int").supports_field();
20  b.add_input<decl::Vector>(N_("Value"), "Value_Vector").supports_field();
21  b.add_input<decl::Color>(N_("Value"), "Value_Color").supports_field();
22  b.add_input<decl::Bool>(N_("Value"), "Value_Bool").supports_field();
23 
24  b.add_output<decl::Float>(N_("Value"), "Value_Float").field_source();
25  b.add_output<decl::Int>(N_("Value"), "Value_Int").field_source();
26  b.add_output<decl::Vector>(N_("Value"), "Value_Vector").field_source();
27  b.add_output<decl::Color>(N_("Value"), "Value_Color").field_source();
28  b.add_output<decl::Bool>(N_("Value"), "Value_Bool").field_source();
29 }
30 
31 static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
32 {
33  uiItemR(layout, ptr, "data_type", 0, "", ICON_NONE);
34  uiItemR(layout, ptr, "domain", 0, "", ICON_NONE);
35 }
36 
38 {
39  node->custom1 = ATTR_DOMAIN_POINT;
40  node->custom2 = CD_PROP_FLOAT;
41 }
42 
44 {
45  const eCustomDataType data_type = static_cast<eCustomDataType>(node->custom2);
46 
47  bNodeSocket *sock_in_float = static_cast<bNodeSocket *>(node->inputs.first);
48  bNodeSocket *sock_in_int = sock_in_float->next;
49  bNodeSocket *sock_in_vector = sock_in_int->next;
50  bNodeSocket *sock_in_color = sock_in_vector->next;
51  bNodeSocket *sock_in_bool = sock_in_color->next;
52 
53  bNodeSocket *sock_out_float = static_cast<bNodeSocket *>(node->outputs.first);
54  bNodeSocket *sock_out_int = sock_out_float->next;
55  bNodeSocket *sock_out_vector = sock_out_int->next;
56  bNodeSocket *sock_out_color = sock_out_vector->next;
57  bNodeSocket *sock_out_bool = sock_out_color->next;
58 
59  nodeSetSocketAvailability(ntree, sock_in_float, data_type == CD_PROP_FLOAT);
60  nodeSetSocketAvailability(ntree, sock_in_int, data_type == CD_PROP_INT32);
61  nodeSetSocketAvailability(ntree, sock_in_vector, data_type == CD_PROP_FLOAT3);
62  nodeSetSocketAvailability(ntree, sock_in_color, data_type == CD_PROP_COLOR);
63  nodeSetSocketAvailability(ntree, sock_in_bool, data_type == CD_PROP_BOOL);
64 
65  nodeSetSocketAvailability(ntree, sock_out_float, data_type == CD_PROP_FLOAT);
66  nodeSetSocketAvailability(ntree, sock_out_int, data_type == CD_PROP_INT32);
67  nodeSetSocketAvailability(ntree, sock_out_vector, data_type == CD_PROP_FLOAT3);
68  nodeSetSocketAvailability(ntree, sock_out_color, data_type == CD_PROP_COLOR);
69  nodeSetSocketAvailability(ntree, sock_out_bool, data_type == CD_PROP_BOOL);
70 }
71 
73 {
74  const bNodeType &node_type = params.node_type();
75  const std::optional<eCustomDataType> type = node_data_type_to_custom_data_type(
76  (eNodeSocketDatatype)params.other_socket().type);
77  if (type && *type != CD_PROP_STRING) {
78  params.add_item(IFACE_("Value"), [node_type, type](LinkSearchOpParams &params) {
79  bNode &node = params.add_node(node_type);
80  node.custom2 = *type;
81  params.update_and_connect_available_socket(node, "Value");
82  });
83  }
84 }
85 
87  private:
88  GField src_field_;
89  eAttrDomain src_domain_;
90 
91  public:
93  : GeometryFieldInput(field.cpp_type(), "Interpolate Domain"),
94  src_field_(std::move(field)),
95  src_domain_(domain)
96  {
97  }
98 
100  const eAttrDomain domain,
101  IndexMask /* mask */) const final
102  {
103  const GeometryComponentFieldContext context{component, src_domain_};
104  const int64_t src_domain_size = component.attribute_domain_size(src_domain_);
105  GArray values(src_field_.cpp_type(), src_domain_size);
106  FieldEvaluator value_evaluator{context, src_domain_size};
107  value_evaluator.add_with_destination(src_field_, values.as_mutable_span());
108  value_evaluator.evaluate();
109  return component.attributes()->adapt_domain(
110  GVArray::ForGArray(std::move(values)), src_domain_, domain);
111  }
112 };
113 
115 {
116  switch (data_type) {
117  case CD_PROP_BOOL:
118  return "Bool";
119  case CD_PROP_FLOAT:
120  return "Float";
121  case CD_PROP_INT32:
122  return "Int";
123  case CD_PROP_COLOR:
124  return "Color";
125  case CD_PROP_FLOAT3:
126  return "Vector";
127  default:
129  return "";
130  }
131 }
132 
134 {
135  const bNode &node = params.node();
136  const eAttrDomain domain = static_cast<eAttrDomain>(node.custom1);
137  const eCustomDataType data_type = static_cast<eCustomDataType>(node.custom2);
138 
139  attribute_math::convert_to_static_type(data_type, [&](auto dummy) {
140  using T = decltype(dummy);
141  static const std::string identifier = "Value_" + identifier_suffix(data_type);
142  Field<T> src_field = params.extract_input<Field<T>>(identifier);
143  Field<T> dst_field{std::make_shared<InterpolateDomain>(std::move(src_field), domain)};
144  params.set_output(identifier, std::move(dst_field));
145  });
146 }
147 
148 } // namespace blender::nodes::node_geo_interpolate_domain_cc
149 
151 {
153 
154  static bNodeType ntype;
155 
157  &ntype, GEO_NODE_INTERPOLATE_DOMAIN, "Interpolate Domain", NODE_CLASS_CONVERTER);
164  nodeRegisterType(&ntype);
165 }
eAttrDomain
Definition: BKE_attribute.h:25
@ ATTR_DOMAIN_POINT
Definition: BKE_attribute.h:27
#define NODE_CLASS_CONVERTER
Definition: BKE_node.h:351
void nodeSetSocketAvailability(struct bNodeTree *ntree, struct bNodeSocket *sock, bool is_available)
Definition: node.cc:3664
#define GEO_NODE_INTERPOLATE_DOMAIN
Definition: BKE_node.h:1504
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1357
#define BLI_assert_unreachable()
Definition: BLI_assert.h:93
#define final(a, b, c)
Definition: BLI_hash.h:21
#define UNUSED(x)
#define IFACE_(msgid)
static uint8 component(Color32 c, uint i)
Definition: ColorBlock.cpp:108
eCustomDataType
@ CD_PROP_FLOAT
@ CD_PROP_FLOAT3
@ CD_PROP_COLOR
@ CD_PROP_INT32
@ CD_PROP_BOOL
@ CD_PROP_STRING
eNodeSocketDatatype
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
void uiItemR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int flag, const char *name, int icon)
GMutableSpan as_mutable_span()
static GVArray ForGArray(GArray<> array)
const CPPType & cpp_type() const
Definition: FN_field.hh:663
const CPPType & cpp_type() const
Definition: FN_field.hh:122
GVArray get_varray_for_context(const GeometryComponent &component, const eAttrDomain domain, IndexMask) const final
OperationNode * node
void * tree
bNodeTree * ntree
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
#define T
void convert_to_static_type(const CPPType &cpp_type, const Func &func)
static void node_init(bNodeTree *UNUSED(tree), bNode *node)
static StringRefNull identifier_suffix(eCustomDataType data_type)
static void node_declare(NodeDeclarationBuilder &b)
static void node_update(bNodeTree *ntree, bNode *node)
static void node_gather_link_searches(GatherLinkSearchOpParams &params)
static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
std::optional< eCustomDataType > node_data_type_to_custom_data_type(const eNodeSocketDatatype type)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
static void node_init(const struct bContext *C, bNodeTree *ntree, bNode *node)
Definition: node.cc:1082
void register_node_type_geo_interpolate_domain()
void geo_node_type_base(bNodeType *ntype, int type, const char *name, short nclass)
__int64 int64_t
Definition: stdint.h:89
struct bNodeSocket * next
Defines a node type.
Definition: BKE_node.h:226
NodeGeometryExecFunction geometry_node_execute
Definition: BKE_node.h:316
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
Definition: BKE_node.h:335
void(* updatefunc)(struct bNodeTree *ntree, struct bNode *node)
Definition: BKE_node.h:265
void(* draw_buttons)(struct uiLayout *, struct bContext *C, struct PointerRNA *ptr)
Definition: BKE_node.h:244
NodeDeclareFunction declare
Definition: BKE_node.h:324
void(* initfunc)(struct bNodeTree *ntree, struct bNode *node)
Definition: BKE_node.h:270
#define N_(msgid)
PointerRNA * ptr
Definition: wm_files.c:3480