Blender V5.3
node_geometry_exec.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
8
9#include <iostream>
10
11#include "DNA_curves_types.h"
13#include "DNA_mesh_types.h"
15
17
18#include "BKE_curves.hh"
19#include "BKE_library.hh"
20#include "BKE_main.hh"
21#include "BKE_node_runtime.hh"
22
23#include "BLI_path_utils.hh"
24#include "BLI_string.hh"
25
26#include "BLT_translation.hh"
27
28#include "NOD_geometry_exec.hh"
29
30#include "node_geometry_util.hh"
31
32namespace blender::nodes {
33
35{
36 return DEG_get_bmain(this->depsgraph());
37}
38
40 const StringRef message) const
41{
42 if (eval_log::NodeTreeLogger *tree_logger = this->get_local_tree_logger()) {
43 tree_logger->node_warnings.append(
44 *tree_logger->allocator,
45 {node_.identifier, {type, tree_logger->allocator->copy_string(message)}});
46 }
47}
48
50 const NamedAttributeUsage usage)
51{
52 if (eval_log::NodeTreeLogger *tree_logger = this->get_local_tree_logger()) {
53 tree_logger->used_named_attributes.append(
54 *tree_logger->allocator,
55 {node_.identifier, tree_logger->allocator->copy_string(attribute_name), usage});
56 }
57}
58
60 const GeometrySet &geometry_set) const
61{
62 const SocketDeclaration &decl = *node_.input_by_identifier(identifier)->runtime->declaration;
63 const decl::Geometry *geo_decl = dynamic_cast<const decl::Geometry *>(&decl);
64 if (geo_decl == nullptr) {
65 return;
66 }
67
68 const bool only_realized_data = geo_decl->only_realized_data();
69 const bool only_instances = geo_decl->only_instances();
70 const Span<GeometryComponent::Type> supported_types = geo_decl->supported_types();
71
72 if (only_realized_data) {
73 if (geometry_set.has_instances()) {
75 TIP_("Instances in input geometry are ignored"));
76 }
77 }
78 if (only_instances) {
79 if (geometry_set.has_realized_data()) {
81 TIP_("Realized data in input geometry is ignored"));
82 }
83 }
84 if (supported_types.is_empty()) {
85 /* Assume all types are supported. */
86 return;
87 }
88 const Vector<GeometryComponent::Type> types_in_geometry = geometry_set.gather_component_types(
89 true, true);
90 for (const GeometryComponent::Type type : types_in_geometry) {
92 continue;
93 }
94 if (supported_types.contains(type)) {
95 continue;
96 }
97 std::string message = RPT_("Input geometry has unsupported type: ");
98 switch (type) {
100 if (const Mesh *mesh = geometry_set.get_mesh()) {
101 if (mesh->verts_num == 0) {
102 continue;
103 }
104 }
105 message += RPT_("Mesh");
106 break;
107 }
109 if (const PointCloud *pointcloud = geometry_set.get_pointcloud()) {
110 if (pointcloud->totpoint == 0) {
111 continue;
112 }
113 }
114 message += RPT_("Point Cloud");
115 break;
116 }
119 break;
120 }
122 message += CTX_RPT_(BLT_I18NCONTEXT_ID_ID, "Volume");
123 break;
124 }
126 if (const Curves *curves = geometry_set.get_curves()) {
127 if (curves->geometry.point_num == 0) {
128 continue;
129 }
130 }
131 message += RPT_("Curve");
132 break;
133 }
135 continue;
136 }
138 if (const GreasePencil *grease_pencil = geometry_set.get_grease_pencil()) {
139 if (grease_pencil->drawing_array_num == 0) {
140 continue;
141 }
142 }
143 message += RPT_("Grease Pencil");
144 break;
145 }
146 }
147 this->error_message_add(NodeWarningType::Info, std::move(message));
148 }
149}
150
152{
153 UNUSED_VARS_NDEBUG(geometry_set);
154#ifndef NDEBUG
155 if (const bke::CurvesEditHints *curve_edit_hints = geometry_set.get_curve_edit_hints()) {
156 /* If this is not valid, it's likely that the number of stored deformed points does not match
157 * the number of points in the original data. */
158 BLI_assert(curve_edit_hints->is_valid());
159 }
160#endif
161}
162
167
168void GeoNodeExecParams::check_input_access(const UString identifier) const
169{
170 const bNodeSocket *found_socket = nullptr;
171 for (const bNodeSocket *socket : node_.input_sockets()) {
172 if (socket->identifier_ustr() == identifier) {
173 found_socket = socket;
174 break;
175 }
176 }
177
178 if (found_socket == nullptr) {
179 std::cout << "Did not find an input socket with the identifier '" << identifier.ref()
180 << "'.\n";
181 std::cout << "Possible identifiers are: ";
182 for (const bNodeSocket *socket : node_.input_sockets()) {
183 if (socket->is_available()) {
184 std::cout << "'" << socket->identifier << "', ";
185 }
186 }
187 std::cout << "\n";
189 }
190 else if (found_socket->flag & SOCK_UNAVAIL) {
191 std::cout << "The socket corresponding to the identifier '" << identifier.ref()
192 << "' is disabled.\n";
194 }
195}
196
197void GeoNodeExecParams::check_output_access(const UString identifier) const
198{
199 const bNodeSocket *found_socket = nullptr;
200 for (const bNodeSocket *socket : node_.output_sockets()) {
201 if (socket->identifier == identifier) {
202 found_socket = socket;
203 break;
204 }
205 }
206
207 if (found_socket == nullptr) {
208 std::cout << "Did not find an output socket with the identifier '" << identifier.ref()
209 << "'.\n";
210 std::cout << "Possible identifiers are: ";
211 for (const bNodeSocket *socket : node_.output_sockets()) {
212 if (socket->is_available()) {
213 std::cout << "'" << socket->identifier << "', ";
214 }
215 }
216 std::cout << "\n";
218 }
219 else if (found_socket->flag & SOCK_UNAVAIL) {
220 std::cout << "The socket corresponding to the identifier '" << identifier.ref()
221 << "' is disabled.\n";
223 }
224 else if (params_.output_was_set(this->get_output_index(identifier))) {
225 std::cout << "The identifier '" << identifier.ref() << "' has been set already.\n";
227 }
228}
229
231{
232 if (!bke::attribute_name_is_anonymous(attribute_name)) {
234 }
235 if (!set_.names) {
237 }
238 if (set_.names->contains(attribute_name)) {
240 }
242}
243
244std::optional<std::string> GeoNodeExecParams::ensure_absolute_path(const StringRefNull path) const
245{
246 if (path.is_empty()) {
247 return std::nullopt;
248 }
249 if (!BLI_path_is_rel(path.c_str())) {
250 return path;
251 }
252 const Main &bmain = *this->bmain();
253 const bNodeTree &tree = node_.owner_tree();
254 const char *base_path = ID_BLEND_PATH(&bmain, &tree.id);
255 if (!base_path || base_path[0] == '\0') {
256 return std::nullopt;
257 }
258 char absolute_path[FILE_MAX];
259 STRNCPY(absolute_path, path.c_str());
260 BLI_path_abs(absolute_path, base_path);
261 return absolute_path;
262}
263
264} // namespace blender::nodes
Low-level operations for curves.
#define FILE_MAX
#define RPT_(msgid)
#define BLT_I18NCONTEXT_ID_ID
#define TIP_(msgid)
#define CTX_RPT_(context, msgid)
#define ID_BLEND_PATH(_bmain, _id)
Definition DNA_ID.h:688
#define BLI_assert_unreachable()
#define UNUSED_VARS_NDEBUG(...)
constexpr bool is_empty() const
Definition BLI_span.hh:264
constexpr bool contains(const T &value) const
Definition BLI_span.hh:281
constexpr const char * c_str() const
StringRefNull ref() const
constexpr bool is_empty() const
void error_message_add(const NodeWarningType type, StringRef message) const
eval_log::NodeTreeLogger * get_local_tree_logger() const
void check_output_geometry_set(const GeometrySet &geometry_set) const
void check_input_geometry_set(UString identifier, const GeometrySet &geometry_set) const
std::optional< std::string > ensure_absolute_path(StringRefNull path) const
void used_named_attribute(StringRef attribute_name, NamedAttributeUsage usage)
const Depsgraph * depsgraph() const
Result filter(StringRef attribute_name) const override
Span< bke::GeometryComponent::Type > supported_types() const
bool attribute_name_is_anonymous(const StringRef name)
void set_default_remaining_node_outputs(lf::Params &params, const bNode &node)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
char * STRNCPY(char(&dst)[N], const char *src)
bool BLI_path_abs(char path[FILE_MAX], const char *basepath) ATTR_NONNULL(1
Main * DEG_get_bmain(const Depsgraph *graph)
bool BLI_path_is_rel(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
const CurvesEditHints * get_curve_edit_hints() const
const GreasePencil * get_grease_pencil() const
const Curves * get_curves() const
const PointCloud * get_pointcloud() const
const Mesh * get_mesh() const
Vector< GeometryComponent::Type > gather_component_types(bool include_instances, bool ignore_empty) const