[Bf-blender-cvs] [b37d36a60f9] master: Fix: Add versioning for geometry nodes attribute input toggle

Hans Goudey noreply at git.blender.org
Tue Sep 21 19:42:59 CEST 2021


Commit: b37d36a60f9f60d8beb34142b4768f7bcd7bf987
Author: Hans Goudey
Date:   Tue Sep 21 12:42:47 2021 -0500
Branches: master
https://developer.blender.org/rBb37d36a60f9f60d8beb34142b4768f7bcd7bf987

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

===================================================================

M	source/blender/blenloader/intern/versioning_300.c

===================================================================

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);
+        }
+      }
+    }
   }
 }



More information about the Bf-blender-cvs mailing list