From 43455f385709ede032de0c39792bad422be87a92 Mon Sep 17 00:00:00 2001 From: Charlie Jolly Date: Fri, 26 Mar 2021 09:28:15 +0000 Subject: Geometry Nodes: Add Attribute Clamp Node This adds a Clamp node for Geometry Nodes Attributes. Supports both Min-Max and Range clamp modes. Float, Vector, Color and Int data types supported. Reviewed By: HooglyBoogly, simonthommes Differential Revision: https://developer.blender.org/D10526 --- source/blender/makesrna/intern/rna_nodetree.c | 41 +++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) (limited to 'source/blender/makesrna') diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c index 7f2120c02e9..b697d872cf3 100644 --- a/source/blender/makesrna/intern/rna_nodetree.c +++ b/source/blender/makesrna/intern/rna_nodetree.c @@ -329,8 +329,12 @@ const EnumPropertyItem rna_enum_node_map_range_items[] = { }; const EnumPropertyItem rna_enum_node_clamp_items[] = { - {NODE_CLAMP_MINMAX, "MINMAX", 0, "Min Max", "Clamp values using Min and Max values"}, - {NODE_CLAMP_RANGE, "RANGE", 0, "Range", "Clamp values between Min and Max range"}, + {NODE_CLAMP_MINMAX, "MINMAX", 0, "Min Max", "Constrain value between min and max"}, + {NODE_CLAMP_RANGE, + "RANGE", + 0, + "Range", + "Constrain value between min and max, swapping arguments when min > max"}, {0, NULL, 0, NULL, NULL}, }; @@ -1886,6 +1890,19 @@ static const EnumPropertyItem *itemf_function_check( return item_array; } +static bool attribute_clamp_type_supported(const EnumPropertyItem *item) +{ + return ELEM(item->value, CD_PROP_FLOAT, CD_PROP_FLOAT3, CD_PROP_INT32, CD_PROP_COLOR); +} +static const EnumPropertyItem *rna_GeometryNodeAttributeClamp_type_itemf(bContext *UNUSED(C), + PointerRNA *UNUSED(ptr), + PropertyRNA *UNUSED(prop), + bool *r_free) +{ + *r_free = true; + return itemf_function_check(rna_enum_attribute_type_items, attribute_clamp_type_supported); +} + static bool attribute_random_type_supported(const EnumPropertyItem *item) { return ELEM(item->value, CD_PROP_FLOAT, CD_PROP_FLOAT3, CD_PROP_BOOL, CD_PROP_INT32); @@ -9006,6 +9023,26 @@ static void def_geo_attribute_mix(StructRNA *srna) RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update"); } +static void def_geo_attribute_clamp(StructRNA *srna) +{ + PropertyRNA *prop; + + RNA_def_struct_sdna_from(srna, "NodeAttributeClamp", "storage"); + + prop = RNA_def_property(srna, "data_type", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_bitflag_sdna(prop, NULL, "data_type"); + RNA_def_property_enum_items(prop, rna_enum_attribute_type_items); + RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_GeometryNodeAttributeClamp_type_itemf"); + RNA_def_property_ui_text(prop, "Data Type", ""); + RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update"); + + prop = RNA_def_property(srna, "operation", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_items(prop, rna_enum_node_clamp_items); + RNA_def_property_enum_default(prop, NODE_CLAMP_MINMAX); + RNA_def_property_ui_text(prop, "Operation", ""); + RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update"); +} + static void def_geo_attribute_attribute_compare(StructRNA *srna) { PropertyRNA *prop; -- cgit v1.2.3