[Bf-blender-cvs] [d9b8ddd8836] geometry-nodes-point-separate-node: Geometry Nodes: Add a boolean attribute data type

Hans Goudey noreply at git.blender.org
Fri Dec 4 05:50:55 CET 2020


Commit: d9b8ddd88364203483c7282321e057edcb9b8e1e
Author: Hans Goudey
Date:   Thu Dec 3 18:23:21 2020 -0600
Branches: geometry-nodes-point-separate-node
https://developer.blender.org/rBd9b8ddd88364203483c7282321e057edcb9b8e1e

Geometry Nodes: Add a boolean attribute data type

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

M	source/blender/blenkernel/BKE_attribute_access.hh
M	source/blender/blenkernel/intern/attribute_access.cc
M	source/blender/blenkernel/intern/customdata.c
M	source/blender/makesdna/DNA_customdata_types.h
M	source/blender/nodes/NOD_geometry_exec.hh
M	source/blender/nodes/intern/node_tree_multi_function.cc

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

diff --git a/source/blender/blenkernel/BKE_attribute_access.hh b/source/blender/blenkernel/BKE_attribute_access.hh
index c4a704ef385..797187bacd7 100644
--- a/source/blender/blenkernel/BKE_attribute_access.hh
+++ b/source/blender/blenkernel/BKE_attribute_access.hh
@@ -266,9 +266,11 @@ template<typename T> class TypedWriteAttribute {
   }
 };
 
+using BooleanReadAttribute = TypedReadAttribute<bool>;
 using FloatReadAttribute = TypedReadAttribute<float>;
 using Float3ReadAttribute = TypedReadAttribute<float3>;
 using Color4fReadAttribute = TypedReadAttribute<Color4f>;
+using BooleanWriteAttribute = TypedWriteAttribute<bool>;
 using FloatWriteAttribute = TypedWriteAttribute<float>;
 using Float3WriteAttribute = TypedWriteAttribute<float3>;
 using Color4fWriteAttribute = TypedWriteAttribute<Color4f>;
diff --git a/source/blender/blenkernel/intern/attribute_access.cc b/source/blender/blenkernel/intern/attribute_access.cc
index 2edf3981c38..d899adf3f07 100644
--- a/source/blender/blenkernel/intern/attribute_access.cc
+++ b/source/blender/blenkernel/intern/attribute_access.cc
@@ -392,6 +392,8 @@ const blender::fn::CPPType *custom_data_type_to_cpp_type(const CustomDataType ty
       return &CPPType::get<int>();
     case CD_PROP_COLOR:
       return &CPPType::get<Color4f>();
+    case CD_PROP_BOOL:
+      return &CPPType::get<bool>();
     default:
       return nullptr;
   }
@@ -415,6 +417,9 @@ CustomDataType cpp_type_to_custom_data_type(const blender::fn::CPPType &type)
   if (type.is<Color4f>()) {
     return CD_PROP_COLOR;
   }
+  if (type.is<bool>()) {
+    return CD_PROP_BOOL;
+  }
   return static_cast<CustomDataType>(-1);
 }
 
@@ -449,6 +454,9 @@ static ReadAttributePtr read_attribute_from_custom_data(const CustomData &custom
         case CD_PROP_COLOR:
           return std::make_unique<ArrayReadAttribute<Color4f>>(
               domain, Span(static_cast<Color4f *>(layer.data), size));
+        case CD_PROP_BOOL:
+          return std::make_unique<ArrayReadAttribute<bool>>(
+              domain, Span(static_cast<bool *>(layer.data), size));
       }
     }
   }
@@ -490,6 +498,9 @@ static WriteAttributePtr write_attribute_from_custom_data(
         case CD_PROP_COLOR:
           return std::make_unique<ArrayWriteAttribute<Color4f>>(
               domain, MutableSpan(static_cast<Color4f *>(layer.data), size));
+        case CD_PROP_BOOL:
+          return std::make_unique<ArrayWriteAttribute<bool>>(
+              domain, MutableSpan(static_cast<bool *>(layer.data), size));
       }
     }
   }
