Commit: c907b160658bfa9f12e35fa2027387fc49a473bc
Author: Bastien Montagne
Date:   Wed Jun 21 11:08:50 2017 +0200
Branches: id_copy_refactor
https://developer.blender.org/rBc907b160658bfa9f12e35fa2027387fc49a473bc

Add mball and lattice new copying, tweak a bit more skey handling.

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

M       source/blender/blenkernel/BKE_lattice.h
M       source/blender/blenkernel/BKE_mball.h
M       source/blender/blenkernel/intern/curve.c
M       source/blender/blenkernel/intern/lattice.c
M       source/blender/blenkernel/intern/library.c
M       source/blender/blenkernel/intern/mball.c
M       source/blender/blenkernel/intern/mesh.c

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

diff --git a/source/blender/blenkernel/BKE_lattice.h 
b/source/blender/blenkernel/BKE_lattice.h
index ec1cf79832d..26e1f34282f 100644
--- a/source/blender/blenkernel/BKE_lattice.h
+++ b/source/blender/blenkernel/BKE_lattice.h
@@ -47,6 +47,7 @@ struct MDeformVert;
 void BKE_lattice_resize(struct Lattice *lt, int u, int v, int w, struct Object 
*ltOb);
 void BKE_lattice_init(struct Lattice *lt);
 struct Lattice *BKE_lattice_add(struct Main *bmain, const char *name);
+void BKE_lattice_copy_ex(struct Main *bmain, struct Lattice *lt_dst, const 
struct Lattice *lt_src, const int flag);
 struct Lattice *BKE_lattice_copy(struct Main *bmain, const struct Lattice *lt);
 void BKE_lattice_free(struct Lattice *lt);
 void BKE_lattice_make_local(struct Main *bmain, struct Lattice *lt, const bool 
lib_local);
diff --git a/source/blender/blenkernel/BKE_mball.h 
b/source/blender/blenkernel/BKE_mball.h
index c00a0743ebb..f182f6db2b6 100644
--- a/source/blender/blenkernel/BKE_mball.h
+++ b/source/blender/blenkernel/BKE_mball.h
@@ -41,6 +41,7 @@ struct MetaElem;
 void BKE_mball_free(struct MetaBall *mb);
 void BKE_mball_init(struct MetaBall *mb);
 struct MetaBall *BKE_mball_add(struct Main *bmain, const char *name);
+void BKE_mball_copy_ex(struct Main *bmain, struct MetaBall *mb_dst, const 
struct MetaBall *mb_src, const int flag);
 struct MetaBall *BKE_mball_copy(struct Main *bmain, const struct MetaBall *mb);
 
 void BKE_mball_make_local(struct Main *bmain, struct MetaBall *mb, const bool 
lib_local);
diff --git a/source/blender/blenkernel/intern/curve.c 
b/source/blender/blenkernel/intern/curve.c
index 9e3d8dccd3a..419246e040a 100644
--- a/source/blender/blenkernel/intern/curve.c
+++ b/source/blender/blenkernel/intern/curve.c
@@ -187,6 +187,12 @@ Curve *BKE_curve_add(Main *bmain, const char *name, int 
type)
        return cu;
 }
 
