diff options
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_material.h | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_mball.h | 3 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/library.c | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/material.c | 9 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/mball.c | 79 |
5 files changed, 42 insertions, 52 deletions
diff --git a/source/blender/blenkernel/BKE_material.h b/source/blender/blenkernel/BKE_material.h index d79214f3076..539cf8a57d7 100644 --- a/source/blender/blenkernel/BKE_material.h +++ b/source/blender/blenkernel/BKE_material.h @@ -58,7 +58,6 @@ struct Material *BKE_material_copy(struct Material *ma); struct Material *localize_material(struct Material *ma); struct Material *give_node_material(struct Material *ma); /* returns node material or self */ void BKE_material_make_local(struct Material *ma); -void extern_local_matarar(struct Material **matar, short totcol); /* UNUSED */ // void automatname(struct Material *); diff --git a/source/blender/blenkernel/BKE_mball.h b/source/blender/blenkernel/BKE_mball.h index b8258455c65..abb1259ca54 100644 --- a/source/blender/blenkernel/BKE_mball.h +++ b/source/blender/blenkernel/BKE_mball.h @@ -42,8 +42,9 @@ 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); struct MetaBall *BKE_mball_copy(struct MetaBall *mb); +struct MetaBall *BKE_mball_copy_ex(struct Main *bmain, struct MetaBall *mb); -void BKE_mball_make_local(struct MetaBall *mb); +void BKE_mball_make_local(struct Main *bmain, struct MetaBall *mb); bool BKE_mball_is_basis_for(struct Object *ob1, struct Object *ob2); bool BKE_mball_is_basis(struct Object *ob); diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index c7a7bb0c0f7..80bd1e9ec03 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -273,7 +273,7 @@ bool id_make_local(Main *bmain, ID *id, bool test) if (!test) BKE_curve_make_local(bmain, (Curve *)id); return true; case ID_MB: - if (!test) BKE_mball_make_local((MetaBall *)id); + if (!test) BKE_mball_make_local(bmain, (MetaBall *)id); return true; case ID_MA: if (!test) BKE_material_make_local((Material *)id); diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c index 5e1dc66d859..1b6fd300f67 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -450,15 +450,6 @@ void BKE_material_make_local(Material *ma) } } -/* for curve, mball, mesh types */ -void extern_local_matarar(struct Material **matar, short totcol) -{ - short i; - for (i = 0; i < totcol; i++) { - id_lib_extern((ID *)matar[i]); - } -} - Material ***give_matarar(Object *ob) { Mesh *me; diff --git a/source/blender/blenkernel/intern/mball.c b/source/blender/blenkernel/intern/mball.c index 877937eb726..c6e6bb86659 100644 --- a/source/blender/blenkernel/intern/mball.c +++ b/source/blender/blenkernel/intern/mball.c @@ -59,6 +59,8 @@ #include "BKE_depsgraph.h" #include "BKE_scene.h" #include "BKE_library.h" +#include "BKE_library_query.h" +#include "BKE_library_remap.h" #include "BKE_displist.h" #include "BKE_mball.h" #include "BKE_object.h" @@ -100,12 +102,12 @@ MetaBall *BKE_mball_add(Main *bmain, const char *name) return mb; } -MetaBall *BKE_mball_copy(MetaBall *mb) +MetaBall *BKE_mball_copy_ex(Main *bmain, MetaBall *mb) { MetaBall *mbn; int a; - mbn = BKE_libblock_copy(&mb->id); + mbn = BKE_libblock_copy_ex(bmain, &mb->id); BLI_duplicatelist(&mbn->elems, &mb->elems); @@ -118,64 +120,61 @@ MetaBall *BKE_mball_copy(MetaBall *mb) mbn->lastelem = NULL; if (ID_IS_LINKED_DATABLOCK(mb)) { - BKE_id_lib_local_paths(G.main, mb->id.lib, &mbn->id); + BKE_id_lib_local_paths(bmain, mb->id.lib, &mbn->id); } return mbn; } -static void extern_local_mball(MetaBall *mb) +MetaBall *BKE_mball_copy(MetaBall *mb) +{ + return BKE_mball_copy_ex(G.main, mb); +} + +static int extern_local_mball_callback( + void *UNUSED(user_data), struct ID *UNUSED(id_self), struct ID **id_pointer, int cd_flag) { - if (mb->mat) { - extern_local_matarar(mb->mat, mb->totcol); + /* We only tag usercounted ID usages as extern... Why? */ + if ((cd_flag & IDWALK_USER) && *id_pointer) { + id_lib_extern(*id_pointer); } + return IDWALK_RET_NOP; } -void BKE_mball_make_local(MetaBall *mb) +static void extern_local_mball(MetaBall *mb) +{ + BKE_library_foreach_ID_link(&mb->id, extern_local_mball_callback, NULL, 0); +} + +void BKE_mball_make_local(Main *bmain, MetaBall *mb) { - Main *bmain = G.main; - Object *ob; bool is_local = false, is_lib = false; /* - only lib users: do nothing * - only local users: set flag * - mixed: make copy */ - - if (!ID_IS_LINKED_DATABLOCK(mb)) return; - if (mb->id.us == 1) { - id_clear_lib_data(bmain, &mb->id); - extern_local_mball(mb); - + + if (!ID_IS_LINKED_DATABLOCK(mb)) { return; } - for (ob = G.main->object.first; ob && ELEM(0, is_lib, is_local); ob = ob->id.next) { - if (ob->data == mb) { - if (ID_IS_LINKED_DATABLOCK(ob)) is_lib = true; - else is_local = true; + BKE_library_ID_test_usages(bmain, mb, &is_local, &is_lib); + + if (is_local) { + if (!is_lib) { + id_clear_lib_data(bmain, &mb->id); + extern_local_mball(mb); } - } - - if (is_local && is_lib == false) { - id_clear_lib_data(bmain, &mb->id); - extern_local_mball(mb); - } - else if (is_local && is_lib) { - MetaBall *mb_new = BKE_mball_copy(mb); - mb_new->id.us = 0; - - /* Remap paths of new ID using old library as base. */ - BKE_id_lib_local_paths(bmain, mb->id.lib, &mb_new->id); - - for (ob = G.main->object.first; ob; ob = ob->id.next) { - if (ob->data == mb) { - if (!ID_IS_LINKED_DATABLOCK(ob)) { - ob->data = mb_new; - id_us_plus(&mb_new->id); - id_us_min(&mb->id); - } - } + else { + MetaBall *mb_new = BKE_mball_copy_ex(bmain, mb); + + mb_new->id.us = 0; + + /* Remap paths of new ID using old library as base. */ + BKE_id_lib_local_paths(bmain, mb->id.lib, &mb_new->id); + + BKE_libblock_remap(bmain, mb, mb_new, ID_REMAP_SKIP_INDIRECT_USAGE); } } } |