OVERVIEW * In 2.7 terminology, all layers and groups are now collection datablocks. * These collections are nestable, linkable, instanceable, overrideable, .. which opens up new ways to set up scenes and link + override data. * Viewport/render visibility and selectability are now a part of the collection and shared across all view layers and linkable. * View layers define which subset of the scene collection hierarchy is excluded for each. For many workflows one view layer can be used, these are more of an advanced feature now. OUTLINER * The outliner now has a "View Layer" display mode instead of "Collections", which can display the collections and/or objects in the view layer. * In this display mode, collections can be excluded with the right click menu. These will then be greyed out and their objects will be excluded. * To view collections not linked to any scene, the "Blender File" display mode can be used, with the new filtering option to just see Colleciton datablocks. * The outliner right click menus for collections and objects were reorganized. * Drag and drop still needs to be improved. Like before, dragging the icon or text gives different results, we'll unify this later. LINKING AND OVERRIDES * Collections can now be linked into the scene without creating an instance, with the link/append operator or from the collections view in the outliner. * Collections can get static overrides with the right click menu in the outliner, but this is rather unreliable and not clearly communicated at the moment. * We still need to improve the make override operator to turn collection instances into collections with overrides directly in the scene. PERFORMANCE * We tried to make performance not worse than before and improve it in some cases. The main thing that's still a bit slower is multiple scenes, we have to change the layer syncing to only updated affected scenes. * Collections keep a list of their parent collections for faster incremental updates in syncing and caching. * View layer bases are now in a object -> base hash to avoid quadratic time lookups internally and in API functions like visible_get(). VERSIONING * Compatibility with 2.7 files should be improved due to the new visibility controls. Of course users may not want to set up their scenes differently now to avoid having separate layers and groups. * Compatibility with 2.8 is mostly there, and was tested on Eevee demo and Hero files. There's a few things which are know to be not quite compatible, like nested layer collections inside groups. * The versioning code for 2.8 files is quite complicated, and isolated behind #ifdef so it can be removed at the end of the release cycle. KNOWN ISSUES * The G-key group operators in the 3D viewport were left mostly as is, they need to be modified still to fit better. * Same for the groups panel in the object properties. This needs to be updated still, or perhaps replaced by something better. * Collections must all have a unique name. Less restrictive namespacing is to be done later, we'll have to see how important this is as all objects within the collections must also have a unique name anyway. * Full scene copy and delete scene are exactly doing the right thing yet. Differential Revision: https://developer.blender.org/D3383 https://code.blender.org/2018/05/collections-and-groups/
176 lines
5.0 KiB
C
176 lines
5.0 KiB
C
/*
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License
|
|
* as published by the Free Software Foundation; either version 2
|
|
* of the License, or (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
*
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
*/
|
|
|
|
/** \file blender/blenkernel/intern/blender_copybuffer.c
|
|
* \ingroup bke
|
|
*
|
|
* Used for copy/paste operator, (using a temporary file).
|
|
*/
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
#include "DNA_userdef_types.h"
|
|
#include "DNA_scene_types.h"
|
|
#include "DNA_screen_types.h"
|
|
#include "DNA_view3d_types.h"
|
|
#include "DNA_windowmanager_types.h"
|
|
|
|
#include "BLI_blenlib.h"
|
|
#include "BLI_utildefines.h"
|
|
#include "BLI_callbacks.h"
|
|
|
|
#include "IMB_imbuf.h"
|
|
#include "IMB_moviecache.h"
|
|
|
|
#include "BKE_blender_copybuffer.h" /* own include */
|
|
#include "BKE_blendfile.h"
|
|
#include "BKE_context.h"
|
|
#include "BKE_global.h"
|
|
#include "BKE_layer.h"
|
|
#include "BKE_library.h"
|
|
#include "BKE_main.h"
|
|
#include "BKE_scene.h"
|
|
|
|
#include "DEG_depsgraph.h"
|
|
#include "DEG_depsgraph_build.h"
|
|
|
|
#include "BLO_readfile.h"
|
|
#include "BLO_writefile.h"
|
|
|
|
#include "IMB_colormanagement.h"
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Copy/Paste `.blend`, partial saves.
|
|
* \{ */
|
|
|
|
void BKE_copybuffer_begin(Main *bmain_src)
|
|
{
|
|
BKE_blendfile_write_partial_begin(bmain_src);
|
|
}
|
|
|
|
void BKE_copybuffer_tag_ID(ID *id)
|
|
{
|
|
BKE_blendfile_write_partial_tag_ID(id, true);
|
|
}
|
|
|
|
/**
|
|
* \return Success.
|
|
*/
|
|
bool BKE_copybuffer_save(Main *bmain_src, const char *filename, ReportList *reports)
|
|
{
|
|
const int write_flags = G_FILE_RELATIVE_REMAP;
|
|
|
|
bool retval = BKE_blendfile_write_partial(bmain_src, filename, write_flags, reports);
|
|
|
|
BKE_blendfile_write_partial_end(bmain_src);
|
|
|
|
return retval;
|
|
}
|
|
|
|
bool BKE_copybuffer_read(Main *bmain_dst, const char *libname, ReportList *reports)
|
|
{
|
|
BlendHandle *bh = BLO_blendhandle_from_file(libname, reports);
|
|
if (bh == NULL) {
|
|
/* Error reports will have been made by BLO_blendhandle_from_file(). */
|
|
return false;
|
|
}
|
|
/* Here appending/linking starts. */
|
|
Main *mainl = BLO_library_link_begin(bmain_dst, &bh, libname);
|
|
BLO_library_link_copypaste(mainl, bh);
|
|
BLO_library_link_end(mainl, &bh, 0, NULL, NULL, NULL);
|
|
/* Mark all library linked objects to be updated. */
|
|
BKE_main_lib_objects_recalc_all(bmain_dst);
|
|
IMB_colormanagement_check_file_config(bmain_dst);
|
|
/* Append, rather than linking. */
|
|
Library *lib = BLI_findstring(&bmain_dst->library, libname, offsetof(Library, filepath));
|
|
BKE_library_make_local(bmain_dst, lib, NULL, true, false);
|
|
/* Important we unset, otherwise these object wont
|
|
* link into other scenes from this blend file.
|
|
*/
|
|
BKE_main_id_tag_all(bmain_dst, LIB_TAG_PRE_EXISTING, false);
|
|
BLO_blendhandle_close(bh);
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* \return Success.
|
|
*/
|
|
bool BKE_copybuffer_paste(bContext *C, const char *libname, const short flag, ReportList *reports)
|
|
{
|
|
Main *bmain = CTX_data_main(C);
|
|
Scene *scene = CTX_data_scene(C);
|
|
ViewLayer *view_layer = CTX_data_view_layer(C);
|
|
Main *mainl = NULL;
|
|
Library *lib;
|
|
BlendHandle *bh;
|
|
|
|
bh = BLO_blendhandle_from_file(libname, reports);
|
|
|
|
if (bh == NULL) {
|
|
/* error reports will have been made by BLO_blendhandle_from_file() */
|
|
return false;
|
|
}
|
|
|
|
BKE_view_layer_base_deselect_all(view_layer);
|
|
|
|
/* tag everything, all untagged data can be made local
|
|
* its also generally useful to know what is new
|
|
*
|
|
* take extra care BKE_main_id_flag_all(bmain, LIB_TAG_PRE_EXISTING, false) is called after! */
|
|
BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, true);
|
|
|
|
/* here appending/linking starts */
|
|
mainl = BLO_library_link_begin(bmain, &bh, libname);
|
|
|
|
BLO_library_link_copypaste(mainl, bh);
|
|
|
|
BLO_library_link_end(mainl, &bh, flag, bmain, scene, view_layer);
|
|
|
|
/* mark all library linked objects to be updated */
|
|
BKE_main_lib_objects_recalc_all(bmain);
|
|
IMB_colormanagement_check_file_config(bmain);
|
|
|
|
/* append, rather than linking */
|
|
lib = BLI_findstring(&bmain->library, libname, offsetof(Library, filepath));
|
|
BKE_library_make_local(bmain, lib, NULL, true, false);
|
|
|
|
/* important we unset, otherwise these object wont
|
|
* link into other scenes from this blend file */
|
|
BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, false);
|
|
|
|
/* recreate dependency graph to include new objects */
|
|
DEG_relations_tag_update(bmain);
|
|
|
|
/* Tag update the scene to flush base collection settings, since the new object is added to a
|
|
* new (active) collection, not its original collection, thus need recalculation. */
|
|
DEG_id_tag_update(&scene->id, 0);
|
|
|
|
BLO_blendhandle_close(bh);
|
|
/* remove library... */
|
|
|
|
return true;
|
|
}
|
|
|
|
/** \} */
|