diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-09-04 08:14:42 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-09-04 08:14:42 +0400 |
commit | ca8d026fefd7ca09b8bf80146c20db1556861767 (patch) | |
tree | 3743ef600427f1dbda1a65303bf30e54b91b7829 /source/blender/editors | |
parent | c6b96c241be073bd72d083391f1f240c0867a59a (diff) |
Fix T40595: File broken after "make local->all"
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/object/object_relations.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/source/blender/editors/object/object_relations.c b/source/blender/editors/object/object_relations.c index 08e30447204..0d58eaee5fa 100644 --- a/source/blender/editors/object/object_relations.c +++ b/source/blender/editors/object/object_relations.c @@ -2143,9 +2143,40 @@ static void tag_localizable_objects(bContext *C, int mode) /* TODO(sergey): Drivers targets? */ } +/** + * Instance indirectly referenced zero user objects, + * otherwise they're lost on reload, see T40595. + */ +static bool make_local_all__instance_indirect_unused(Main *bmain, Scene *scene) +{ + Object *ob; + bool changed = false; + + for (ob = bmain->object.first; ob; ob = ob->id.next) { + if (ob->id.lib && (ob->id.us == 0)) { + Base *base; + + ob->id.us = 1; + + /* not essential, but for correctness */ + id_lib_extern(&ob->id); + + base = BKE_scene_base_add(scene, ob); + base->flag |= SELECT; + base->object->flag = base->flag; + DAG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME); + + changed = true; + } + } + + return changed; +} + static int make_local_exec(bContext *C, wmOperator *op) { Main *bmain = CTX_data_main(C); + Scene *scene = CTX_data_scene(C); AnimData *adt; ParticleSystem *psys; Material *ma, ***matarar; @@ -2154,6 +2185,14 @@ static int make_local_exec(bContext *C, wmOperator *op) int a, b, mode = RNA_enum_get(op->ptr, "type"); if (mode == MAKE_LOCAL_ALL) { + /* de-select so the user can differentiate newly instanced from existing objects */ + BKE_scene_base_deselect_all(scene); + + if (make_local_all__instance_indirect_unused(bmain, scene)) { + BKE_report(op->reports, RPT_INFO, + "Orphan library objects added to the current scene to avoid loss"); + } + BKE_library_make_local(bmain, NULL, false); /* NULL is all libs */ WM_event_add_notifier(C, NC_WINDOW, NULL); return OPERATOR_FINISHED; |