[Bf-blender-cvs] [6505f9c09ae] geometry-nodes-point-separate-node: Geometry Nodes: Add boolean type to random attribute node

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


Commit: 6505f9c09ae8cd88d67dc4e946bd5ade66af7387
Author: Hans Goudey
Date:   Thu Dec 3 18:27:20 2020 -0600
Branches: geometry-nodes-point-separate-node
https://developer.blender.org/rB6505f9c09ae8cd88d67dc4e946bd5ade66af7387

Geometry Nodes: Add boolean type to random attribute node

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

M	source/blender/makesrna/intern/rna_attribute.c
M	source/blender/makesrna/intern/rna_nodetree.c
M	source/blender/nodes/geometry/nodes/node_geo_random_attribute.cc

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

diff --git a/source/blender/makesrna/intern/rna_attribute.c b/source/blender/makesrna/intern/rna_attribute.c
index ad615026343..c8be4344be0 100644
--- a/source/blender/makesrna/intern/rna_attribute.c
+++ b/source/blender/makesrna/intern/rna_attribute.c
@@ -44,6 +44,7 @@ const EnumPropertyItem rna_enum_attribute_type_items[] = {
     {CD_PROP_COLOR, "FLOAT_COLOR", 0, "Float Color", "RGBA color with floating point precisions"},
     {CD_MLOOPCOL, "BYTE_COLOR", 0, "Byte Color", "RGBA color with 8-bit precision"},
     {CD_PROP_STRING, "STRING", 0, "String", "Text string"},
+    {CD_PROP_BOOL, "BOOLEAN", 0, "Boolean", "True or false"},
     {0, NULL, 0, NULL, NULL},
 };
 
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index 99ae1b85e0c..9ac25da1252 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -1859,7 +1859,7 @@ static const EnumPropertyItem *itemf_function_check(
 
 static bool attribute_random_type_supported(const EnumPropertyItem *item)
 {
-  return ELEM(item->value, CD_PROP_FLOAT, CD_PROP_FLOAT3);
+  return ELEM(item->value, CD_PROP_FLOAT, CD_PROP_FLOAT3, CD_PROP_BOOL);
 }
 static const EnumPropertyItem *rna_GeometryNodeAttributeRandom_type_itemf(
     bContext *UNUSED(C), PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free)
diff --git a/source/blender/nodes/geometry/nodes/node_geo_random_attribute.cc b/source/blender/nodes/geometry/nodes/node_geo_random_attribute.cc
index 5cacb96412c..5574a570feb 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_random_attribute.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_random_attribute.cc
@@ -59,6 +59,16 @@ static void geo_node_random_attribute_update(bNodeTree *UNUSED(ntree), bNode *no
 
 namespace blender::nodes {
 
+static void randomize_attribute(BooleanWriteAttribute &attribute, RandomNumberGenerator &rng)
+{
+  MutableSpan<bool> attribute_span = attribute.get_span();
+  for (const int i : IndexRange(attribute.size())) {
+    const bool value = rng.get_float() > 0.5f;
+    attribute_span[i] = value;
+  }
+  attribute.apply_span();
+}
+
 static void randomize_attribute(FloatWriteAttribute &attribute,
                                 float min,
                                 float max,
@@ -121,6 +131,11 @@ static void randomize_attribute(GeometryComponent &component,
       randomize_attribute(float3_attribute, min_value, max_value, rng);
       break;
     }
+    case CD_PROP_BOOL: {
+      BooleanWriteAttribute boolean_attribute = std::move(attribute);
+      randomize_attribute(boolean_attribute, rng);
+      break;
+    }
     default:
       break;
   }



More information about the Bf-blender-cvs mailing list