Blender  V2.93
NOD_geometry_exec.hh
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
17 #pragma once
18 
19 #include "FN_generic_value_map.hh"
20 
21 #include "BKE_attribute_access.hh"
22 #include "BKE_geometry_set.hh"
24 #include "BKE_node_ui_storage.hh"
26 
27 #include "DNA_node_types.h"
28 
29 #include "NOD_derived_node_tree.hh"
30 
31 struct Depsgraph;
32 struct ModifierData;
33 
34 namespace blender::nodes {
35 
49 using bke::PersistentDataHandleMap;
50 using bke::PersistentObjectHandle;
51 using bke::ReadAttribute;
53 using bke::WriteAttribute;
55 using fn::CPPType;
56 using fn::GMutablePointer;
57 using fn::GPointer;
58 using fn::GValueMap;
59 
61  private:
62  const DNode node_;
63  GValueMap<StringRef> &input_values_;
64  GValueMap<StringRef> &output_values_;
65  const PersistentDataHandleMap &handle_map_;
66  const Object *self_object_;
67  const ModifierData *modifier_;
68  Depsgraph *depsgraph_;
69 
70  public:
72  GValueMap<StringRef> &input_values,
73  GValueMap<StringRef> &output_values,
75  const Object *self_object,
76  const ModifierData *modifier,
78  : node_(node),
79  input_values_(input_values),
80  output_values_(output_values),
81  handle_map_(handle_map),
82  self_object_(self_object),
83  modifier_(modifier),
84  depsgraph_(depsgraph)
85  {
86  }
87 
95  {
96 #ifdef DEBUG
97  this->check_extract_input(identifier);
98 #endif
99  return input_values_.extract(identifier);
100  }
101 
107  template<typename T> T extract_input(StringRef identifier)
108  {
109 #ifdef DEBUG
110  this->check_extract_input(identifier, &CPPType::get<T>());
111 #endif
112  return input_values_.extract<T>(identifier);
113  }
114 
120  template<typename T> Vector<T> extract_multi_input(StringRef identifier)
121  {
122  Vector<T> values;
123  int index = 0;
124  while (true) {
125  std::string sub_identifier = identifier;
126  if (index > 0) {
127  sub_identifier += "[" + std::to_string(index) + "]";
128  }
129  if (!input_values_.contains(sub_identifier)) {
130  break;
131  }
132  values.append(input_values_.extract<T, StringRef>(sub_identifier));
133  index++;
134  }
135  return values;
136  }
137 
141  template<typename T> const T &get_input(StringRef identifier) const
142  {
143 #ifdef DEBUG
144  this->check_extract_input(identifier, &CPPType::get<T>());
145 #endif
146  return input_values_.lookup<T>(identifier);
147  }
148 
154  {
155 #ifdef DEBUG
156  BLI_assert(value.type() != nullptr);
157  BLI_assert(value.get() != nullptr);
158  this->check_set_output(identifier, *value.type());
159 #endif
160  output_values_.add_new_by_move(identifier, value);
161  }
162 
163  void set_output_by_copy(StringRef identifier, GPointer value)
164  {
165 #ifdef DEBUG
166  BLI_assert(value.type() != nullptr);
167  BLI_assert(value.get() != nullptr);
168  this->check_set_output(identifier, *value.type());
169 #endif
170  output_values_.add_new_by_copy(identifier, value);
171  }
172 
176  template<typename T> void set_output(StringRef identifier, T &&value)
177  {
178 #ifdef DEBUG
179  this->check_set_output(identifier, CPPType::get<std::decay_t<T>>());
180 #endif
181  output_values_.add_new(identifier, std::forward<T>(value));
182  }
183 
187  const bNode &node() const
188  {
189  return *node_->bnode();
190  }
191 
193  {
194  return handle_map_;
195  }
196 
197  const Object *self_object() const
198  {
199  return self_object_;
200  }
201 
203  {
204  return depsgraph_;
205  }
206 
211  void error_message_add(const NodeWarningType type, std::string message) const;
212 
222  const AttributeDomain domain,
223  const CustomDataType type,
224  const void *default_value) const;
225 
226  template<typename T>
229  const AttributeDomain domain,
230  const T &default_value) const
231  {
232  const CustomDataType type = bke::cpp_type_to_custom_data_type(CPPType::get<T>());
233  return this->get_input_attribute(name, component, domain, type, &default_value);
234  }
235 
242  const CustomDataType default_type) const;
243 
246  const AttributeDomain default_domain) const;
247 
248  private:
249  /* Utilities for detecting common errors at when using this class. */
250  void check_extract_input(StringRef identifier, const CPPType *requested_type = nullptr) const;
251  void check_set_output(StringRef identifier, const CPPType &value_type) const;
252 
253  /* Find the active socket socket with the input name (not the identifier). */
254  const bNodeSocket *find_available_socket(const StringRef name) const;
255 };
256 
257 } // namespace blender::nodes
AttributeDomain
Definition: BKE_attribute.h:41
NodeWarningType
#define BLI_assert(a)
Definition: BLI_assert.h:58
static uint8 component(Color32 c, uint i)
Definition: ColorBlock.cpp:126
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:51
CustomDataType
_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
static std::string default_domain
void append(const T &value)
Definition: BLI_vector.hh:438
static const CPPType & get()
const CPPType * type() const
const void * get() const
const CPPType * type() const
GMutablePointer extract(const ForwardKey &key)
const T & lookup(const ForwardKey &key) const
void add_new(ForwardKey &&key, T &&value)
void add_new_by_copy(ForwardKey &&key, GPointer value)
void add_new_by_move(ForwardKey &&key, GMutablePointer value)
bool contains(const ForwardKey &key) const
T extract_input(StringRef identifier)
GMutablePointer extract_input(StringRef identifier)
AttributeDomain get_highest_priority_input_domain(Span< std::string > names, const GeometryComponent &component, const AttributeDomain default_domain) const
const PersistentDataHandleMap & handle_map() const
Vector< T > extract_multi_input(StringRef identifier)
void set_output(StringRef identifier, T &&value)
GeoNodeExecParams(const DNode node, GValueMap< StringRef > &input_values, GValueMap< StringRef > &output_values, const PersistentDataHandleMap &handle_map, const Object *self_object, const ModifierData *modifier, Depsgraph *depsgraph)
CustomDataType get_input_attribute_data_type(const StringRef name, const GeometryComponent &component, const CustomDataType default_type) const
bke::TypedReadAttribute< T > get_input_attribute(const StringRef name, const GeometryComponent &component, const AttributeDomain domain, const T &default_value) const
void set_output_by_copy(StringRef identifier, GPointer value)
const T & get_input(StringRef identifier) const
ReadAttributePtr get_input_attribute(const StringRef name, const GeometryComponent &component, const AttributeDomain domain, const CustomDataType type, const void *default_value) const
void set_output_by_move(StringRef identifier, GMutablePointer value)
void error_message_add(const NodeWarningType type, std::string message) const
static char ** names
Definition: makesdna.c:162
#define T
TypedReadAttribute< Color4f > Color4fReadAttribute
CustomDataType cpp_type_to_custom_data_type(const CPPType &type)
TypedWriteAttribute< float3 > Float3WriteAttribute
TypedWriteAttribute< Color4f > Color4fWriteAttribute
TypedReadAttribute< float > FloatReadAttribute
TypedReadAttribute< float3 > Float3ReadAttribute
TypedReadAttribute< int > Int32ReadAttribute
std::unique_ptr< WriteAttribute > WriteAttributePtr
GeometrySet geometry_set_realize_instances(const GeometrySet &geometry_set)
TypedWriteAttribute< int > Int32WriteAttribute
TypedReadAttribute< bool > BooleanReadAttribute
TypedWriteAttribute< float2 > Float2WriteAttribute
TypedWriteAttribute< float > FloatWriteAttribute
TypedReadAttribute< float2 > Float2ReadAttribute
TypedWriteAttribute< bool > BooleanWriteAttribute
std::unique_ptr< ReadAttribute > ReadAttributePtr
std::string to_string(const T &n)