Blender  V3.3
intern/node_geometry_exec.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #include "DNA_modifier_types.h"
4 
5 #include "DEG_depsgraph_query.h"
6 
7 #include "BKE_curves.hh"
9 
10 #include "NOD_geometry_exec.hh"
11 
12 #include "node_geometry_util.hh"
13 
15 
16 namespace blender::nodes {
17 
18 void GeoNodeExecParams::error_message_add(const NodeWarningType type, std::string message) const
19 {
20  if (provider_->logger == nullptr) {
21  return;
22  }
23  LocalGeoLogger &local_logger = provider_->logger->local();
24  local_logger.log_node_warning(provider_->dnode, type, std::move(message));
25 }
26 
27 void GeoNodeExecParams::used_named_attribute(std::string attribute_name,
28  const eNamedAttrUsage usage)
29 {
30  if (provider_->logger == nullptr) {
31  return;
32  }
33  LocalGeoLogger &local_logger = provider_->logger->local();
34  local_logger.log_used_named_attribute(provider_->dnode, std::move(attribute_name), usage);
35 }
36 
38  const GeometrySet &geometry_set) const
39 {
40  const SocketDeclaration &decl =
41  *provider_->dnode->input_by_identifier(identifier).bsocket()->runtime->declaration;
42  const decl::Geometry *geo_decl = dynamic_cast<const decl::Geometry *>(&decl);
43  if (geo_decl == nullptr) {
44  return;
45  }
46 
47  const bool only_realized_data = geo_decl->only_realized_data();
48  const bool only_instances = geo_decl->only_instances();
49  const Span<GeometryComponentType> supported_types = geo_decl->supported_types();
50 
51  if (only_realized_data) {
52  if (geometry_set.has_instances()) {
54  TIP_("Instances in input geometry are ignored"));
55  }
56  }
57  if (only_instances) {
58  if (geometry_set.has_realized_data()) {
60  TIP_("Realized data in input geometry is ignored"));
61  }
62  }
63  if (supported_types.is_empty()) {
64  /* Assume all types are supported. */
65  return;
66  }
67  const Vector<GeometryComponentType> types_in_geometry = geometry_set.gather_component_types(
68  true, true);
69  for (const GeometryComponentType type : types_in_geometry) {
71  continue;
72  }
73  if (supported_types.contains(type)) {
74  continue;
75  }
76  std::string message = TIP_("Input geometry has unsupported type: ");
77  switch (type) {
79  message += TIP_("Mesh");
80  break;
81  }
83  message += TIP_("Point Cloud");
84  break;
85  }
88  break;
89  }
91  message += TIP_("Volume");
92  break;
93  }
95  message += TIP_("Curve");
96  break;
97  }
99  continue;
100  }
101  }
102  this->error_message_add(NodeWarningType::Info, std::move(message));
103  }
104 }
105 
107 {
108  UNUSED_VARS_NDEBUG(geometry_set);
109 #ifdef DEBUG
110  if (const bke::CurvesEditHints *curve_edit_hints =
111  geometry_set.get_curve_edit_hints_for_read()) {
112  /* If this is not valid, it's likely that the number of stored deformed points does not match
113  * the number of points in the original data. */
114  BLI_assert(curve_edit_hints->is_valid());
115  }
116 #endif
117 }
118 
119 const bNodeSocket *GeoNodeExecParams::find_available_socket(const StringRef name) const
120 {
121  for (const InputSocketRef *socket : provider_->dnode->inputs()) {
122  if (socket->is_available() && socket->name() == name) {
123  return socket->bsocket();
124  }
125  }
126 
127  return nullptr;
128 }
129 
131 {
132  return provider_->dnode->label_or_name() + TIP_(" node");
133 }
134 
136 {
137  provider_->set_default_remaining_outputs();
138 }
139 
140 void GeoNodeExecParams::check_input_access(StringRef identifier,
141  const CPPType *requested_type) const
142 {
143  bNodeSocket *found_socket = nullptr;
144  for (const InputSocketRef *socket : provider_->dnode->inputs()) {
145  if (socket->identifier() == identifier) {
146  found_socket = socket->bsocket();
147  break;
148  }
149  }
150 
151  if (found_socket == nullptr) {
152  std::cout << "Did not find an input socket with the identifier '" << identifier << "'.\n";
153  std::cout << "Possible identifiers are: ";
154  for (const InputSocketRef *socket : provider_->dnode->inputs()) {
155  if (socket->is_available()) {
156  std::cout << "'" << socket->identifier() << "', ";
157  }
158  }
159  std::cout << "\n";
161  }
162  else if (found_socket->flag & SOCK_UNAVAIL) {
163  std::cout << "The socket corresponding to the identifier '" << identifier
164  << "' is disabled.\n";
166  }
167  else if (!provider_->can_get_input(identifier)) {
168  std::cout << "The identifier '" << identifier
169  << "' is valid, but there is no value for it anymore.\n";
170  std::cout << "Most likely it has been extracted before.\n";
172  }
173  else if (requested_type != nullptr) {
174  const CPPType &expected_type = *found_socket->typeinfo->geometry_nodes_cpp_type;
175  if (*requested_type != expected_type) {
176  std::cout << "The requested type '" << requested_type->name() << "' is incorrect. Expected '"
177  << expected_type.name() << "'.\n";
179  }
180  }
181 }
182 
183 void GeoNodeExecParams::check_output_access(StringRef identifier, const CPPType &value_type) const
184 {
185  bNodeSocket *found_socket = nullptr;
186  for (const OutputSocketRef *socket : provider_->dnode->outputs()) {
187  if (socket->identifier() == identifier) {
188  found_socket = socket->bsocket();
189  break;
190  }
191  }
192 
193  if (found_socket == nullptr) {
194  std::cout << "Did not find an output socket with the identifier '" << identifier << "'.\n";
195  std::cout << "Possible identifiers are: ";
196  for (const OutputSocketRef *socket : provider_->dnode->outputs()) {
197  if (socket->is_available()) {
198  std::cout << "'" << socket->identifier() << "', ";
199  }
200  }
201  std::cout << "\n";
203  }
204  else if (found_socket->flag & SOCK_UNAVAIL) {
205  std::cout << "The socket corresponding to the identifier '" << identifier
206  << "' is disabled.\n";
208  }
209  else if (!provider_->can_set_output(identifier)) {
210  std::cout << "The identifier '" << identifier << "' has been set already.\n";
212  }
213  else {
214  const CPPType &expected_type = *found_socket->typeinfo->geometry_nodes_cpp_type;
215  if (value_type != expected_type) {
216  std::cout << "The value type '" << value_type.name() << "' is incorrect. Expected '"
217  << expected_type.name() << "'.\n";
219  }
220  }
221 }
222 
223 } // namespace blender::nodes
Low-level operations for curves.
GeometryComponentType
@ GEO_COMPONENT_TYPE_MESH
@ GEO_COMPONENT_TYPE_POINT_CLOUD
@ GEO_COMPONENT_TYPE_INSTANCES
@ GEO_COMPONENT_TYPE_EDIT
@ GEO_COMPONENT_TYPE_CURVE
@ GEO_COMPONENT_TYPE_VOLUME
#define BLI_assert_unreachable()
Definition: BLI_assert.h:93
#define BLI_assert(a)
Definition: BLI_assert.h:46
#define UNUSED_VARS_NDEBUG(...)
#define TIP_(msgid)
@ SOCK_UNAVAIL
_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
in reality light always falls off quadratically Particle Info
StringRefNull name() const
constexpr bool is_empty() const
Definition: BLI_span.hh:248
constexpr bool contains(const T &value) const
Definition: BLI_span.hh:265
geometry_nodes_eval_log::GeoLogger * logger
virtual bool can_get_input(StringRef identifier) const =0
virtual bool can_set_output(StringRef identifier) const =0
void used_named_attribute(std::string attribute_name, eNamedAttrUsage usage)
void check_output_geometry_set(const GeometrySet &geometry_set) const
void check_input_geometry_set(StringRef identifier, const GeometrySet &geometry_set) const
void error_message_add(const NodeWarningType type, std::string message) const
Span< const InputSocketRef * > inputs() const
Span< const OutputSocketRef * > outputs() const
StringRefNull label_or_name() const
const InputSocketRef & input_by_identifier(StringRef identifier) const
bNodeSocket * bsocket() const
Span< GeometryComponentType > supported_types() const
void log_node_warning(DNode node, NodeWarningType type, std::string message)
void log_used_named_attribute(DNode node, std::string attribute_name, eNamedAttrUsage usage)
bool has_realized_data() const
blender::Vector< GeometryComponentType > gather_component_types(bool include_instances, bool ignore_empty) const
bool has_instances() const
const blender::bke::CurvesEditHints * get_curve_edit_hints_for_read() const
const CPPTypeHandle * geometry_nodes_cpp_type
Definition: BKE_node.h:199
bNodeSocketRuntimeHandle * runtime
struct bNodeSocketType * typeinfo
char identifier[64]