2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2020-12-02 13:25:25 +01:00
|
|
|
|
2025-01-22 23:29:33 +01:00
|
|
|
#include <iostream>
|
|
|
|
|
|
2024-06-14 18:57:26 +02:00
|
|
|
#include "DNA_curves_types.h"
|
|
|
|
|
#include "DNA_grease_pencil_types.h"
|
|
|
|
|
#include "DNA_mesh_types.h"
|
|
|
|
|
#include "DNA_pointcloud_types.h"
|
2021-02-16 17:15:08 -06:00
|
|
|
|
2023-09-22 03:18:17 +02:00
|
|
|
#include "DEG_depsgraph_query.hh"
|
2021-02-16 17:15:08 -06:00
|
|
|
|
2022-07-22 15:39:41 +02:00
|
|
|
#include "BKE_curves.hh"
|
2025-02-19 15:33:37 +01:00
|
|
|
#include "BKE_library.hh"
|
|
|
|
|
#include "BKE_main.hh"
|
2025-01-26 20:08:04 +01:00
|
|
|
#include "BKE_node_runtime.hh"
|
2021-12-07 15:21:59 +01:00
|
|
|
|
2025-02-19 15:33:37 +01:00
|
|
|
#include "BLI_path_utils.hh"
|
|
|
|
|
#include "BLI_string.h"
|
|
|
|
|
|
2024-02-09 18:59:42 +01:00
|
|
|
#include "BLT_translation.hh"
|
2023-08-13 10:50:52 +03:00
|
|
|
|
2020-12-02 13:25:25 +01:00
|
|
|
#include "NOD_geometry_exec.hh"
|
|
|
|
|
|
Geometry Nodes: Allow attribute nodes to use different domains
Currently every attribute node assumes that the attribute exists on the
"points" domain, so it generally isn't possible to work with attributes
on other domains like edges, polygons, and corners.
This commit adds a heuristic to each attribute node to determine the
correct domain for the result attribute. In general, it works like this:
- If the output attribute already exists, use that domain.
- Otherwise, use the highest priority domain of the input attributes.
- If none of the inputs are attributes, use the default domain (points).
For the implementation I abstracted the check a bit, but in each
node has a slightly different situation, so we end up with slightly
different `get_result_domain` functions in each node. I think this makes
sense, it keeps the code flexible and more easily understandable.
Note that we might eventually want to expose a domain drop-down to some
of the nodes. But that will be a separate discussion; this commit focuses
on making a more useful choice automatically.
Differential Revision: https://developer.blender.org/D10389
2021-02-12 12:46:17 -06:00
|
|
|
#include "node_geometry_util.hh"
|
|
|
|
|
|
2020-12-02 13:25:25 +01:00
|
|
|
namespace blender::nodes {
|
|
|
|
|
|
2024-04-17 16:19:28 -04:00
|
|
|
Main *GeoNodeExecParams::bmain() const
|
|
|
|
|
{
|
|
|
|
|
return DEG_get_bmain(this->depsgraph());
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-17 12:08:43 +02:00
|
|
|
void GeoNodeExecParams::error_message_add(const NodeWarningType type,
|
|
|
|
|
const StringRef message) const
|
2021-02-16 17:15:08 -06:00
|
|
|
{
|
2022-09-13 08:44:26 +02:00
|
|
|
if (geo_eval_log::GeoTreeLogger *tree_logger = this->get_local_tree_logger()) {
|
2022-12-01 14:53:27 -06:00
|
|
|
tree_logger->node_warnings.append(
|
2024-02-28 22:22:21 +01:00
|
|
|
*tree_logger->allocator,
|
2022-12-01 14:53:27 -06:00
|
|
|
{node_.identifier, {type, tree_logger->allocator->copy_string(message)}});
|
2021-07-12 14:29:28 +02:00
|
|
|
}
|
2021-02-16 17:15:08 -06:00
|
|
|
}
|
|
|
|
|
|
2022-09-17 12:08:43 +02:00
|
|
|
void GeoNodeExecParams::used_named_attribute(const StringRef attribute_name,
|
2022-09-13 08:44:26 +02:00
|
|
|
const NamedAttributeUsage usage)
|
2022-04-14 16:31:09 +02:00
|
|
|
{
|
2022-09-13 08:44:26 +02:00
|
|
|
if (geo_eval_log::GeoTreeLogger *tree_logger = this->get_local_tree_logger()) {
|
2022-12-01 14:53:27 -06:00
|
|
|
tree_logger->used_named_attributes.append(
|
2024-02-28 22:22:21 +01:00
|
|
|
*tree_logger->allocator,
|
2022-12-01 14:53:27 -06:00
|
|
|
{node_.identifier, tree_logger->allocator->copy_string(attribute_name), usage});
|
2022-04-14 16:31:09 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-26 20:00:03 +02:00
|
|
|
void GeoNodeExecParams::check_input_geometry_set(StringRef identifier,
|
|
|
|
|
const GeometrySet &geometry_set) const
|
|
|
|
|
{
|
2025-07-31 21:58:58 +02:00
|
|
|
const SocketDeclaration &decl = *node_.input_by_identifier(identifier)->runtime->declaration;
|
2021-10-26 20:00:03 +02:00
|
|
|
const decl::Geometry *geo_decl = dynamic_cast<const decl::Geometry *>(&decl);
|
|
|
|
|
if (geo_decl == nullptr) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const bool only_realized_data = geo_decl->only_realized_data();
|
|
|
|
|
const bool only_instances = geo_decl->only_instances();
|
2023-06-15 22:18:28 +02:00
|
|
|
const Span<GeometryComponent::Type> supported_types = geo_decl->supported_types();
|
2021-10-26 20:00:03 +02:00
|
|
|
|
|
|
|
|
if (only_realized_data) {
|
|
|
|
|
if (geometry_set.has_instances()) {
|
2021-10-27 15:31:00 +02:00
|
|
|
this->error_message_add(NodeWarningType::Info,
|
|
|
|
|
TIP_("Instances in input geometry are ignored"));
|
2021-10-26 20:00:03 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (only_instances) {
|
|
|
|
|
if (geometry_set.has_realized_data()) {
|
|
|
|
|
this->error_message_add(NodeWarningType::Info,
|
2021-10-27 15:31:00 +02:00
|
|
|
TIP_("Realized data in input geometry is ignored"));
|
2021-10-26 20:00:03 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (supported_types.is_empty()) {
|
|
|
|
|
/* Assume all types are supported. */
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-06-15 22:18:28 +02:00
|
|
|
const Vector<GeometryComponent::Type> types_in_geometry = geometry_set.gather_component_types(
|
2021-10-26 20:00:03 +02:00
|
|
|
true, true);
|
2023-06-15 22:18:28 +02:00
|
|
|
for (const GeometryComponent::Type type : types_in_geometry) {
|
|
|
|
|
if (type == GeometryComponent::Type::Instance) {
|
2021-10-26 20:00:03 +02:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (supported_types.contains(type)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2024-01-11 19:49:03 +01:00
|
|
|
std::string message = RPT_("Input geometry has unsupported type: ");
|
2021-10-26 20:00:03 +02:00
|
|
|
switch (type) {
|
2023-06-15 22:18:28 +02:00
|
|
|
case GeometryComponent::Type::Mesh: {
|
2024-06-14 18:57:26 +02:00
|
|
|
if (const Mesh *mesh = geometry_set.get_mesh()) {
|
|
|
|
|
if (mesh->verts_num == 0) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-01-11 19:49:03 +01:00
|
|
|
message += RPT_("Mesh");
|
2021-10-26 20:00:03 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2023-06-15 22:18:28 +02:00
|
|
|
case GeometryComponent::Type::PointCloud: {
|
2024-06-14 18:57:26 +02:00
|
|
|
if (const PointCloud *pointcloud = geometry_set.get_pointcloud()) {
|
|
|
|
|
if (pointcloud->totpoint == 0) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-01-11 19:49:03 +01:00
|
|
|
message += RPT_("Point Cloud");
|
2021-10-26 20:00:03 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2023-06-15 22:18:28 +02:00
|
|
|
case GeometryComponent::Type::Instance: {
|
2021-10-26 20:00:03 +02:00
|
|
|
BLI_assert_unreachable();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2023-06-15 22:18:28 +02:00
|
|
|
case GeometryComponent::Type::Volume: {
|
2024-01-11 19:49:03 +01:00
|
|
|
message += CTX_RPT_(BLT_I18NCONTEXT_ID_ID, "Volume");
|
2021-10-26 20:00:03 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2023-06-15 22:18:28 +02:00
|
|
|
case GeometryComponent::Type::Curve: {
|
2024-06-14 18:57:26 +02:00
|
|
|
if (const Curves *curves = geometry_set.get_curves()) {
|
|
|
|
|
if (curves->geometry.point_num == 0) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-01-11 19:49:03 +01:00
|
|
|
message += RPT_("Curve");
|
2021-10-26 20:00:03 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2023-06-15 22:18:28 +02:00
|
|
|
case GeometryComponent::Type::Edit: {
|
2022-07-22 15:39:41 +02:00
|
|
|
continue;
|
|
|
|
|
}
|
2023-07-26 13:59:37 +02:00
|
|
|
case GeometryComponent::Type::GreasePencil: {
|
2024-06-14 18:57:26 +02:00
|
|
|
if (const GreasePencil *grease_pencil = geometry_set.get_grease_pencil()) {
|
|
|
|
|
if (grease_pencil->drawing_array_num == 0) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-01-11 19:49:03 +01:00
|
|
|
message += RPT_("Grease Pencil");
|
2023-07-26 13:59:37 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2021-10-26 20:00:03 +02:00
|
|
|
}
|
|
|
|
|
this->error_message_add(NodeWarningType::Info, std::move(message));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-22 15:39:41 +02:00
|
|
|
void GeoNodeExecParams::check_output_geometry_set(const GeometrySet &geometry_set) const
|
|
|
|
|
{
|
|
|
|
|
UNUSED_VARS_NDEBUG(geometry_set);
|
2023-12-04 15:13:06 +01:00
|
|
|
#ifndef NDEBUG
|
2023-08-03 17:09:18 +02:00
|
|
|
if (const bke::CurvesEditHints *curve_edit_hints = geometry_set.get_curve_edit_hints()) {
|
2022-07-22 15:39:41 +02:00
|
|
|
/* If this is not valid, it's likely that the number of stored deformed points does not match
|
|
|
|
|
* the number of points in the original data. */
|
|
|
|
|
BLI_assert(curve_edit_hints->is_valid());
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-14 11:43:46 -06:00
|
|
|
const bNodeSocket *GeoNodeExecParams::find_available_socket(const StringRef name) const
|
2020-12-09 16:20:48 +01:00
|
|
|
{
|
2022-09-13 08:44:26 +02:00
|
|
|
for (const bNodeSocket *socket : node_.input_sockets()) {
|
2022-08-31 12:15:57 +02:00
|
|
|
if (socket->is_available() && socket->name == name) {
|
|
|
|
|
return socket;
|
2020-12-09 16:20:48 +01:00
|
|
|
}
|
|
|
|
|
}
|
2020-12-14 11:43:46 -06:00
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-26 18:00:52 +01:00
|
|
|
void GeoNodeExecParams::set_default_remaining_outputs()
|
|
|
|
|
{
|
2023-12-17 14:00:07 +01:00
|
|
|
set_default_remaining_node_outputs(params_, node_);
|
2021-11-26 18:00:52 +01:00
|
|
|
}
|
|
|
|
|
|
2025-08-12 07:45:03 +02:00
|
|
|
void GeoNodeExecParams::check_input_access(StringRef identifier) const
|
2020-12-02 13:25:25 +01:00
|
|
|
{
|
2022-08-31 12:15:57 +02:00
|
|
|
const bNodeSocket *found_socket = nullptr;
|
2022-09-13 08:44:26 +02:00
|
|
|
for (const bNodeSocket *socket : node_.input_sockets()) {
|
2022-08-31 12:15:57 +02:00
|
|
|
if (socket->identifier == identifier) {
|
|
|
|
|
found_socket = socket;
|
2020-12-02 13:25:25 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-02-16 13:06:18 -06:00
|
|
|
|
2020-12-02 13:25:25 +01:00
|
|
|
if (found_socket == nullptr) {
|
|
|
|
|
std::cout << "Did not find an input socket with the identifier '" << identifier << "'.\n";
|
|
|
|
|
std::cout << "Possible identifiers are: ";
|
2022-09-13 08:44:26 +02:00
|
|
|
for (const bNodeSocket *socket : node_.input_sockets()) {
|
2021-02-16 13:06:18 -06:00
|
|
|
if (socket->is_available()) {
|
2022-08-31 12:15:57 +02:00
|
|
|
std::cout << "'" << socket->identifier << "', ";
|
2020-12-02 13:25:25 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
std::cout << "\n";
|
2021-04-27 13:03:40 +02:00
|
|
|
BLI_assert_unreachable();
|
2020-12-02 13:25:25 +01:00
|
|
|
}
|
|
|
|
|
else if (found_socket->flag & SOCK_UNAVAIL) {
|
|
|
|
|
std::cout << "The socket corresponding to the identifier '" << identifier
|
|
|
|
|
<< "' is disabled.\n";
|
2021-04-27 13:03:40 +02:00
|
|
|
BLI_assert_unreachable();
|
2020-12-02 13:25:25 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-12 07:45:03 +02:00
|
|
|
void GeoNodeExecParams::check_output_access(StringRef identifier) const
|
2020-12-02 13:25:25 +01:00
|
|
|
{
|
2022-08-31 12:15:57 +02:00
|
|
|
const bNodeSocket *found_socket = nullptr;
|
2022-09-13 08:44:26 +02:00
|
|
|
for (const bNodeSocket *socket : node_.output_sockets()) {
|
2022-08-31 12:15:57 +02:00
|
|
|
if (socket->identifier == identifier) {
|
|
|
|
|
found_socket = socket;
|
2020-12-02 13:25:25 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-02-16 13:06:18 -06:00
|
|
|
|
2020-12-02 13:25:25 +01:00
|
|
|
if (found_socket == nullptr) {
|
|
|
|
|
std::cout << "Did not find an output socket with the identifier '" << identifier << "'.\n";
|
|
|
|
|
std::cout << "Possible identifiers are: ";
|
2022-09-13 08:44:26 +02:00
|
|
|
for (const bNodeSocket *socket : node_.output_sockets()) {
|
|
|
|
|
if (socket->is_available()) {
|
2022-08-31 12:15:57 +02:00
|
|
|
std::cout << "'" << socket->identifier << "', ";
|
2020-12-02 13:25:25 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
std::cout << "\n";
|
2021-04-27 13:03:40 +02:00
|
|
|
BLI_assert_unreachable();
|
2020-12-02 13:25:25 +01:00
|
|
|
}
|
|
|
|
|
else if (found_socket->flag & SOCK_UNAVAIL) {
|
|
|
|
|
std::cout << "The socket corresponding to the identifier '" << identifier
|
|
|
|
|
<< "' is disabled.\n";
|
2021-04-27 13:03:40 +02:00
|
|
|
BLI_assert_unreachable();
|
2020-12-02 13:25:25 +01:00
|
|
|
}
|
2022-09-13 08:44:26 +02:00
|
|
|
else if (params_.output_was_set(this->get_output_index(identifier))) {
|
2020-12-02 13:25:25 +01:00
|
|
|
std::cout << "The identifier '" << identifier << "' has been set already.\n";
|
2021-04-27 13:03:40 +02:00
|
|
|
BLI_assert_unreachable();
|
2020-12-02 13:25:25 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-05 11:33:35 +02:00
|
|
|
AttributeFilter::Result NodeAttributeFilter::filter(const StringRef attribute_name) const
|
|
|
|
|
{
|
|
|
|
|
if (!bke::attribute_name_is_anonymous(attribute_name)) {
|
|
|
|
|
return AttributeFilter::Result::Process;
|
|
|
|
|
}
|
|
|
|
|
if (!set_.names) {
|
|
|
|
|
return AttributeFilter::Result::AllowSkip;
|
|
|
|
|
}
|
|
|
|
|
if (set_.names->contains(attribute_name)) {
|
|
|
|
|
return AttributeFilter::Result::Process;
|
|
|
|
|
}
|
|
|
|
|
return AttributeFilter::Result::AllowSkip;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-19 15:33:37 +01:00
|
|
|
std::optional<std::string> GeoNodeExecParams::ensure_absolute_path(const StringRefNull path) const
|
|
|
|
|
{
|
|
|
|
|
if (path.is_empty()) {
|
|
|
|
|
return std::nullopt;
|
|
|
|
|
}
|
|
|
|
|
if (!BLI_path_is_rel(path.c_str())) {
|
|
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
const Main &bmain = *this->bmain();
|
|
|
|
|
const bNodeTree &tree = node_.owner_tree();
|
|
|
|
|
const char *base_path = ID_BLEND_PATH(&bmain, &tree.id);
|
|
|
|
|
if (!base_path || base_path[0] == '\0') {
|
|
|
|
|
return std::nullopt;
|
|
|
|
|
}
|
|
|
|
|
char absolute_path[FILE_MAX];
|
|
|
|
|
STRNCPY(absolute_path, path.c_str());
|
|
|
|
|
BLI_path_abs(absolute_path, base_path);
|
|
|
|
|
return absolute_path;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-02 13:25:25 +01:00
|
|
|
} // namespace blender::nodes
|