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:
authorHans Goudey <h.goudey@me.com>2021-02-12 21:46:17 +0300
committerHans Goudey <h.goudey@me.com>2021-02-12 21:46:17 +0300
commitd7c2c889a688067dab280fc137ad4c3c7ce4cb2b (patch)
treee7fbfd4e400c3e8eb939946a9ef053a7b0abe545 /source/blender/nodes/intern
parentba03f7f0b1d0c40acf997749949a0b0efe19e6d0 (diff)
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
Diffstat (limited to 'source/blender/nodes/intern')
-rw-r--r--source/blender/nodes/intern/node_geometry_exec.cc36
1 files changed, 36 insertions, 0 deletions
diff --git a/source/blender/nodes/intern/node_geometry_exec.cc b/source/blender/nodes/intern/node_geometry_exec.cc
index eef2c6c9125..6ddeb73e31f 100644
--- a/source/blender/nodes/intern/node_geometry_exec.cc
+++ b/source/blender/nodes/intern/node_geometry_exec.cc
@@ -17,6 +17,8 @@
#include "NOD_geometry_exec.hh"
#include "NOD_type_callbacks.hh"
+#include "node_geometry_util.hh"
+
namespace blender::nodes {
const bNodeSocket *GeoNodeExecParams::find_available_socket(const StringRef name) const
@@ -104,6 +106,40 @@ CustomDataType GeoNodeExecParams::get_input_attribute_data_type(
return default_type;
}
+/**
+ * If any of the corresponding input sockets are attributes instead of single values,
+ * use the highest priority attribute domain from among them.
+ * Otherwise return the default domain.
+ */
+AttributeDomain GeoNodeExecParams::get_highest_priority_input_domain(
+ Span<std::string> names,
+ const GeometryComponent &component,
+ const AttributeDomain default_domain) const
+{
+ Vector<AttributeDomain, 8> input_domains;
+ for (const std::string &name : names) {
+ const bNodeSocket *found_socket = this->find_available_socket(name);
+ BLI_assert(found_socket != nullptr); /* A socket should be available socket for the name. */
+ if (found_socket == nullptr) {
+ continue;
+ }
+
+ if (found_socket->type == SOCK_STRING) {
+ const std::string name = this->get_input<std::string>(found_socket->identifier);
+ ReadAttributePtr attribute = component.attribute_try_get_for_read(name);
+ if (attribute) {
+ input_domains.append(attribute->domain());
+ }
+ }
+ }
+
+ if (input_domains.size() > 0) {
+ return attribute_domain_highest_priority(input_domains);
+ }
+
+ return default_domain;
+}
+
void GeoNodeExecParams::check_extract_input(StringRef identifier,
const CPPType *requested_type) const
{