[Bf-blender-cvs] [61e0f229453] geometry-nodes: Geometry Nodes: Hide unsupported attribute types and domains
Hans Goudey
noreply at git.blender.org
Thu Nov 19 23:14:07 CET 2020
Commit: 61e0f22945397ca2a0ffd860f5bb8bc944235259
Author: Hans Goudey
Date: Thu Nov 19 17:13:56 2020 -0500
Branches: geometry-nodes
https://developer.blender.org/rB61e0f22945397ca2a0ffd860f5bb8bc944235259
Geometry Nodes: Hide unsupported attribute types and domains
The random attribute node currently doesn't support every attribute
domain or data type. With a bit of boilerplate code we can remove these
unsupported enum items from the UI for now, and also get a system to
remove unsupported items from the UI in the future. If all attribute
creation nodes end up always supporting all attibute types and domains,
this can be removed.
===================================================================
M source/blender/makesrna/intern/rna_nodetree.c
===================================================================
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index 701cf78d38b..c8fd92e9be5 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -1858,6 +1858,46 @@ static StructRNA *rna_Node_register(Main *bmain,
return nt->rna_ext.srna;
}
+static const EnumPropertyItem *generic_attribute_supported_list(
+ const EnumPropertyItem *original_item_array, bool (*value_supported)(int value))
+{
+ EnumPropertyItem *item_array = NULL;
+ int items_len = 0;
+
+ for (const EnumPropertyItem *item = original_item_array; item->identifier != NULL; item++) {
+ if (value_supported(item->value)) {
+ RNA_enum_items_add_value(&item_array, &items_len, original_item_array, item->value);
+ }
+ }
+
+ RNA_enum_item_end(&item_array, &items_len);
+ return item_array;
+}
+
+static bool attribute_random_type_supported(int value)
+{
+ return ELEM(value, CD_PROP_FLOAT, CD_PROP_FLOAT3);
+}
+static const EnumPropertyItem *rna_GeometryNodeAttributeRandom_type_itemf(
+ bContext *UNUSED(C), PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free)
+{
+ *r_free = true;
+ return generic_attribute_supported_list(rna_enum_attribute_type_items,
+ attribute_random_type_supported);
+}
+
+static bool attribute_random_domain_supported(int value)
+{
+ return ELEM(value, ATTR_DOMAIN_VERTEX, ATTR_DOMAIN_POINT);
+}
+static const EnumPropertyItem *rna_GeometryNodeAttributeRandom_domain_itemf(
+ bContext *UNUSED(C), PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free)
+{
+ *r_free = true;
+ return generic_attribute_supported_list(rna_enum_attribute_domain_items,
+ attribute_random_domain_supported);
+}
+
static StructRNA *rna_ShaderNode_register(Main *bmain,
ReportList *reports,
void *data,
@@ -8259,13 +8299,22 @@ static void def_geo_triangulate(StructRNA *srna)
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
}
-static void def_geo_attribute_create_common(StructRNA *srna)
+/**
+ * \note Passing the item functions as arguments here allows reusing the same
+ * original list of items from Attribute RNA.
+ */
+static void def_geo_attribute_create_common(StructRNA *srna,
+ const char *type_items_func,
+ const char *domain_items_func)
{
PropertyRNA *prop;
prop = RNA_def_property(srna, "data_type", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "custom1");
RNA_def_property_enum_items(prop, rna_enum_attribute_type_items);
+ if (type_items_func != NULL) {
+ RNA_def_property_enum_funcs(prop, NULL, NULL, type_items_func);
+ }
RNA_def_property_enum_default(prop, CD_PROP_FLOAT);
RNA_def_property_ui_text(prop, "Data Type", "Type of data stored in attribute");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
@@ -8273,6 +8322,9 @@ static void def_geo_attribute_create_common(StructRNA *srna)
prop = RNA_def_property(srna, "domain", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "custom2");
RNA_def_property_enum_items(prop, rna_enum_attribute_domain_items);
+ if (domain_items_func != NULL) {
+ RNA_def_property_enum_funcs(prop, NULL, NULL, domain_items_func);
+ }
RNA_def_property_enum_default(prop, ATTR_DOMAIN_VERTEX);
RNA_def_property_ui_text(prop, "Domain", "");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
@@ -8280,7 +8332,9 @@ static void def_geo_attribute_create_common(StructRNA *srna)
static void def_geo_random_attribute(StructRNA *srna)
{
- def_geo_attribute_create_common(srna);
+ def_geo_attribute_create_common(srna,
+ "rna_GeometryNodeAttributeRandom_type_itemf",
+ "rna_GeometryNodeAttributeRandom_domain_itemf");
}
/* -------------------------------------------------------------------------- */
More information about the Bf-blender-cvs
mailing list