Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2022-04-14 17:31:09 +0300
committerJacques Lucke <jacques@blender.org>2022-04-14 17:31:09 +0300
commitc71013082d096968d33ba977a0fdbcfbfb0690d1 (patch)
treedf09bab6e0405ab79779fe74a21991381ed137e6 /source/blender/nodes
parenta9b94e5f81ced89381033fd8d13ef6e3489e2665 (diff)
Geometry Nodes: show used named attributes in nodes
This adds a new node editor overlay that helps users to see where named attributes are used. This is important, because named attributes can have name collisions between independent node groups which can lead to hard to find issues. Differential Revision: https://developer.blender.org/D14618
Diffstat (limited to 'source/blender/nodes')
-rw-r--r--source/blender/nodes/NOD_geometry_exec.hh3
-rw-r--r--source/blender/nodes/NOD_geometry_nodes_eval_log.hh26
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_input_named_attribute.cc4
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_remove_attribute.cc2
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_store_named_attribute.cc4
-rw-r--r--source/blender/nodes/intern/geometry_nodes_eval_log.cc14
-rw-r--r--source/blender/nodes/intern/node_geometry_exec.cc10
7 files changed, 61 insertions, 2 deletions
diff --git a/source/blender/nodes/NOD_geometry_exec.hh b/source/blender/nodes/NOD_geometry_exec.hh
index 96a1904abdd..bac4d0165e9 100644
--- a/source/blender/nodes/NOD_geometry_exec.hh
+++ b/source/blender/nodes/NOD_geometry_exec.hh
@@ -40,6 +40,7 @@ using fn::FieldInput;
using fn::FieldOperation;
using fn::GField;
using fn::ValueOrField;
+using geometry_nodes_eval_log::NamedAttributeUsage;
using geometry_nodes_eval_log::NodeWarningType;
/**
@@ -342,6 +343,8 @@ class GeoNodeExecParams {
void set_default_remaining_outputs();
+ void used_named_attribute(std::string attribute_name, NamedAttributeUsage usage);
+
private:
/* Utilities for detecting common errors at when using this class. */
void check_input_access(StringRef identifier, const CPPType *requested_type = nullptr) const;
diff --git a/source/blender/nodes/NOD_geometry_nodes_eval_log.hh b/source/blender/nodes/NOD_geometry_nodes_eval_log.hh
index 16332be5179..1ad859aa47b 100644
--- a/source/blender/nodes/NOD_geometry_nodes_eval_log.hh
+++ b/source/blender/nodes/NOD_geometry_nodes_eval_log.hh
@@ -170,6 +170,24 @@ struct ValueOfSockets {
destruct_ptr<ValueLog> value;
};
+enum class NamedAttributeUsage {
+ None = 0,
+ Read = 1 << 0,
+ Write = 1 << 1,
+ Remove = 1 << 2,
+};
+ENUM_OPERATORS(NamedAttributeUsage, NamedAttributeUsage::Remove);
+
+struct UsedNamedAttribute {
+ std::string name;
+ NamedAttributeUsage usage;
+};
+
+struct NodeWithUsedNamedAttribute {
+ DNode node;
+ UsedNamedAttribute attribute;
+};
+
class GeoLogger;
class ModifierLog;
@@ -186,6 +204,7 @@ class LocalGeoLogger {
Vector<NodeWithWarning> node_warnings_;
Vector<NodeWithExecutionTime> node_exec_times_;
Vector<NodeWithDebugMessage> node_debug_messages_;
+ Vector<NodeWithUsedNamedAttribute> used_named_attributes_;
friend ModifierLog;
@@ -199,6 +218,7 @@ class LocalGeoLogger {
void log_multi_value_socket(DSocket socket, Span<GPointer> values);
void log_node_warning(DNode node, NodeWarningType type, std::string message);
void log_execution_time(DNode node, std::chrono::microseconds exec_time);
+ void log_used_named_attribute(DNode node, std::string attribute_name, NamedAttributeUsage usage);
/**
* Log a message that will be displayed in the node editor next to the node.
* This should only be used for debugging purposes and not to display information to users.
@@ -278,6 +298,7 @@ class NodeLog {
Vector<SocketLog> output_logs_;
Vector<NodeWarning, 0> warnings_;
Vector<std::string, 0> debug_messages_;
+ Vector<UsedNamedAttribute, 0> used_named_attributes_;
std::chrono::microseconds exec_time_;
friend ModifierLog;
@@ -307,6 +328,11 @@ class NodeLog {
return debug_messages_;
}
+ Span<UsedNamedAttribute> used_named_attributes() const
+ {
+ return used_named_attributes_;
+ }
+
std::chrono::microseconds execution_time() const
{
return exec_time_;
diff --git a/source/blender/nodes/geometry/nodes/node_geo_input_named_attribute.cc b/source/blender/nodes/geometry/nodes/node_geo_input_named_attribute.cc
index f6e2be9119c..6cb9ca642ef 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_input_named_attribute.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_input_named_attribute.cc
@@ -81,11 +81,13 @@ static void node_geo_exec(GeoNodeExecParams params)
const std::string name = params.extract_input<std::string>("Name");
- if (!U.experimental.use_named_attribute_nodes) {
+ if (!U.experimental.use_named_attribute_nodes || name.empty()) {
params.set_default_remaining_outputs();
return;
}
+ params.used_named_attribute(name, NamedAttributeUsage::Read);
+
switch (data_type) {
case CD_PROP_FLOAT:
params.set_output("Attribute_Float", AttributeFieldInput::Create<float>(std::move(name)));
diff --git a/source/blender/nodes/geometry/nodes/node_geo_remove_attribute.cc b/source/blender/nodes/geometry/nodes/node_geo_remove_attribute.cc
index 202241affeb..f46b70c91a9 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_remove_attribute.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_remove_attribute.cc
@@ -32,6 +32,8 @@ static void node_geo_exec(GeoNodeExecParams params)
return;
}
+ params.used_named_attribute(name, NamedAttributeUsage::Remove);
+
std::atomic<bool> attribute_exists = false;
std::atomic<bool> cannot_delete = false;
diff --git a/source/blender/nodes/geometry/nodes/node_geo_store_named_attribute.cc b/source/blender/nodes/geometry/nodes/node_geo_store_named_attribute.cc
index 1d1446ce1bd..92614d1a31d 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_store_named_attribute.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_store_named_attribute.cc
@@ -127,11 +127,13 @@ static void node_geo_exec(GeoNodeExecParams params)
GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry");
std::string name = params.extract_input<std::string>("Name");
- if (!U.experimental.use_named_attribute_nodes) {
+ if (!U.experimental.use_named_attribute_nodes || name.empty()) {
params.set_output("Geometry", std::move(geometry_set));
return;
}
+ params.used_named_attribute(name, NamedAttributeUsage::Write);
+
const NodeGeometryStoreNamedAttribute &storage = node_storage(params.node());
const CustomDataType data_type = static_cast<CustomDataType>(storage.data_type);
const AttributeDomain domain = static_cast<AttributeDomain>(storage.domain);
diff --git a/source/blender/nodes/intern/geometry_nodes_eval_log.cc b/source/blender/nodes/intern/geometry_nodes_eval_log.cc
index 13f38c3352e..378bac894e8 100644
--- a/source/blender/nodes/intern/geometry_nodes_eval_log.cc
+++ b/source/blender/nodes/intern/geometry_nodes_eval_log.cc
@@ -62,6 +62,13 @@ ModifierLog::ModifierLog(GeoLogger &logger)
NodeLog &node_log = this->lookup_or_add_node_log(log_by_tree_context, debug_message.node);
node_log.debug_messages_.append(debug_message.message);
}
+
+ for (NodeWithUsedNamedAttribute &node_with_attribute_name :
+ local_logger.used_named_attributes_) {
+ NodeLog &node_log = this->lookup_or_add_node_log(log_by_tree_context,
+ node_with_attribute_name.node);
+ node_log.used_named_attributes_.append(std::move(node_with_attribute_name.attribute));
+ }
}
}
@@ -486,6 +493,13 @@ void LocalGeoLogger::log_execution_time(DNode node, std::chrono::microseconds ex
node_exec_times_.append({node, exec_time});
}
+void LocalGeoLogger::log_used_named_attribute(DNode node,
+ std::string attribute_name,
+ NamedAttributeUsage usage)
+{
+ used_named_attributes_.append({node, {std::move(attribute_name), usage}});
+}
+
void LocalGeoLogger::log_debug_message(DNode node, std::string message)
{
node_debug_messages_.append({node, std::move(message)});
diff --git a/source/blender/nodes/intern/node_geometry_exec.cc b/source/blender/nodes/intern/node_geometry_exec.cc
index d63a6d11eda..cea3084a418 100644
--- a/source/blender/nodes/intern/node_geometry_exec.cc
+++ b/source/blender/nodes/intern/node_geometry_exec.cc
@@ -23,6 +23,16 @@ void GeoNodeExecParams::error_message_add(const NodeWarningType type, std::strin
local_logger.log_node_warning(provider_->dnode, type, std::move(message));
}
+void GeoNodeExecParams::used_named_attribute(std::string attribute_name,
+ const NamedAttributeUsage usage)
+{
+ if (provider_->logger == nullptr) {
+ return;
+ }
+ LocalGeoLogger &local_logger = provider_->logger->local();
+ local_logger.log_used_named_attribute(provider_->dnode, std::move(attribute_name), usage);
+}
+
void GeoNodeExecParams::check_input_geometry_set(StringRef identifier,
const GeometrySet &geometry_set) const
{