[Bf-blender-cvs] [13e9291650f] master: Library: Add flag top keep ID library pointer around

Sergey Sharybin noreply at git.blender.org
Wed Dec 6 13:00:19 CET 2017


Commit: 13e9291650f2f8c8c71fa13d5cc2c4fb7938cd05
Author: Sergey Sharybin
Date:   Wed Dec 6 12:59:00 2017 +0100
Branches: master
https://developer.blender.org/rB13e9291650f2f8c8c71fa13d5cc2c4fb7938cd05

Library: Add flag top keep ID library pointer around

This only applies to ID being copied outside of bmain. Handy for cases when it
is important to check if the copy corresponds to a data block coming from
library.

Example of that is proxy evaluation with copy on write.

Thanks Bastien for review!

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

M	source/blender/blenkernel/BKE_library.h
M	source/blender/blenkernel/intern/library.c

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

diff --git a/source/blender/blenkernel/BKE_library.h b/source/blender/blenkernel/BKE_library.h
index cd449b4d840..eb66d4edf0f 100644
--- a/source/blender/blenkernel/BKE_library.h
+++ b/source/blender/blenkernel/BKE_library.h
@@ -77,6 +77,7 @@ enum {
 	LIB_ID_COPY_CACHES             = 1 << 18,  /* Copy runtime data caches. */
 	/* XXX TODO Do we want to keep that? would rather try to get rid of it... */
 	LIB_ID_COPY_ACTIONS            = 1 << 19,  /* EXCEPTION! Deep-copy actions used by animdata of copied ID. */
+	LIB_ID_COPY_KEEP_LIB           = 1 << 20,  /* Keep the library pointer when copying datablock outside of bmain. */
 };
 
 void BKE_libblock_copy_ex(struct Main *bmain, const struct ID *id, struct ID **r_newid, const int flag);
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index b84a494c70e..9d05f13d7df 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -661,8 +661,12 @@ bool BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag, con
 	/* Do not make new copy local in case we are copying outside of main...
 	 * XXX TODO: is this behavior OK, or should we need own flag to control that? */
 	if ((flag & LIB_ID_CREATE_NO_MAIN) == 0) {
+		BLI_assert((flag & LIB_ID_COPY_KEEP_LIB) == 0);
 		BKE_id_copy_ensure_local(bmain, id, *r_newid);
 	}
+	else {
+		(*r_newid)->lib = id->lib;
+	}
 
 	return true;
 }



More information about the Bf-blender-cvs mailing list