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>2020-12-10 01:33:09 +0300
committerHans Goudey <h.goudey@me.com>2020-12-10 01:33:09 +0300
commit0e757da3b548543ac938620d4defe177348220bd (patch)
tree3defced2aaef7fcd555a52d01df51748a766cf23
parent200cbb6adfca8f5fe55ff73650882cc0026da27b (diff)
Geometry Nodes: Add a method to find the lowest complexity attribute
For the attribute comparison node, it makes sense to read both input attributes implicitly converted to the same data type. But the choice of which of the two data types to read with is somewhat arbitrary. This commit adds a utility function to choose the least "complex" data type as a lowest common denominator, to make that choice less arbitrary , and to support other needs in the future.
-rw-r--r--source/blender/nodes/geometry/node_geometry_util.cc42
-rw-r--r--source/blender/nodes/geometry/node_geometry_util.hh5
2 files changed, 46 insertions, 1 deletions
diff --git a/source/blender/nodes/geometry/node_geometry_util.cc b/source/blender/nodes/geometry/node_geometry_util.cc
index 34c7d224f03..f9ded0e1995 100644
--- a/source/blender/nodes/geometry/node_geometry_util.cc
+++ b/source/blender/nodes/geometry/node_geometry_util.cc
@@ -36,6 +36,48 @@ void update_attribute_input_socket_availabilities(bNode &node,
}
}
+static int attribute_data_type_complexity(const CustomDataType data_type)
+{
+ switch (data_type) {
+ case CD_PROP_BOOL:
+ return 0;
+ case CD_PROP_FLOAT:
+ return 2;
+ case CD_PROP_FLOAT3:
+ return 4;
+ case CD_PROP_COLOR:
+ return 5;
+#if 0 /* Attribute types are not supported yet. */
+ case CD_PROP_INT32:
+ return 1;
+ 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_domain_lowest_complexity(Span<CustomDataType> data_types)
+{
+ int lowest_complexity = INT_MAX;
+ CustomDataType least_complex_type = CD_PROP_BOOL;
+
+ for (const CustomDataType data_type : data_types) {
+ const int complexity = attribute_data_type_complexity(data_type);
+ if (complexity < lowest_complexity) {
+ lowest_complexity = complexity;
+ least_complex_type = data_type;
+ }
+ }
+
+ return least_complex_type;
+}
+
} // namespace blender::nodes
bool geo_node_poll_default(bNodeType *UNUSED(ntype), bNodeTree *ntree)
diff --git a/source/blender/nodes/geometry/node_geometry_util.hh b/source/blender/nodes/geometry/node_geometry_util.hh
index ec389961615..b8728016230 100644
--- a/source/blender/nodes/geometry/node_geometry_util.hh
+++ b/source/blender/nodes/geometry/node_geometry_util.hh
@@ -42,4 +42,7 @@ namespace blender::nodes {
void update_attribute_input_socket_availabilities(bNode &node,
const StringRef name,
const GeometryNodeAttributeInputMode mode);
-}
+
+CustomDataType attribute_domain_lowest_complexity(Span<CustomDataType>);
+
+} // namespace blender::nodes \ No newline at end of file