2022-02-11 09:07:11 +11:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
* Copyright 2001-2002 NaN Holding BV. All rights reserved. */
|
2020-02-10 17:10:17 +01:00
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
|
* \ingroup bke
|
|
|
|
|
*
|
|
|
|
|
* Contains code specific to the `Library` ID type.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "CLG_log.h"
|
|
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
|
|
/* all types are needed here, in order to do memory operations */
|
|
|
|
|
#include "DNA_ID.h"
|
|
|
|
|
|
|
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
|
|
|
|
|
#include "BLI_blenlib.h"
|
|
|
|
|
|
2020-03-06 11:27:29 +01:00
|
|
|
#include "BLT_translation.h"
|
|
|
|
|
|
Refactor BKE_bpath module.
The main goal of this refactor is to make BPath module use `IDTypeInfo`,
and move each ID-specific part of the `foreach_path` looper into their
own IDTypeInfo struct, using a new `foreach_path` callback.
Additionally, following improvements/cleanups are included:
* Attempt to get better, more consistent namings.
** In particular, move from `path_visitor` to more standard `foreach_path`.
* Update and extend documentation.
** API doc was moved to header, according to recent discussions on this
topic.
* Remove `BKE_bpath_relocate_visitor` from API, this is specific
callback that belongs in `lib_id.c` user code.
NOTE: This commit is expected to be 100% non-behavioral-change. This
implies that several potential further changes were only noted as
comments (like using a more generic solution for
`lib_id_library_local_paths`, addressing inconsistencies like path of
packed libraries always being skipped, regardless of the
`BKE_BPATH_FOREACH_PATH_SKIP_PACKED` `eBPathForeachFlag` flag value,
etc.).
NOTE: basic unittests were added to master already in
rBdcc500e5a265093bc9cc.
Reviewed By: brecht
Differential Revision: https://developer.blender.org/D13381
2021-11-29 14:20:58 +01:00
|
|
|
#include "BKE_bpath.h"
|
2020-03-06 11:27:29 +01:00
|
|
|
#include "BKE_idtype.h"
|
2020-02-10 17:10:17 +01:00
|
|
|
#include "BKE_lib_id.h"
|
2020-05-12 18:20:49 +02:00
|
|
|
#include "BKE_lib_query.h"
|
2020-02-10 17:10:17 +01:00
|
|
|
#include "BKE_library.h"
|
|
|
|
|
#include "BKE_main.h"
|
IDManagement: Speedup ID unique name assignment by tracking used names/basenames/suffixes
An implementation of T73412, roughly as outlined there:
Track the names that are in use, as well as base names (before
numeric suffix) plus a bit map for each base name, indicating which
numeric suffixes are already used. This is done per-Main/Library,
per-object-type.
Timings (Windows, VS2022 Release build, AMD Ryzen 5950X):
- Scene with 10k cubes, Shift+D to duplicate them all: 8.7s -> 1.9s.
Name map memory usage for resulting 20k objects: 4.3MB.
- Importing a 2.5GB .obj file of exported Blender 3.0 splash scene
(24k objects), using the new C++ importer: 34.2s-> 22.0s. Name map
memory usage for resulting scene: 8.6MB.
- Importing Disney Moana USD scene (almost half a million objects):
56min -> 10min. Name map usage: ~100MB. Blender crashes later on
when trying to render it, in the same place in both cases, but
that's for another day.
Reviewed By: Bastien Montagne
Differential Revision: https://developer.blender.org/D14162
2022-07-20 14:27:14 +03:00
|
|
|
#include "BKE_main_namemap.h"
|
2020-02-10 17:10:17 +01:00
|
|
|
#include "BKE_packedFile.h"
|
|
|
|
|
|
|
|
|
|
/* Unused currently. */
|
|
|
|
|
// static CLG_LogRef LOG = {.identifier = "bke.library"};
|
|
|
|
|
|
IDManagement: Speedup ID unique name assignment by tracking used names/basenames/suffixes
An implementation of T73412, roughly as outlined there:
Track the names that are in use, as well as base names (before
numeric suffix) plus a bit map for each base name, indicating which
numeric suffixes are already used. This is done per-Main/Library,
per-object-type.
Timings (Windows, VS2022 Release build, AMD Ryzen 5950X):
- Scene with 10k cubes, Shift+D to duplicate them all: 8.7s -> 1.9s.
Name map memory usage for resulting 20k objects: 4.3MB.
- Importing a 2.5GB .obj file of exported Blender 3.0 splash scene
(24k objects), using the new C++ importer: 34.2s-> 22.0s. Name map
memory usage for resulting scene: 8.6MB.
- Importing Disney Moana USD scene (almost half a million objects):
56min -> 10min. Name map usage: ~100MB. Blender crashes later on
when trying to render it, in the same place in both cases, but
that's for another day.
Reviewed By: Bastien Montagne
Differential Revision: https://developer.blender.org/D14162
2022-07-20 14:27:14 +03:00
|
|
|
struct BlendDataReader;
|
|
|
|
|
|
|
|
|
|
static void library_runtime_reset(Library *lib)
|
|
|
|
|
{
|
|
|
|
|
if (lib->runtime.name_map) {
|
|
|
|
|
BKE_main_namemap_destroy(&lib->runtime.name_map);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-06 11:27:29 +01:00
|
|
|
static void library_free_data(ID *id)
|
2020-02-10 17:10:17 +01:00
|
|
|
{
|
2020-03-06 11:27:29 +01:00
|
|
|
Library *library = (Library *)id;
|
IDManagement: Speedup ID unique name assignment by tracking used names/basenames/suffixes
An implementation of T73412, roughly as outlined there:
Track the names that are in use, as well as base names (before
numeric suffix) plus a bit map for each base name, indicating which
numeric suffixes are already used. This is done per-Main/Library,
per-object-type.
Timings (Windows, VS2022 Release build, AMD Ryzen 5950X):
- Scene with 10k cubes, Shift+D to duplicate them all: 8.7s -> 1.9s.
Name map memory usage for resulting 20k objects: 4.3MB.
- Importing a 2.5GB .obj file of exported Blender 3.0 splash scene
(24k objects), using the new C++ importer: 34.2s-> 22.0s. Name map
memory usage for resulting scene: 8.6MB.
- Importing Disney Moana USD scene (almost half a million objects):
56min -> 10min. Name map usage: ~100MB. Blender crashes later on
when trying to render it, in the same place in both cases, but
that's for another day.
Reviewed By: Bastien Montagne
Differential Revision: https://developer.blender.org/D14162
2022-07-20 14:27:14 +03:00
|
|
|
library_runtime_reset(library);
|
2020-03-06 11:27:29 +01:00
|
|
|
if (library->packedfile) {
|
|
|
|
|
BKE_packedfile_free(library->packedfile);
|
2020-02-10 17:10:17 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-12 18:20:49 +02:00
|
|
|
static void library_foreach_id(ID *id, LibraryForeachIDData *data)
|
|
|
|
|
{
|
|
|
|
|
Library *lib = (Library *)id;
|
2021-10-26 10:40:36 +02:00
|
|
|
BKE_LIB_FOREACHID_PROCESS_IDSUPER(data, lib->parent, IDWALK_CB_NEVER_SELF);
|
2020-05-12 18:20:49 +02:00
|
|
|
}
|
|
|
|
|
|
Refactor BKE_bpath module.
The main goal of this refactor is to make BPath module use `IDTypeInfo`,
and move each ID-specific part of the `foreach_path` looper into their
own IDTypeInfo struct, using a new `foreach_path` callback.
Additionally, following improvements/cleanups are included:
* Attempt to get better, more consistent namings.
** In particular, move from `path_visitor` to more standard `foreach_path`.
* Update and extend documentation.
** API doc was moved to header, according to recent discussions on this
topic.
* Remove `BKE_bpath_relocate_visitor` from API, this is specific
callback that belongs in `lib_id.c` user code.
NOTE: This commit is expected to be 100% non-behavioral-change. This
implies that several potential further changes were only noted as
comments (like using a more generic solution for
`lib_id_library_local_paths`, addressing inconsistencies like path of
packed libraries always being skipped, regardless of the
`BKE_BPATH_FOREACH_PATH_SKIP_PACKED` `eBPathForeachFlag` flag value,
etc.).
NOTE: basic unittests were added to master already in
rBdcc500e5a265093bc9cc.
Reviewed By: brecht
Differential Revision: https://developer.blender.org/D13381
2021-11-29 14:20:58 +01:00
|
|
|
static void library_foreach_path(ID *id, BPathForeachPathData *bpath_data)
|
|
|
|
|
{
|
|
|
|
|
Library *lib = (Library *)id;
|
|
|
|
|
|
|
|
|
|
/* FIXME: Find if we should respect #BKE_BPATH_FOREACH_PATH_SKIP_PACKED here, and if not, explain
|
|
|
|
|
* why. */
|
|
|
|
|
if (lib->packedfile !=
|
|
|
|
|
NULL /*&& (bpath_data->flag & BKE_BPATH_FOREACH_PATH_SKIP_PACKED) != 0 */) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (BKE_bpath_foreach_path_fixed_process(bpath_data, lib->filepath)) {
|
|
|
|
|
BKE_library_filepath_set(bpath_data->bmain, lib, lib->filepath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
IDManagement: Speedup ID unique name assignment by tracking used names/basenames/suffixes
An implementation of T73412, roughly as outlined there:
Track the names that are in use, as well as base names (before
numeric suffix) plus a bit map for each base name, indicating which
numeric suffixes are already used. This is done per-Main/Library,
per-object-type.
Timings (Windows, VS2022 Release build, AMD Ryzen 5950X):
- Scene with 10k cubes, Shift+D to duplicate them all: 8.7s -> 1.9s.
Name map memory usage for resulting 20k objects: 4.3MB.
- Importing a 2.5GB .obj file of exported Blender 3.0 splash scene
(24k objects), using the new C++ importer: 34.2s-> 22.0s. Name map
memory usage for resulting scene: 8.6MB.
- Importing Disney Moana USD scene (almost half a million objects):
56min -> 10min. Name map usage: ~100MB. Blender crashes later on
when trying to render it, in the same place in both cases, but
that's for another day.
Reviewed By: Bastien Montagne
Differential Revision: https://developer.blender.org/D14162
2022-07-20 14:27:14 +03:00
|
|
|
static void library_blend_read_data(struct BlendDataReader *UNUSED(reader), ID *id)
|
|
|
|
|
{
|
|
|
|
|
Library *lib = (Library *)id;
|
2022-07-21 16:36:06 +02:00
|
|
|
lib->runtime.name_map = NULL;
|
IDManagement: Speedup ID unique name assignment by tracking used names/basenames/suffixes
An implementation of T73412, roughly as outlined there:
Track the names that are in use, as well as base names (before
numeric suffix) plus a bit map for each base name, indicating which
numeric suffixes are already used. This is done per-Main/Library,
per-object-type.
Timings (Windows, VS2022 Release build, AMD Ryzen 5950X):
- Scene with 10k cubes, Shift+D to duplicate them all: 8.7s -> 1.9s.
Name map memory usage for resulting 20k objects: 4.3MB.
- Importing a 2.5GB .obj file of exported Blender 3.0 splash scene
(24k objects), using the new C++ importer: 34.2s-> 22.0s. Name map
memory usage for resulting scene: 8.6MB.
- Importing Disney Moana USD scene (almost half a million objects):
56min -> 10min. Name map usage: ~100MB. Blender crashes later on
when trying to render it, in the same place in both cases, but
that's for another day.
Reviewed By: Bastien Montagne
Differential Revision: https://developer.blender.org/D14162
2022-07-20 14:27:14 +03:00
|
|
|
}
|
|
|
|
|
|
2020-03-06 11:27:29 +01:00
|
|
|
IDTypeInfo IDType_ID_LI = {
|
|
|
|
|
.id_code = ID_LI,
|
2022-07-13 16:10:03 +02:00
|
|
|
.id_filter = FILTER_ID_LI,
|
2020-03-06 11:27:29 +01:00
|
|
|
.main_listbase_index = INDEX_ID_LI,
|
|
|
|
|
.struct_size = sizeof(Library),
|
|
|
|
|
.name = "Library",
|
|
|
|
|
.name_plural = "libraries",
|
|
|
|
|
.translation_context = BLT_I18NCONTEXT_ID_LIBRARY,
|
2021-09-16 10:50:27 +02:00
|
|
|
.flags = IDTYPE_FLAGS_NO_COPY | IDTYPE_FLAGS_NO_LIBLINKING | IDTYPE_FLAGS_NO_ANIMDATA,
|
2021-11-24 10:32:28 +01:00
|
|
|
.asset_type_info = NULL,
|
2020-03-06 11:27:29 +01:00
|
|
|
|
|
|
|
|
.init_data = NULL,
|
|
|
|
|
.copy_data = NULL,
|
|
|
|
|
.free_data = library_free_data,
|
|
|
|
|
.make_local = NULL,
|
2020-05-12 18:20:49 +02:00
|
|
|
.foreach_id = library_foreach_id,
|
2020-08-28 13:05:48 +02:00
|
|
|
.foreach_cache = NULL,
|
Refactor BKE_bpath module.
The main goal of this refactor is to make BPath module use `IDTypeInfo`,
and move each ID-specific part of the `foreach_path` looper into their
own IDTypeInfo struct, using a new `foreach_path` callback.
Additionally, following improvements/cleanups are included:
* Attempt to get better, more consistent namings.
** In particular, move from `path_visitor` to more standard `foreach_path`.
* Update and extend documentation.
** API doc was moved to header, according to recent discussions on this
topic.
* Remove `BKE_bpath_relocate_visitor` from API, this is specific
callback that belongs in `lib_id.c` user code.
NOTE: This commit is expected to be 100% non-behavioral-change. This
implies that several potential further changes were only noted as
comments (like using a more generic solution for
`lib_id_library_local_paths`, addressing inconsistencies like path of
packed libraries always being skipped, regardless of the
`BKE_BPATH_FOREACH_PATH_SKIP_PACKED` `eBPathForeachFlag` flag value,
etc.).
NOTE: basic unittests were added to master already in
rBdcc500e5a265093bc9cc.
Reviewed By: brecht
Differential Revision: https://developer.blender.org/D13381
2021-11-29 14:20:58 +01:00
|
|
|
.foreach_path = library_foreach_path,
|
2022-09-08 16:32:35 +02:00
|
|
|
.owner_pointer_get = NULL,
|
2020-08-28 13:05:48 +02:00
|
|
|
|
2022-07-21 16:36:06 +02:00
|
|
|
.blend_write = NULL,
|
IDManagement: Speedup ID unique name assignment by tracking used names/basenames/suffixes
An implementation of T73412, roughly as outlined there:
Track the names that are in use, as well as base names (before
numeric suffix) plus a bit map for each base name, indicating which
numeric suffixes are already used. This is done per-Main/Library,
per-object-type.
Timings (Windows, VS2022 Release build, AMD Ryzen 5950X):
- Scene with 10k cubes, Shift+D to duplicate them all: 8.7s -> 1.9s.
Name map memory usage for resulting 20k objects: 4.3MB.
- Importing a 2.5GB .obj file of exported Blender 3.0 splash scene
(24k objects), using the new C++ importer: 34.2s-> 22.0s. Name map
memory usage for resulting scene: 8.6MB.
- Importing Disney Moana USD scene (almost half a million objects):
56min -> 10min. Name map usage: ~100MB. Blender crashes later on
when trying to render it, in the same place in both cases, but
that's for another day.
Reviewed By: Bastien Montagne
Differential Revision: https://developer.blender.org/D14162
2022-07-20 14:27:14 +03:00
|
|
|
.blend_read_data = library_blend_read_data,
|
2020-08-28 13:05:48 +02:00
|
|
|
.blend_read_lib = NULL,
|
|
|
|
|
.blend_read_expand = NULL,
|
2020-11-03 11:39:36 +01:00
|
|
|
|
|
|
|
|
.blend_read_undo_preserve = NULL,
|
2021-01-22 14:52:50 +01:00
|
|
|
|
|
|
|
|
.lib_override_apply_post = NULL,
|
2020-03-06 11:27:29 +01:00
|
|
|
};
|
|
|
|
|
|
2020-02-10 17:10:17 +01:00
|
|
|
void BKE_library_filepath_set(Main *bmain, Library *lib, const char *filepath)
|
|
|
|
|
{
|
|
|
|
|
/* in some cases this is used to update the absolute path from the
|
|
|
|
|
* relative */
|
2020-06-23 09:54:14 +10:00
|
|
|
if (lib->filepath != filepath) {
|
|
|
|
|
BLI_strncpy(lib->filepath, filepath, sizeof(lib->filepath));
|
2020-02-10 17:10:17 +01:00
|
|
|
}
|
|
|
|
|
|
2020-06-23 09:54:07 +10:00
|
|
|
BLI_strncpy(lib->filepath_abs, filepath, sizeof(lib->filepath_abs));
|
2020-02-10 17:10:17 +01:00
|
|
|
|
2020-06-23 09:54:07 +10:00
|
|
|
/* Not essential but set `filepath_abs` is an absolute copy of value which
|
|
|
|
|
* is more useful if its kept in sync. */
|
|
|
|
|
if (BLI_path_is_rel(lib->filepath_abs)) {
|
2023-02-09 11:30:25 +11:00
|
|
|
/* NOTE(@ideasman42): the file may be unsaved, in this case, setting the
|
2020-06-23 09:54:07 +10:00
|
|
|
* `filepath_abs` on an indirectly linked path is not allowed from the
|
2020-02-10 17:10:17 +01:00
|
|
|
* outliner, and its not really supported but allow from here for now
|
2021-07-03 23:08:40 +10:00
|
|
|
* since making local could cause this to be directly linked.
|
2020-02-10 17:10:17 +01:00
|
|
|
*/
|
|
|
|
|
/* Never make paths relative to parent lib - reading code (blenloader) always set *all*
|
2020-06-23 09:54:14 +10:00
|
|
|
* `lib->filepath` relative to current main, not to their parent for indirectly linked ones. */
|
2021-12-14 21:32:14 +11:00
|
|
|
const char *blendfile_path = BKE_main_blendfile_path(bmain);
|
|
|
|
|
BLI_path_abs(lib->filepath_abs, blendfile_path);
|
2020-02-10 17:10:17 +01:00
|
|
|
}
|
|
|
|
|
}
|