From b37d36a60f9f60d8beb34142b4768f7bcd7bf987 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Tue, 21 Sep 2021 12:42:47 -0500 Subject: Fix: Add versioning for geometry nodes attribute input toggle rB8e21d528cab98 neglected to add versioning to add the new "use_attribute" and "attribute_name" properties to the modifier input list. Though they are added if the modifier's interface is updated, that doesn't happen when the file is loaded, so patch adds them manually. Another solution would be calling `MOD_nodes_update_interface`, but that would require including the modifiers module. Differential Revision: https://developer.blender.org/D12535 --- source/blender/blenloader/intern/versioning_300.c | 48 +++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/versioning_300.c b/source/blender/blenloader/intern/versioning_300.c index 791b5d52d97..58265bca238 100644 --- a/source/blender/blenloader/intern/versioning_300.c +++ b/source/blender/blenloader/intern/versioning_300.c @@ -808,6 +808,47 @@ static void do_version_subsurface_methods(bNode *node) } } +static void version_geometry_nodes_add_attribute_input_settings(NodesModifierData *nmd) +{ + /* Before versioning the properties, make sure it hasn't been done already. */ + LISTBASE_FOREACH (const IDProperty *, property, &nmd->settings.properties->data.group) { + if (strstr(property->name, "_use_attribute") || strstr(property->name, "_attribute_name")) { + return; + } + } + + LISTBASE_FOREACH_MUTABLE (IDProperty *, property, &nmd->settings.properties->data.group) { + if (!ELEM(property->type, IDP_FLOAT, IDP_INT, IDP_ARRAY)) { + continue; + } + + if (strstr(property->name, "_use_attribute") || strstr(property->name, "_attribute_name")) { + continue; + } + + char use_attribute_prop_name[MAX_IDPROP_NAME]; + BLI_snprintf(use_attribute_prop_name, + sizeof(use_attribute_prop_name), + "%s%s", + property->name, + "_use_attribute"); + + IDPropertyTemplate idprop = {0}; + IDProperty *use_attribute_prop = IDP_New(IDP_INT, &idprop, use_attribute_prop_name); + IDP_AddToGroup(nmd->settings.properties, use_attribute_prop); + + char attribute_name_prop_name[MAX_IDPROP_NAME]; + BLI_snprintf(attribute_name_prop_name, + sizeof(attribute_name_prop_name), + "%s%s", + property->name, + "_attribute_name"); + + IDProperty *attribute_prop = IDP_New(IDP_STRING, &idprop, attribute_name_prop_name); + IDP_AddToGroup(nmd->settings.properties, attribute_prop); + } +} + /* NOLINTNEXTLINE: readability-function-size */ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain) { @@ -1390,5 +1431,12 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain) */ { /* Keep this block, even when empty. */ + LISTBASE_FOREACH (Object *, ob, &bmain->objects) { + LISTBASE_FOREACH (ModifierData *, md, &ob->modifiers) { + if (md->type == eModifierType_Nodes) { + version_geometry_nodes_add_attribute_input_settings((NodesModifierData *)md); + } + } + } } } -- cgit v1.2.3