+/**
+ * Only copy internal data of Curve ID from source to already 
allocated/initialized destination.
+ * You probably nerver want to use that directly, use id_copy or 
BKE_id_copy_ex for typical needs.
+ *
+ * @param flag  Copying options (see BKE_library.h's LIB_ID_COPY_... flags for 
more).
+ */
 void BKE_curve_copy_ex(Main *bmain, Curve *cu_dst, const Curve *cu_src, const 
int flag)
 {
        int a;
@@ -208,7 +214,6 @@ void BKE_curve_copy_ex(Main *bmain, Curve *cu_dst, const 
Curve *cu_src, const in
 
        if (cu_src->key) {
                BKE_id_copy_ex(bmain, &cu_src->key->id, (ID **)&cu_dst->key, 
flag, false);
-               cu_dst->key->id.tag &= ~LIB_TAG_FREE_NO_USER_REFCOUNT;  /* XXX 
Bad hack, to be solved better hopefully :( */
        }
 
        cu_dst->editnurb = NULL;
diff --git a/source/blender/blenkernel/intern/lattice.c 
b/source/blender/blenkernel/intern/lattice.c
index c9d7dddf25a..0e5261ac6be 100644
--- a/source/blender/blenkernel/intern/lattice.c
+++ b/source/blender/blenkernel/intern/lattice.c
@@ -277,32 +277,37 @@ Lattice *BKE_lattice_add(Main *bmain, const char *name)
        return lt;
 }
 
-Lattice *BKE_lattice_copy(Main *bmain, const Lattice *lt)
+/**
+ * Only copy internal data of Lattice ID from source to already 
allocated/initialized destination.
+ * You probably nerver want to use that directly, use id_copy or 
BKE_id_copy_ex for typical needs.
+ *
+ * @param flag  Copying options (see BKE_library.h's LIB_ID_COPY_... flags for 
more).
+ */
+void BKE_lattice_copy_ex(Main *bmain, Lattice *lt_dst, const Lattice *lt_src, 
const int flag)
 {
-       Lattice *ltn;
+       lt_dst->def = MEM_dupallocN(lt_src->def);
 
-       ltn = BKE_libblock_copy(bmain, &lt->id);
-       ltn->def = MEM_dupallocN(lt->def);
-
-       if (lt->key) {
-               ltn->key = BKE_key_copy(bmain, ltn->key);
-               ltn->key->from = (ID *)ltn;
-       }
-       
-       if (lt->dvert) {
-               int tot = lt->pntsu * lt->pntsv * lt->pntsw;
-               ltn->dvert = MEM_mallocN(sizeof(MDeformVert) * tot, "Lattice 
MDeformVert");
-               BKE_defvert_array_copy(ltn->dvert, lt->dvert, tot);
+       if (lt_src->key) {
+               BKE_id_copy_ex(bmain, &lt_src->key->id, (ID **)&lt_dst->key, 
flag, false);
        }
 
-       ltn->editlatt = NULL;
+       if (lt_src->dvert) {
+               int tot = lt_src->pntsu * lt_src->pntsv * lt_src->pntsw;
+               lt_dst->dvert = MEM_mallocN(sizeof(MDeformVert) * tot, "Lattice 
MDeformVert");
+               BKE_defvert_array_copy(lt_dst->dvert, lt_src->dvert, tot);
+       }
 
-       BKE_id_copy_ensure_local(bmain, &lt->id, &ltn->id);
+       lt_dst->editlatt = NULL;
+}
 
-       return ltn;
+Lattice *BKE_lattice_copy(Main *bmain, const Lattice *lt)
+{
+       Lattice *lt_copy;
+       BKE_id_copy_ex(bmain, &lt->id, (ID **)&lt_copy, 0, false);
+       return lt_copy;
 }
 
-/** Free (or release) any data used by this lattice (does not free the lattice 
itself). */
+       /** Free (or release) any data used by this lattice (does not free the 
lattice itself). */
 void BKE_lattice_free(Lattice *lt)
 {
        BKE_animdata_free(&lt->id, false);
diff --git a/source/blender/blenkernel/intern/library.c 
b/source/blender/blenkernel/intern/library.c
index b765eafa141..3b46024556a 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -530,9 +530,11 @@ bool BKE_id_copy_ex(Main *bmain, const ID *id, ID 
**r_newid, const int flag, con
         * Ideally, usercount should never be handled by IDType-specific 
copying code, but for now let's allow it... */
        const int flag_idtype_copy = flag | LIB_ID_COPY_NO_USER_REFCOUNT;
 
+#define ITEMS_IMPLEMENTED ID_OB, ID_ME, ID_CU, ID_MB, ID_LT, ID_KE
+
        if (!test) {
                /* Check to be removed of course, just here until all 
BKE_xxx_copy_ex functions are done. */
-               if (ELEM(GS(id->name), ID_OB, ID_ME, ID_CU, ID_KE)) {
+               if (ELEM(GS(id->name), ITEMS_IMPLEMENTED)) {
                        BKE_libblock_copy_ex(bmain, id, r_newid, flag);
                }
        }
@@ -548,7 +550,7 @@ bool BKE_id_copy_ex(Main *bmain, const ID *id, ID 
**r_newid, const int flag, con
                        if (!test) BKE_curve_copy_ex(bmain, (Curve *)*r_newid, 
(Curve *)id, flag_idtype_copy);
                        break;
                case ID_MB:
-                       if (!test) *r_newid = (ID *)BKE_mball_copy(bmain, 
(MetaBall *)id);
+                       if (!test) BKE_mball_copy_ex(bmain, (MetaBall 
*)*r_newid, (MetaBall *)id, flag_idtype_copy);
                        break;
                case ID_MA:
                        if (!test) *r_newid = (ID *)BKE_material_copy(bmain, 
(Material *)id);
@@ -560,7 +562,7 @@ bool BKE_id_copy_ex(Main *bmain, const ID *id, ID 
**r_newid, const int flag, con
                        if (!test) *r_newid = (ID *)BKE_image_copy(bmain, 
(Image *)id);
                        break;
                case ID_LT:
-                       if (!test) *r_newid = (ID *)BKE_lattice_copy(bmain, 
(Lattice *)id);
+                       if (!test) BKE_lattice_copy_ex(bmain, (Lattice 
*)*r_newid, (Lattice *)id, flag_idtype_copy);
                        break;
                case ID_LA:
                        if (!test) *r_newid = (ID *)BKE_lamp_copy(bmain, (Lamp 
*)id);
@@ -633,7 +635,7 @@ bool BKE_id_copy_ex(Main *bmain, const ID *id, ID 
**r_newid, const int flag, con
 
        if (!test) {
                /* Check to be removed of course, just here until all 
BKE_xxx_copy_ex functions are done. */
-               if (ELEM(GS(id->name), ID_OB, ID_ME, ID_CU, ID_KE)) {
+               if (ELEM(GS(id->name), ITEMS_IMPLEMENTED)) {
                        /* Update ID refcount, remap pointers to self in new 
ID. */
                        struct IDCopyLibManagementData data = {.id_src=id, 
.flag=flag};
                        BKE_library_foreach_ID_link(bmain, *r_newid, 
id_copy_libmanagement_cb, &data, IDWALK_NOP);
@@ -646,6 +648,9 @@ bool BKE_id_copy_ex(Main *bmain, const ID *id, ID 
**r_newid, const int flag, con
                        if (key) {
                                data.id_src = (ID *)BKE_key_from_id((ID *)id);
                                BKE_library_foreach_ID_link(bmain, key, 
id_copy_libmanagement_cb, &data, IDWALK_NOP);
+                               if ((flag & LIB_ID_COPY_NO_USER_REFCOUNT) == 0) 
{
+                                       key->tag &= 
~LIB_TAG_FREE_NO_USER_REFCOUNT;
+                               }
                        }
                        /* TODO: most likely same for nodes too? */
 
diff --git a/source/blender/blenkernel/intern/mball.c 
b/source/blender/blenkernel/intern/mball.c
index b80579014d6..2cdef448a38 100644
--- a/source/blender/blenkernel/intern/mball.c
+++ b/source/blender/blenkernel/intern/mball.c
@@ -103,26 +103,36 @@ MetaBall *BKE_mball_add(Main *bmain, const char *name)
        return mb;
 }
 
-MetaBall *BKE_mball_copy(Main *bmain, const MetaBall *mb)
+/**
+ * Only copy internal data of MetaBall ID from source to already 
allocated/initialized destination.
+ * You probably nerver want to use that directly, use id_copy or 
BKE_id_copy_ex for typical needs.
+ *
+ * @param flag  Copying options (see BKE_library.h's LIB_ID_COPY_... flags for 
more).
+ */
+void BKE_mball_copy_ex(Main *UNUSED(bmain), MetaBall *mb_dst, const MetaBall 
*mb_src, const int flag)
 {
-       MetaBall *mbn;
        int a;
-       
-       mbn = BKE_libblock_copy(bmain, &mb->id);
 
-       BLI_duplicatelist(&mbn->elems, &mb->elems);
-       
-       mbn->mat = MEM_dupallocN(mb->mat);
-       for (a = 0; a < mbn->totcol; a++) {
-               id_us_plus((ID *)mbn->mat[a]);
+       BLI_duplicatelist(&mb_dst->elems, &mb_src->elems);
+
+       mb_dst->mat = MEM_dupallocN(mb_src->mat);
+       if ((flag & LIB_ID_COPY_NO_USER_REFCOUNT) == 0) {
+               for (a = 0; a < mb_dst->totcol; a++) {
+                       id_us_plus((ID *)mb_dst->mat[a]);
+               }
        }
 
-       mbn->editelems = NULL;
-       mbn->lastelem = NULL;
-       
-       BKE_id_copy_ensure_local(bmain, &mb->id, &mbn->id);
+       mb_dst->editelems = NULL;
+       mb_dst->lastelem = NULL;
+
+       return mb_dst;
+}
 
-       return mbn;
+MetaBall *BKE_mball_copy(Main *bmain, const MetaBall *mb)
+{
+       MetaBall *mb_copy;
+       BKE_id_copy_ex(bmain, &mb->id, (ID **)&mb_copy, 0, false);
+       return mb_copy;
 }
 
 void BKE_mball_make_local(Main *bmain, MetaBall *mb, const bool lib_local)
diff --git a/source/blender/blenkernel/intern/mesh.c 
b/source/blender/blenkernel/intern/mesh.c
index ef2571c4f4b..47f8957ed13 100644
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@ -542,7 +542,6 @@ void BKE_mesh_copy_ex(Main *bmain, Mesh *me_dst, const Mesh 
*me_src, const int f
        /* TODO Do we want to add flag to prevent this? */
        if (me_src->key) {
                BKE_id_copy_ex(bmain, &me_src->key->id, (ID **)&me_dst->key, 
flag, false);
-               me_dst->key->id.tag &= ~LIB_TAG_FREE_NO_USER_REFCOUNT;  /* XXX 
Bad hack, to be solved better hopefully :( */
        }
 }

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

Reply via email to