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>2021-02-16 13:55:00 +0300
committerJacques Lucke <jacques@blender.org>2021-02-16 13:55:12 +0300
commit39f60e6909e61b8b7982e637a2091a84d618ddd7 (patch)
tree7a3c044f1bad7bfda338d1b21e3cd4d8f3474079 /source/blender/blenkernel/intern/attribute_access.cc
parentc03650073e60194500e13dc996168c4930970f5b (diff)
Geometry Nodes: move some attribute utilities to blenkernel
I need to access these utilities from modifier code as well. Therefore, they should not live in the nodes module.
Diffstat (limited to 'source/blender/blenkernel/intern/attribute_access.cc')
-rw-r--r--source/blender/blenkernel/intern/attribute_access.cc90
1 files changed, 90 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/attribute_access.cc b/source/blender/blenkernel/intern/attribute_access.cc
index 17f8b5ba2b3..f594ec54a7e 100644
--- a/source/blender/blenkernel/intern/attribute_access.cc
+++ b/source/blender/blenkernel/intern/attribute_access.cc
@@ -508,6 +508,96 @@ CustomDataType cpp_type_to_custom_data_type(const blender::fn::CPPType &type)
return static_cast<CustomDataType>(-1);
}
+static int attribute_data_type_complexity(const CustomDataType data_type)
+{
+ switch (data_type) {
+ case CD_PROP_BOOL:
+ return 0;
+ case CD_PROP_INT32:
+ return 1;
+ case CD_PROP_FLOAT:
+ return 2;
+ case CD_PROP_FLOAT2:
+ return 3;
+ case CD_PROP_FLOAT3:
+ return 4;
+ case CD_PROP_COLOR:
+ return 5;
+#if 0 /* These attribute types are not supported yet. */
+ case CD_MLOOPCOL:
+ return 3;
+ case CD_PROP_STRING:
+ return 6;
+#endif
+ default:
+ /* Only accept "generic" custom data types used by the attribute system. */
+ BLI_assert(false);
+ return 0;
+ }
+}
+
+CustomDataType attribute_data_type_highest_complexity(Span<CustomDataType> data_types)
+{
+ int highest_complexity = INT_MIN;
+ CustomDataType most_complex_type = CD_PROP_COLOR;
+
+ for (const CustomDataType data_type : data_types) {
+ const int complexity = attribute_data_type_complexity(data_type);
+ if (complexity > highest_complexity) {
+ highest_complexity = complexity;
+ most_complex_type = data_type;
+ }
+ }
+
+ return most_complex_type;
+}
+
+/**
+ * \note Generally the order should mirror the order of the domains
+ * established in each component's ComponentAttributeProviders.
+ */
+static int attribute_domain_priority(const AttributeDomain domain)
+{
+ switch (domain) {
+#if 0
+ case ATTR_DOMAIN_CURVE:
+ return 0;
+#endif
+ case ATTR_DOMAIN_POLYGON:
+ return 1;
+ case ATTR_DOMAIN_EDGE:
+ return 2;
+ case ATTR_DOMAIN_POINT:
+ return 3;
+ case ATTR_DOMAIN_CORNER:
+ return 4;
+ default:
+ /* Domain not supported in nodes yet. */
+ BLI_assert(false);
+ return 0;
+ }
+}
+
+/**
+ * Domains with a higher "information density" have a higher priority, in order
+ * to choose a domain that will not lose data through domain conversion.
+ */
+AttributeDomain attribute_domain_highest_priority(Span<AttributeDomain> domains)
+{
+ int highest_priority = INT_MIN;
+ AttributeDomain highest_priority_domain = ATTR_DOMAIN_CORNER;
+
+ for (const AttributeDomain domain : domains) {
+ const int priority = attribute_domain_priority(domain);
+ if (priority > highest_priority) {
+ highest_priority = priority;
+ highest_priority_domain = domain;
+ }
+ }
+
+ return highest_priority_domain;
+}
+
/**
* A #BuiltinAttributeProvider is responsible for exactly one attribute on a geometry component.
* The attribute is identified by its name and has a fixed domain and type. Builtin attributes do