[Bf-blender-cvs] [0e757da3b54] geometry-nodes-point-separate-node: Geometry Nodes: Add a method to find the lowest complexity attribute

Hans Goudey noreply at git.blender.org
Wed Dec 9 23:42:32 CET 2020


Commit: 0e757da3b548543ac938620d4defe177348220bd
Author: Hans Goudey
Date:   Wed Dec 9 16:33:09 2020 -0600
Branches: geometry-nodes-point-separate-node
https://developer.blender.org/rB0e757da3b548543ac938620d4defe177348220bd

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.

===================================================================

M	source/blender/nodes/geometry/node_geometry_util.cc
M	source/blender/nodes/geometry/node_geometry_util.hh

===================================================================

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



More information about the Bf-blender-cvs mailing list