Commit: 1833e8d7b0945605fda5beb8f224b019aaf7d6a8
Author: Sergey Sharybin
Date:   Thu May 3 11:07:09 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB1833e8d7b0945605fda5beb8f224b019aaf7d6a8

Fix for material/node tree localization

The workaround removal was wrong, the whole id->adt of a local
copy is to be NULL.

But now instead of modifying original datablock, we tell library
manager to not copy animation data.

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

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

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

diff --git a/source/blender/blenkernel/BKE_library.h 
b/source/blender/blenkernel/BKE_library.h
index f3df8b9b363..c34571fdd7a 100644
--- a/source/blender/blenkernel/BKE_library.h
+++ b/source/blender/blenkernel/BKE_library.h
@@ -78,6 +78,7 @@ enum {
        /* 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. */
+       LIB_ID_COPY_NO_ANIMDATA        = 1 << 21,  /* Don't copy id->adt, used 
by ID datablock localization routines. */
 };
 
 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 fa38e3c441a..d23d48752b6 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -1429,8 +1429,14 @@ void BKE_libblock_copy_ex(Main *bmain, const ID *id, ID 
**r_newid, const int fla
 #endif
 
        /* the duplicate should get a copy of the animdata */
-       BLI_assert((flag & LIB_ID_COPY_ACTIONS) == 0 || (flag & 
LIB_ID_CREATE_NO_MAIN) == 0);
-       id_copy_animdata(bmain, new_id, (flag & LIB_ID_COPY_ACTIONS) != 0 && 
(flag & LIB_ID_CREATE_NO_MAIN) == 0);
+       if ((flag & LIB_ID_COPY_NO_ANIMDATA) == 0) {
+               BLI_assert((flag & LIB_ID_COPY_ACTIONS) == 0 || (flag & 
LIB_ID_CREATE_NO_MAIN) == 0);
+               id_copy_animdata(bmain, new_id, (flag & LIB_ID_COPY_ACTIONS) != 
0 && (flag & LIB_ID_CREATE_NO_MAIN) == 0);
+       }
+       else if (id_can_have_animdata(new_id)) {
+               IdAdtTemplate *iat = (IdAdtTemplate *)new_id;
+               iat->adt = NULL;
+       }
 
        if ((flag & LIB_ID_CREATE_NO_DEG_TAG) == 0 && (flag & 
LIB_ID_CREATE_NO_MAIN) == 0) {
                DEG_id_type_tag(bmain, GS(new_id->name));
diff --git a/source/blender/blenkernel/intern/material.c 
b/source/blender/blenkernel/intern/material.c
index 725a7b07194..131d79c249f 100644
--- a/source/blender/blenkernel/intern/material.c
+++ b/source/blender/blenkernel/intern/material.c
@@ -187,15 +187,18 @@ Material *BKE_material_localize(Material *ma)
         * ... Once f*** nodes are fully converted to that too :( */
 
        Material *man;
-       
-       man = BKE_libblock_copy_nolib(&ma->id, false);
+
+       BKE_id_copy_ex(
+               NULL, &ma->id, (ID **)&man,
+               (LIB_ID_CREATE_NO_MAIN |
+                LIB_ID_CREATE_NO_USER_REFCOUNT |
+                LIB_ID_COPY_NO_PREVIEW |
+                LIB_ID_COPY_NO_ANIMDATA),
+               false);
 
        man->texpaintslot = NULL;
        man->preview = NULL;
-       
-       if (ma->nodetree)
-               man->nodetree = ntreeLocalize(ma->nodetree);
-       
+
        BLI_listbase_clear(&man->gpumaterial);
 
        /* TODO Duplicate Engine Settings and set runtime to NULL */
diff --git a/source/blender/blenkernel/intern/node.c 
b/source/blender/blenkernel/intern/node.c
index f3fd8b69b2c..3b51ce9366f 100644
--- a/source/blender/blenkernel/intern/node.c
+++ b/source/blender/blenkernel/intern/node.c
@@ -2001,8 +2001,13 @@ bNodeTree *ntreeLocalize(bNodeTree *ntree)
                /* Make full copy outside of Main database.
                 * Note: previews are not copied here.
                 */
-               BKE_id_copy_ex(G.main, (ID *)ntree, (ID **)&ltree,
-                              LIB_ID_CREATE_NO_MAIN | 
LIB_ID_CREATE_NO_USER_REFCOUNT | LIB_ID_COPY_NO_PREVIEW, false);
+               BKE_id_copy_ex(
+                       NULL, &ntree->id, (ID **)&ltree,
+                       (LIB_ID_CREATE_NO_MAIN |
+                        LIB_ID_CREATE_NO_USER_REFCOUNT |
+                        LIB_ID_COPY_NO_PREVIEW |
+                        LIB_ID_COPY_NO_ANIMDATA),
+                       false);
                ltree->flag |= NTREE_IS_LOCALIZED;
 
                for (node = ltree->nodes.first; node; node = node->next) {

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to