[Bf-blender-cvs] [6db059e3d7c] master: Render: Update lightgroup membership in objects and world if lightgroup is renamed

Lukas Stockner noreply at git.blender.org
Sun Jul 24 21:34:09 CEST 2022


Commit: 6db059e3d7c3156943e3f0646612eb1d74409215
Author: Lukas Stockner
Date:   Mon May 16 10:52:49 2022 +0200
Branches: master
https://developer.blender.org/rB6db059e3d7c3156943e3f0646612eb1d74409215

Render: Update lightgroup membership in objects and world if lightgroup is renamed

As discussed, this only updates objects in and the world of the scene to which the view layer belongs, which also avoids the problem of not having a BMain available.

Differential Revision: https://developer.blender.org/D14740

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

M	source/blender/blenkernel/BKE_layer.h
M	source/blender/blenkernel/intern/layer.c
M	source/blender/makesrna/intern/rna_scene.c

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

diff --git a/source/blender/blenkernel/BKE_layer.h b/source/blender/blenkernel/BKE_layer.h
index 3e4f2fe154e..9a6c3cf2b5f 100644
--- a/source/blender/blenkernel/BKE_layer.h
+++ b/source/blender/blenkernel/BKE_layer.h
@@ -590,7 +590,8 @@ void BKE_view_layer_set_active_lightgroup(struct ViewLayer *view_layer,
                                           struct ViewLayerLightgroup *lightgroup);
 struct ViewLayer *BKE_view_layer_find_with_lightgroup(
     struct Scene *scene, struct ViewLayerLightgroup *view_layer_lightgroup);
-void BKE_view_layer_rename_lightgroup(ViewLayer *view_layer,
+void BKE_view_layer_rename_lightgroup(struct Scene *scene,
+                                      ViewLayer *view_layer,
                                       ViewLayerLightgroup *lightgroup,
                                       const char *name);
 
diff --git a/source/blender/blenkernel/intern/layer.c b/source/blender/blenkernel/intern/layer.c
index ac582ff69ca..dabc76f29ca 100644
--- a/source/blender/blenkernel/intern/layer.c
+++ b/source/blender/blenkernel/intern/layer.c
@@ -39,6 +39,7 @@
 #include "DNA_view3d_types.h"
 #include "DNA_windowmanager_types.h"
 #include "DNA_workspace_types.h"
+#include "DNA_world_types.h"
 
 #include "DEG_depsgraph.h"
 #include "DEG_depsgraph_debug.h"
@@ -2588,12 +2589,36 @@ ViewLayer *BKE_view_layer_find_with_lightgroup(struct Scene *scene,
   return NULL;
 }
 
-void BKE_view_layer_rename_lightgroup(ViewLayer *view_layer,
+void BKE_view_layer_rename_lightgroup(Scene *scene,
+                                      ViewLayer *view_layer,
                                       ViewLayerLightgroup *lightgroup,
                                       const char *name)
 {
+  char old_name[64];
+  BLI_strncpy_utf8(old_name, lightgroup->name, sizeof(old_name));
   BLI_strncpy_utf8(lightgroup->name, name, sizeof(lightgroup->name));
   viewlayer_lightgroup_make_name_unique(view_layer, lightgroup);
+
+  if (scene != NULL) {
+    /* Update objects in the scene to refer to the new name instead. */
+    FOREACH_SCENE_OBJECT_BEGIN (scene, ob) {
+      if (!ID_IS_LINKED(ob) && ob->lightgroup != NULL) {
+        LightgroupMembership *lgm = ob->lightgroup;
+        if (STREQ(lgm->name, old_name)) {
+          BLI_strncpy_utf8(lgm->name, lightgroup->name, sizeof(lgm->name));
+        }
+      }
+    }
+    FOREACH_SCENE_OBJECT_END;
+
+    /* Update the scene's world to refer to the new name instead. */
+    if (scene->world != NULL && !ID_IS_LINKED(scene->world) && scene->world->lightgroup != NULL) {
+      LightgroupMembership *lgm = scene->world->lightgroup;
+      if (STREQ(lgm->name, old_name)) {
+        BLI_strncpy_utf8(lgm->name, lightgroup->name, sizeof(lgm->name));
+      }
+    }
+  }
 }
 
 void BKE_lightgroup_membership_get(struct LightgroupMembership *lgm, char *name)
diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c
index daf4c99845d..f24aec3447b 100644
--- a/source/blender/makesrna/intern/rna_scene.c
+++ b/source/blender/makesrna/intern/rna_scene.c
@@ -2501,7 +2501,7 @@ static void rna_ViewLayerLightgroup_name_set(PointerRNA *ptr, const char *value)
   Scene *scene = (Scene *)ptr->owner_id;
   ViewLayer *view_layer = BKE_view_layer_find_with_lightgroup(scene, lightgroup);
 
-  BKE_view_layer_rename_lightgroup(view_layer, lightgroup, value);
+  BKE_view_layer_rename_lightgroup(scene, view_layer, lightgroup, value);
 }
 
 /* Fake value, used internally (not saved to DNA). */



More information about the Bf-blender-cvs mailing list