[Bf-blender-cvs] [45264883075] temp-geometry-nodes-mix-attributes: support changing factor type
Jacques Lucke
noreply at git.blender.org
Wed Dec 9 15:03:30 CET 2020
Commit: 4526488307535b0d9a2a7a575f63a9fcfd77ba51
Author: Jacques Lucke
Date: Wed Dec 9 13:15:53 2020 +0100
Branches: temp-geometry-nodes-mix-attributes
https://developer.blender.org/rB4526488307535b0d9a2a7a575f63a9fcfd77ba51
support changing factor type
===================================================================
M source/blender/editors/space_node/drawnode.c
M source/blender/makesrna/intern/rna_nodetree.c
M source/blender/nodes/geometry/nodes/node_geo_attribute_mix.cc
===================================================================
diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c
index f9ef1f356f3..65b084faff9 100644
--- a/source/blender/editors/space_node/drawnode.c
+++ b/source/blender/editors/space_node/drawnode.c
@@ -3187,6 +3187,7 @@ static void node_geometry_buts_attribute_mix(uiLayout *layout,
PointerRNA *ptr)
{
uiItemR(layout, ptr, "blend_type", DEFAULT_FLAGS, "", ICON_NONE);
+ uiItemR(layout, ptr, "input_type_factor", DEFAULT_FLAGS, "Factor", ICON_NONE);
}
static void node_geometry_set_butfunc(bNodeType *ntype)
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index c435c40e7a6..9cf96c28960 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -435,6 +435,14 @@ static const EnumPropertyItem rna_node_geometry_attribute_input_b_items[] = {
{0, NULL, 0, NULL, NULL},
};
+static const EnumPropertyItem rna_node_geometry_attribute_input_type_items[] = {
+ {GEO_NODE_ATTRIBUTE_INPUT__ATTRIBUTE, "ATTRIBUTE", 0, "Attribute", ""},
+ {GEO_NODE_ATTRIBUTE_INPUT__CONSTANT_FLOAT, "FLOAT", 0, "Float", ""},
+ {GEO_NODE_ATTRIBUTE_INPUT__CONSTANT_VECTOR, "VECTOR", 0, "Vector", ""},
+ {GEO_NODE_ATTRIBUTE_INPUT__CONSTANT_COLOR, "COLOR", 0, "Color", ""},
+ {0, NULL, 0, NULL, NULL},
+};
+
#endif
#ifdef RNA_RUNTIME
@@ -8379,6 +8387,11 @@ static void def_geo_attribute_mix(StructRNA *srna)
RNA_def_property_enum_default(prop, MA_RAMP_BLEND);
RNA_def_property_ui_text(prop, "Blending Mode", "");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
+
+ prop = RNA_def_property(srna, "input_type_factor", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_items(prop, rna_node_geometry_attribute_input_type_items);
+ RNA_def_property_ui_text(prop, "Input Type Factor", "");
+ RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update");
}
/* -------------------------------------------------------------------------- */
diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_mix.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_mix.cc
index 955ada7d83d..33c4e9ef8e7 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_attribute_mix.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_mix.cc
@@ -21,7 +21,11 @@
static bNodeSocketTemplate geo_node_attribute_mix_in[] = {
{SOCK_GEOMETRY, N_("Geometry")},
{SOCK_STRING, N_("Factor")},
+ {SOCK_FLOAT, N_("Factor"), 0.5, 0.0, 0.0, 0.0, 0.0, 1.0, PROP_FACTOR},
{SOCK_STRING, N_("Attribute A")},
+ {SOCK_FLOAT, N_("Attribute A"), 0.0, 0.0, 0.0, 0.0, -FLT_MAX, FLT_MAX},
+ {SOCK_VECTOR, N_("Attribute A"), 0.0, 0.0, 0.0, 0.0, -FLT_MAX, FLT_MAX},
+ {SOCK_RGBA, N_("Attribute A"), 0.5, 0.5, 0.5, 1.0},
{SOCK_STRING, N_("Attribute B")},
{SOCK_STRING, N_("Result")},
{-1, ""},
@@ -86,9 +90,8 @@ static void do_mix_operation_color4f(const int blend_mode,
static void attribute_mix_calc(GeometryComponent &component, const GeoNodeExecParams ¶ms)
{
const bNode &node = params.node();
- const int blend_mode = node.custom1;
+ const NodeAttributeMix *node_storage = (const NodeAttributeMix *)node.storage;
- const std::string factor_name = params.get_input<std::string>("Factor");
const std::string attribute_a_name = params.get_input<std::string>("Attribute A");
const std::string attribute_b_name = params.get_input<std::string>("Attribute B");
const std::string result_name = params.get_input<std::string>("Result");
@@ -109,8 +112,15 @@ static void attribute_mix_calc(GeometryComponent &component, const GeoNodeExecPa
return;
}
- FloatReadAttribute attribute_factor = component.attribute_get_for_read<float>(
- factor_name, result_domain, 0.5f);
+ FloatReadAttribute attribute_factor = [&]() {
+ if (node_storage->input_type_factor == GEO_NODE_ATTRIBUTE_INPUT__ATTRIBUTE) {
+ const std::string factor_name = params.get_input<std::string>("Factor");
+ return component.attribute_get_for_read<float>(factor_name, result_domain, 0.5f);
+ }
+ const float factor = params.get_input<float>("Factor_001");
+ return component.attribute_get_constant_for_read(result_domain, factor);
+ }();
+
ReadAttributePtr attribute_a = component.attribute_get_for_read(
attribute_a_name, result_domain, result_type, nullptr);
ReadAttributePtr attribute_b = component.attribute_get_for_read(
@@ -120,7 +130,7 @@ static void attribute_mix_calc(GeometryComponent &component, const GeoNodeExecPa
FloatReadAttribute attribute_a_float = std::move(attribute_a);
FloatReadAttribute attribute_b_float = std::move(attribute_b);
FloatWriteAttribute attribute_result_float = std::move(attribute_result);
- do_mix_operation_float(blend_mode,
+ do_mix_operation_float(node_storage->blend_type,
attribute_factor,
attribute_a_float,
attribute_b_float,
@@ -130,7 +140,7 @@ static void attribute_mix_calc(GeometryComponent &component, const GeoNodeExecPa
Float3ReadAttribute attribute_a_float3 = std::move(attribute_a);
Float3ReadAttribute attribute_b_float3 = std::move(attribute_b);
Float3WriteAttribute attribute_result_float3 = std::move(attribute_result);
- do_mix_operation_float3(blend_mode,
+ do_mix_operation_float3(node_storage->blend_type,
attribute_factor,
attribute_a_float3,
attribute_b_float3,
@@ -140,7 +150,7 @@ static void attribute_mix_calc(GeometryComponent &component, const GeoNodeExecPa
Color4fReadAttribute attribute_a_color4f = std::move(attribute_a);
Color4fReadAttribute attribute_b_color4f = std::move(attribute_b);
Color4fWriteAttribute attribute_result_color4f = std::move(attribute_result);
- do_mix_operation_color4f(blend_mode,
+ do_mix_operation_color4f(node_storage->blend_type,
attribute_factor,
attribute_a_color4f,
attribute_b_color4f,
@@ -173,6 +183,30 @@ static void geo_node_attribute_mix_init(bNodeTree *UNUSED(ntree), bNode *node)
node->storage = data;
}
+static void update_attribute_input_socket_availabilities(bNode &node,
+ const char *prefix,
+ const uint8_t mode)
+{
+ const GeometryNodeAttributeInputMode mode_ = (GeometryNodeAttributeInputMode)mode;
+ LISTBASE_FOREACH (bNodeSocket *, socket, &node.inputs) {
+ if (BLI_str_startswith(socket->name, prefix)) {
+ const bool is_available =
+ ((socket->type == SOCK_STRING && mode_ == GEO_NODE_ATTRIBUTE_INPUT__ATTRIBUTE) ||
+ (socket->type == SOCK_FLOAT && mode_ == GEO_NODE_ATTRIBUTE_INPUT__CONSTANT_FLOAT) ||
+ (socket->type == SOCK_VECTOR && mode_ == GEO_NODE_ATTRIBUTE_INPUT__CONSTANT_VECTOR) ||
+ (socket->type == SOCK_RGBA && mode_ == GEO_NODE_ATTRIBUTE_INPUT__CONSTANT_COLOR));
+ nodeSetSocketAvailability(socket, is_available);
+ }
+ }
+}
+
+static void geo_node_attribute_mix_update(bNodeTree *UNUSED(ntree), bNode *node)
+{
+ NodeAttributeMix *node_storage = (NodeAttributeMix *)node->storage;
+ update_attribute_input_socket_availabilities(*node, "Factor", node_storage->input_type_factor);
+ update_attribute_input_socket_availabilities(*node, "Attribute A", node_storage->input_type_a);
+}
+
} // namespace blender::nodes
void register_node_type_geo_attribute_mix()
@@ -182,6 +216,7 @@ void register_node_type_geo_attribute_mix()
geo_node_type_base(&ntype, GEO_NODE_ATTRIBUTE_MIX, "Attribute Mix", NODE_CLASS_ATTRIBUTE, 0);
node_type_socket_templates(&ntype, geo_node_attribute_mix_in, geo_node_mix_attribute_out);
node_type_init(&ntype, blender::nodes::geo_node_attribute_mix_init);
+ node_type_update(&ntype, blender::nodes::geo_node_attribute_mix_update);
node_type_storage(
&ntype, "NodeAttributeMix", node_free_standard_storage, node_copy_standard_storage);
ntype.geometry_node_execute = blender::nodes::geo_node_attribute_mix_exec;
More information about the Bf-blender-cvs
mailing list