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