[Bf-blender-cvs] [4dbf5e3a814] master: Fix T62613: In duplicated collections objects loses patrenting.

Bastien Montagne noreply at git.blender.org
Wed Mar 6 15:39:58 CET 2019


Commit: 4dbf5e3a81466724f7eefc0978ae247571d1f4bd
Author: Bastien Montagne
Date:   Wed Mar 6 11:38:06 2019 +0100
Branches: master
https://developer.blender.org/rB4dbf5e3a81466724f7eefc0978ae247571d1f4bd

Fix T62613: In duplicated collections objects loses patrenting.

We need to remap duplicated IDs' ID pointers to new ones if they exist.

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

M	source/blender/blenkernel/intern/collection.c
M	source/blender/blenkernel/intern/library_remap.c

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

diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c
index ceac0215a5f..d351f112c8a 100644
--- a/source/blender/blenkernel/intern/collection.c
+++ b/source/blender/blenkernel/intern/collection.c
@@ -33,6 +33,7 @@
 #include "BKE_idprop.h"
 #include "BKE_layer.h"
 #include "BKE_library.h"
+#include "BKE_library_remap.h"
 #include "BKE_main.h"
 #include "BKE_object.h"
 #include "BKE_rigidbody.h"
@@ -308,14 +309,19 @@ Collection *BKE_collection_duplicate(
 	}
 
 	if (do_hierarchy) {
+		BKE_main_id_tag_all(bmain, LIB_TAG_NEW, false);
 		BKE_main_id_clear_newpoins(bmain);
 	}
 
 	Collection *collection_new = collection_duplicate_recursive(
 	                                 bmain, parent, collection, do_hierarchy, do_deep_copy);
 
+	/* This code will follows into all ID links using an ID tagged with LIB_TAG_NEW.*/
+	BKE_libblock_relink_to_newid(&collection_new->id);
+
 	if (do_hierarchy) {
 		/* Cleanup. */
+		BKE_main_id_tag_all(bmain, LIB_TAG_NEW, false);
 		BKE_main_id_clear_newpoins(bmain);
 	}
 
diff --git a/source/blender/blenkernel/intern/library_remap.c b/source/blender/blenkernel/intern/library_remap.c
index 03630297dc3..077ce059edf 100644
--- a/source/blender/blenkernel/intern/library_remap.c
+++ b/source/blender/blenkernel/intern/library_remap.c
@@ -679,7 +679,7 @@ static int id_relink_to_newid_looper(void *UNUSED(user_data), ID *UNUSED(self_id
 
 /** Similar to libblock_relink_ex, but is remapping IDs to their newid value if non-NULL, in given \a id.
  *
- * Very specific usage, not sure we'll keep it on the long run, currently only used in Object duplication code...
+ * Very specific usage, not sure we'll keep it on the long run, currently only used in Object/Collection duplication code...
  */
 void BKE_libblock_relink_to_newid(ID *id)
 {



More information about the Bf-blender-cvs mailing list