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-16 21:33:13 +0300
committerHans Goudey <h.goudey@me.com>2020-12-16 21:33:13 +0300
commitc484b54453e6072399dd79daccf237bb4bd73b41 (patch)
tree71c659eee2541f55daacce87e0a3f47704dd1bbb /source/blender/nodes
parentc06c5d617a8b0e72acdeb60674172d748093bf24 (diff)
Geometry Nodes: Boolean attribute type
This adds a boolean attribute and custom data type, to be used in the point separate node. It also adds it as supported data types in the random attribute and attribute fill nodes. There are more clever ways of storing a boolean attribute that make more sense in certain situations-- sets, bitfields, and others, this commit keeps it simple, saving those changes for when there is a proper use case for them. In any case, we will still probably always want the idea of a boolean attribute. Differential Revision: https://developer.blender.org/D9818
Diffstat (limited to 'source/blender/nodes')
-rw-r--r--source/blender/nodes/NOD_geometry_exec.hh2
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_attribute_fill.cc11
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_attribute_randomize.cc15
-rw-r--r--source/blender/nodes/intern/node_tree_multi_function.cc4
4 files changed, 32 insertions, 0 deletions
diff --git a/source/blender/nodes/NOD_geometry_exec.hh b/source/blender/nodes/NOD_geometry_exec.hh
index 5fe554e0478..445e1ed6af2 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/geometry/nodes/node_geo_attribute_fill.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_fill.cc
index d3c7e86b708..5cdbd18ecc8 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_attribute_fill.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_fill.cc
@@ -27,6 +27,7 @@ static bNodeSocketTemplate geo_node_attribute_fill_in[] = {
{SOCK_VECTOR, N_("Value"), 0.0f, 0.0f, 0.0f, 0.0f, -FLT_MAX, FLT_MAX},
{SOCK_FLOAT, N_("Value"), 0.0f, 0.0f, 0.0f, 0.0f, -FLT_MAX, FLT_MAX},
{SOCK_RGBA, N_("Value"), 0.0f, 0.0f, 0.0f, 0.0f, -FLT_MAX, FLT_MAX},
+ {SOCK_BOOLEAN, N_("Value"), 0.0f, 0.0f, 0.0f, 0.0f, -FLT_MAX, FLT_MAX},
{-1, ""},
};
@@ -45,12 +46,14 @@ static void geo_node_attribute_fill_update(bNodeTree *UNUSED(ntree), bNode *node
bNodeSocket *socket_value_vector = (bNodeSocket *)BLI_findlink(&node->inputs, 2);
bNodeSocket *socket_value_float = socket_value_vector->next;
bNodeSocket *socket_value_color4f = socket_value_float->next;
+ bNodeSocket *socket_value_boolean = socket_value_color4f->next;
const CustomDataType data_type = static_cast<CustomDataType>(node->custom1);
nodeSetSocketAvailability(socket_value_vector, data_type == CD_PROP_FLOAT3);
nodeSetSocketAvailability(socket_value_float, data_type == CD_PROP_FLOAT);
nodeSetSocketAvailability(socket_value_color4f, data_type == CD_PROP_COLOR);
+ nodeSetSocketAvailability(socket_value_boolean, data_type == CD_PROP_BOOL);
}
namespace blender::nodes {
@@ -96,6 +99,14 @@ static void fill_attribute(GeometryComponent &component, const GeoNodeExecParams
color4f_attribute.apply_span();
break;
}
+ case CD_PROP_BOOL: {
+ BooleanWriteAttribute boolean_attribute = std::move(attribute);
+ const bool value = params.get_input<bool>("Value_003");
+ MutableSpan<bool> attribute_span = boolean_attribute.get_span();
+ attribute_span.fill(value);
+ boolean_attribute.apply_span();
+ break;
+ }
default:
break;
}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_randomize.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_randomize.cc
index bde9a2a695e..53df2e8c087 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_attribute_randomize.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_randomize.cc
@@ -59,6 +59,16 @@ static void geo_node_attribute_randomize_update(bNodeTree *UNUSED(ntree), bNode
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;
}
diff --git a/source/blender/nodes/intern/node_tree_multi_function.cc b/source/blender/nodes/intern/node_tree_multi_function.cc
index ec5527a2970..2e4196af156 100644
--- a/source/blender/nodes/intern/node_tree_multi_function.cc
+++ b/source/blender/nodes/intern/node_tree_multi_function.cc
@@ -208,6 +208,10 @@ 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_squared() == 0.0f; });
+ add_implicit_conversion<bool, float3>(
+ conversions, "boolean to float3", [](bool a) { return (a) ? float3(1.0f) : float3(0.0f); });
return conversions;
}