@@ -718,6 +729,7 @@ bool PointCloudComponent::attribute_domain_with_type_supported(
     const AttributeDomain domain, const CustomDataType data_type) const
 {
   return domain == ATTR_DOMAIN_POINT && ELEM(data_type,
+                                             CD_PROP_BOOL,
                                              CD_PROP_FLOAT,
                                              CD_PROP_FLOAT2,
                                              CD_PROP_FLOAT3,
@@ -841,8 +853,13 @@ bool MeshComponent::attribute_domain_with_type_supported(const AttributeDomain d
   if (!this->attribute_domain_supported(domain)) {
     return false;
   }
-  return ELEM(
-      data_type, CD_PROP_FLOAT, CD_PROP_FLOAT2, CD_PROP_FLOAT3, CD_PROP_INT32, CD_PROP_COLOR);
+  return ELEM(data_type,
+              CD_PROP_BOOL,
+              CD_PROP_FLOAT,
+              CD_PROP_FLOAT2,
+              CD_PROP_FLOAT3,
+              CD_PROP_INT32,
+              CD_PROP_COLOR);
 }
 
 int MeshComponent::attribute_domain_size(const AttributeDomain domain) const
diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c
index fdb3e246382..1e2bc570c65 100644
--- a/source/blender/blenkernel/intern/customdata.c
+++ b/source/blender/blenkernel/intern/customdata.c
@@ -1837,6 +1837,21 @@ static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = {
      layerMultiply_propfloat2,
      NULL,
      layerAdd_propfloat2},
+    /* 50: CD_PROP_POOL */
+    {sizeof(bool),
+     "bool",
+     1,
+     N_("Boolean"),
+     NULL,
+     NULL,
+     NULL,
+     NULL,
+     NULL,
+     NULL,
+     NULL,
+     NULL,
+     NULL,
+     NULL},
 };
 
 static const char *LAYERTYPENAMES[CD_NUMTYPES] = {
@@ -1892,6 +1907,7 @@ static const char *LAYERTYPENAMES[CD_NUMTYPES] = {
     "CDPropCol",
     "CDPropFloat3",
     "CDPropFloat2",
+    "CDPropBoolean",
 };
 
 const CustomData_MeshMasks CD_MASK_BAREMESH = {
diff --git a/source/blender/makesdna/DNA_customdata_types.h b/source/blender/makesdna/DNA_customdata_types.h
index ae0bb20e529..832d55ea151 100644
--- a/source/blender/makesdna/DNA_customdata_types.h
+++ b/source/blender/makesdna/DNA_customdata_types.h
@@ -75,8 +75,7 @@ typedef struct CustomData {
    * MUST be >= CD_NUMTYPES, but we cant use a define here.
    * Correct size is ensured in CustomData_update_typemap assert().
    */
-  int typemap[50];
-  char _pad[4];
+  int typemap[51];
   /** Number of layers, size of layers array. */
   int totlayer, maxlayer;
   /** In editmode, total size of all data layers. */
@@ -156,7 +155,9 @@ typedef enum CustomDataType {
   CD_PROP_FLOAT3 = 48,
   CD_PROP_FLOAT2 = 49,
 
-  CD_NUMTYPES = 50,
+  CD_PROP_BOOL = 50,
+
+  CD_NUMTYPES = 51,
 } CustomDataType;
 
 /* Bits for CustomDataMask */
@@ -208,6 +209,7 @@ typedef enum CustomDataType {
 #define CD_MASK_PROP_COLOR (1ULL << CD_PROP_COLOR)
 #define CD_MASK_PROP_FLOAT3 (1ULL << CD_PROP_FLOAT3)
 #define CD_MASK_PROP_FLOAT2 (1ULL << CD_PROP_FLOAT2)
+#define CD_MASK_PROP_BOOL (1ULL << CD_PROP_BOOL)
 
 /** Multires loop data. */
 #define CD_MASK_MULTIRES_GRIDS (CD_MASK_MDISPS | CD_GRID_PAINT_MASK)
diff --git a/source/blender/nodes/NOD_geometry_exec.hh b/source/blender/nodes/NOD_geometry_exec.hh
index fde576d7429..cddd99e0d21 100644
--- a/source/blender/nodes/NOD_geometry_exec.hh
+++ b/source/blender/nodes/NOD_geometry_exec.hh
@@ -26,6 +26,8 @@
 
 namespace blender::nodes {
 
+using bke::BooleanReadAttribute;
+using bke::BooleanWriteAttribute;
 using bke::Color4fReadAttribute;
 using bke::Color4fWriteAttribute;
 using bke::Float3ReadAttribute;
diff --git a/source/blender/nodes/intern/node_tree_multi_function.cc b/source/blender/nodes/intern/node_tree_multi_function.cc
index ec5527a2970..8b55e8f96b9 100644
--- a/source/blender/nodes/intern/node_tree_multi_function.cc
+++ b/source/blender/nodes/intern/node_tree_multi_function.cc
@@ -208,6 +208,8 @@ static DataTypeConversions create_implicit_conversions()
       conversions, "float to Color4f", [](float a) { return Color4f(a, a, a, 1.0f); });
   add_implicit_conversion<Color4f, float>(
       conversions, "Color4f to float", [](Color4f a) { return rgb_to_grayscale(a); });
+  add_implicit_conversion<float3, bool>(
+      conversions, "float3 to boolean", [](float3 a) { return a.length() == 0.0f; });
   return conversions;
 }



More information about the Bf-blender-cvs mailing list