diff options
Diffstat (limited to 'source/blender/blenkernel/intern/mball.c')
-rw-r--r-- | source/blender/blenkernel/intern/mball.c | 67 |
1 files changed, 22 insertions, 45 deletions
diff --git a/source/blender/blenkernel/intern/mball.c b/source/blender/blenkernel/intern/mball.c index 685cd35fc20..9a0a6e3540c 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(Main *bmain, MetaBall *mb) { MetaBall *mbn; int a; - mbn = BKE_libblock_copy(&mb->id); + mbn = BKE_libblock_copy(bmain, &mb->id); BLI_duplicatelist(&mbn->elems, &mb->elems); @@ -117,65 +119,40 @@ MetaBall *BKE_mball_copy(MetaBall *mb) mbn->editelems = NULL; mbn->lastelem = NULL; - if (mb->id.lib) { - BKE_id_lib_local_paths(G.main, mb->id.lib, &mbn->id); + if (ID_IS_LINKED_DATABLOCK(mb)) { + BKE_id_expand_local(&mbn->id); + BKE_id_lib_local_paths(bmain, mb->id.lib, &mbn->id); } return mbn; } -static void extern_local_mball(MetaBall *mb) +void BKE_mball_make_local(Main *bmain, MetaBall *mb) { - if (mb->mat) { - extern_local_matarar(mb->mat, mb->totcol); - } -} - -void BKE_mball_make_local(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 (mb->id.lib == NULL) 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 (ob->id.lib) 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); + BKE_id_expand_local(&mb->id); } - } - - 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 (ob->id.lib == NULL) { - ob->data = mb_new; - id_us_plus(&mb_new->id); - id_us_min(&mb->id); - } - } + else { + MetaBall *mb_new = BKE_mball_copy(bmain, mb); + + mb_new->id.us = 0; + + BKE_libblock_remap(bmain, mb, mb_new, ID_REMAP_SKIP_INDIRECT_USAGE); } } } |