2022-02-11 09:07:11 +11:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2020-12-02 13:25:25 +01:00
|
|
|
|
2021-02-16 17:15:08 -06:00
|
|
|
#include "DNA_modifier_types.h"
|
|
|
|
|
|
|
|
|
|
#include "DEG_depsgraph_query.h"
|
|
|
|
|
|
2022-07-22 15:39:41 +02:00
|
|
|
#include "BKE_curves.hh"
|
2021-12-07 15:21:59 +01:00
|
|
|
#include "BKE_type_conversions.hh"
|
|
|
|
|
|
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"
|
|
|
|
|
|
2021-07-07 11:20:19 +02:00
|
|
|
using blender::nodes::geometry_nodes_eval_log::LocalGeoLogger;
|
|
|
|
|
|
2020-12-02 13:25:25 +01:00
|
|
|
namespace blender::nodes {
|
|
|
|
|
|
2021-02-16 17:15:08 -06:00
|
|
|
void GeoNodeExecParams::error_message_add(const NodeWarningType type, std::string message) const
|
|
|
|
|
{
|
2021-07-12 14:29:28 +02:00
|
|
|
if (provider_->logger == nullptr) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-07-07 11:20:19 +02:00
|
|
|
LocalGeoLogger &local_logger = provider_->logger->local();
|
|
|
|
|
local_logger.log_node_warning(provider_->dnode, type, std::move(message));
|
2021-02-16 17:15:08 -06:00
|
|
|
}
|
|
|
|
|
|
2022-04-14 16:31:09 +02:00
|
|
|
void GeoNodeExecParams::used_named_attribute(std::string attribute_name,
|
2022-06-01 14:38:06 +10:00
|
|
|
const eNamedAttrUsage usage)
|
2022-04-14 16:31:09 +02:00
|
|
|
{
|
|
|
|
|
if (provider_->logger == nullptr) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
LocalGeoLogger &local_logger = provider_->logger->local();
|
|
|
|
|
local_logger.log_used_named_attribute(provider_->dnode, std::move(attribute_name), usage);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-26 20:00:03 +02:00
|
|
|
void GeoNodeExecParams::check_input_geometry_set(StringRef identifier,
|
|
|
|
|
const GeometrySet &geometry_set) const
|
|
|
|
|
{
|
2021-11-08 12:23:50 +01:00
|
|
|
const SocketDeclaration &decl =
|
2022-08-31 12:15:57 +02:00
|
|
|
*provider_->dnode->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();
|
|
|
|
|
const Span<GeometryComponentType> supported_types = geo_decl->supported_types();
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
const Vector<GeometryComponentType> types_in_geometry = geometry_set.gather_component_types(
|
|
|
|
|
true, true);
|
|
|
|
|
for (const GeometryComponentType type : types_in_geometry) {
|
|
|
|
|
if (type == GEO_COMPONENT_TYPE_INSTANCES) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (supported_types.contains(type)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
std::string message = TIP_("Input geometry has unsupported type: ");
|
|
|
|
|
switch (type) {
|
|
|
|
|
case GEO_COMPONENT_TYPE_MESH: {
|
|
|
|
|
message += TIP_("Mesh");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case GEO_COMPONENT_TYPE_POINT_CLOUD: {
|
|
|
|
|
message += TIP_("Point Cloud");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case GEO_COMPONENT_TYPE_INSTANCES: {
|
|
|
|
|
BLI_assert_unreachable();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case GEO_COMPONENT_TYPE_VOLUME: {
|
|
|
|
|
message += TIP_("Volume");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case GEO_COMPONENT_TYPE_CURVE: {
|
|
|
|
|
message += TIP_("Curve");
|
|
|
|
|
break;
|
|
|
|
|
}
|
2022-07-22 15:39:41 +02:00
|
|
|
case GEO_COMPONENT_TYPE_EDIT: {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
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);
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
if (const bke::CurvesEditHints *curve_edit_hints =
|
|
|
|
|
geometry_set.get_curve_edit_hints_for_read()) {
|
|
|
|
|
/* 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-08-31 12:15:57 +02:00
|
|
|
for (const bNodeSocket *socket : provider_->dnode->runtime->inputs) {
|
|
|
|
|
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-10-26 15:32:01 +02:00
|
|
|
std::string GeoNodeExecParams::attribute_producer_name() const
|
|
|
|
|
{
|
|
|
|
|
return provider_->dnode->label_or_name() + TIP_(" node");
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-26 18:00:52 +01:00
|
|
|
void GeoNodeExecParams::set_default_remaining_outputs()
|
|
|
|
|
{
|
|
|
|
|
provider_->set_default_remaining_outputs();
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-27 13:03:40 +02:00
|
|
|
void GeoNodeExecParams::check_input_access(StringRef identifier,
|
|
|
|
|
const CPPType *requested_type) const
|
2020-12-02 13:25:25 +01:00
|
|
|
{
|
2022-08-31 12:15:57 +02:00
|
|
|
const bNodeSocket *found_socket = nullptr;
|
|
|
|
|
for (const bNodeSocket *socket : provider_->dnode->input_sockets()) {
|
|
|
|
|
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-08-31 12:15:57 +02:00
|
|
|
for (const bNodeSocket *socket : provider_->dnode->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
|
|
|
}
|
2021-04-27 13:03:40 +02:00
|
|
|
else if (!provider_->can_get_input(identifier)) {
|
2020-12-02 13:25:25 +01:00
|
|
|
std::cout << "The identifier '" << identifier
|
|
|
|
|
<< "' is valid, but there is no value for it anymore.\n";
|
|
|
|
|
std::cout << "Most likely it has been extracted before.\n";
|
2021-04-27 13:03:40 +02:00
|
|
|
BLI_assert_unreachable();
|
2020-12-02 13:25:25 +01:00
|
|
|
}
|
|
|
|
|
else if (requested_type != nullptr) {
|
2021-11-22 10:18:08 +01:00
|
|
|
const CPPType &expected_type = *found_socket->typeinfo->geometry_nodes_cpp_type;
|
2020-12-02 13:25:25 +01:00
|
|
|
if (*requested_type != expected_type) {
|
|
|
|
|
std::cout << "The requested type '" << requested_type->name() << "' is incorrect. Expected '"
|
|
|
|
|
<< expected_type.name() << "'.\n";
|
2021-04-27 13:03:40 +02:00
|
|
|
BLI_assert_unreachable();
|
2020-12-02 13:25:25 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-27 13:03:40 +02:00
|
|
|
void GeoNodeExecParams::check_output_access(StringRef identifier, const CPPType &value_type) const
|
2020-12-02 13:25:25 +01:00
|
|
|
{
|
2022-08-31 12:15:57 +02:00
|
|
|
const bNodeSocket *found_socket = nullptr;
|
|
|
|
|
for (const bNodeSocket *socket : provider_->dnode->output_sockets()) {
|
|
|
|
|
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-08-31 12:15:57 +02:00
|
|
|
for (const bNodeSocket *socket : provider_->dnode->output_sockets()) {
|
|
|
|
|
if (!(socket->flag & SOCK_UNAVAIL)) {
|
|
|
|
|
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
|
|
|
}
|
2021-04-27 13:03:40 +02:00
|
|
|
else if (!provider_->can_set_output(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
|
|
|
}
|
|
|
|
|
else {
|
2021-11-22 10:18:08 +01:00
|
|
|
const CPPType &expected_type = *found_socket->typeinfo->geometry_nodes_cpp_type;
|
2020-12-02 13:25:25 +01:00
|
|
|
if (value_type != expected_type) {
|
|
|
|
|
std::cout << "The value type '" << value_type.name() << "' is incorrect. Expected '"
|
|
|
|
|
<< expected_type.name() << "'.\n";
|
2021-04-27 13:03:40 +02:00
|
|
|
BLI_assert_unreachable();
|
2020-12-02 13:25:25 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace blender::nodes
|