2023-05-31 16:19:06 +02:00
|
|
|
/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2018-11-07 16:06:36 +01:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup bke
|
2018-11-07 16:06:36 +01:00
|
|
|
*
|
2019-02-12 01:21:09 +11:00
|
|
|
* Contains management of #Main database itself.
|
2018-11-07 16:06:36 +01:00
|
|
|
*/
|
|
|
|
|
|
2023-07-22 11:27:25 +10:00
|
|
|
#include <cstring>
|
2023-12-01 15:17:55 +01:00
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
|
#include "CLG_log.h"
|
2018-11-07 16:06:36 +01:00
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
|
|
#include "BLI_ghash.h"
|
2025-02-11 16:59:42 +01:00
|
|
|
#include "BLI_listbase.h"
|
2023-12-01 15:17:55 +01:00
|
|
|
#include "BLI_map.hh"
|
2018-11-07 16:06:36 +01:00
|
|
|
#include "BLI_mempool.h"
|
2025-01-28 15:27:34 +01:00
|
|
|
#include "BLI_path_utils.hh"
|
|
|
|
|
#include "BLI_string.h"
|
2018-11-07 16:06:36 +01:00
|
|
|
#include "BLI_threads.h"
|
2023-12-01 15:17:55 +01:00
|
|
|
#include "BLI_vector.hh"
|
2018-11-07 16:06:36 +01:00
|
|
|
|
|
|
|
|
#include "DNA_ID.h"
|
|
|
|
|
|
2024-02-09 19:23:03 +01:00
|
|
|
#include "BKE_bpath.hh"
|
2024-02-10 18:25:14 +01:00
|
|
|
#include "BKE_global.hh"
|
2024-01-20 19:17:36 +01:00
|
|
|
#include "BKE_idtype.hh"
|
2024-01-15 12:44:04 -05:00
|
|
|
#include "BKE_lib_id.hh"
|
2024-01-18 12:20:42 +01:00
|
|
|
#include "BKE_lib_query.hh"
|
2023-12-01 15:17:55 +01:00
|
|
|
#include "BKE_lib_remap.hh"
|
2025-02-07 17:47:16 +01:00
|
|
|
#include "BKE_library.hh"
|
2023-12-01 19:43:16 +01:00
|
|
|
#include "BKE_main.hh"
|
2023-11-27 16:21:49 +01:00
|
|
|
#include "BKE_main_idmap.hh"
|
|
|
|
|
#include "BKE_main_namemap.hh"
|
2024-02-10 18:34:29 +01:00
|
|
|
#include "BKE_report.hh"
|
2018-11-07 16:06:36 +01:00
|
|
|
|
2024-01-18 22:50:23 +02:00
|
|
|
#include "IMB_imbuf.hh"
|
|
|
|
|
#include "IMB_imbuf_types.hh"
|
2018-11-07 16:06:36 +01:00
|
|
|
|
2024-02-13 15:36:38 +01:00
|
|
|
using namespace blender::bke;
|
|
|
|
|
|
2023-12-01 15:17:55 +01:00
|
|
|
static CLG_LogRef LOG = {"bke.main"};
|
|
|
|
|
|
2023-07-18 14:18:07 +10:00
|
|
|
Main *BKE_main_new()
|
2018-11-07 16:06:36 +01:00
|
|
|
{
|
2023-07-17 10:46:26 +02:00
|
|
|
Main *bmain = static_cast<Main *>(MEM_callocN(sizeof(Main), "new main"));
|
2024-07-01 14:21:06 +02:00
|
|
|
BKE_main_init(*bmain);
|
|
|
|
|
return bmain;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_main_init(Main &bmain)
|
|
|
|
|
{
|
|
|
|
|
bmain.lock = static_cast<MainLock *>(MEM_mallocN(sizeof(SpinLock), "main lock"));
|
|
|
|
|
BLI_spin_init(reinterpret_cast<SpinLock *>(bmain.lock));
|
|
|
|
|
bmain.is_global_main = false;
|
2024-06-13 14:27:36 +02:00
|
|
|
|
2024-07-05 16:59:34 +02:00
|
|
|
/* Just rebuilding the Action Slot to ID* map once is likely cheaper than,
|
2024-06-13 14:27:36 +02:00
|
|
|
* for every ID, when it's loaded from disk, check whether it's animated or
|
|
|
|
|
* not, and then figure out which Main it went into, and then set the flag. */
|
2024-07-05 16:59:34 +02:00
|
|
|
bmain.is_action_slot_to_id_map_dirty = true;
|
2018-11-07 16:06:36 +01:00
|
|
|
}
|
|
|
|
|
|
2024-07-01 14:21:06 +02:00
|
|
|
void BKE_main_clear(Main &bmain)
|
2018-11-07 16:06:36 +01:00
|
|
|
{
|
2024-07-01 14:21:06 +02:00
|
|
|
/* Also call when reading a file, erase all, etc */
|
2018-11-07 16:06:36 +01:00
|
|
|
|
2024-07-01 14:21:06 +02:00
|
|
|
/* Since we are removing whole main, no need to bother 'properly' (and slowly) removing each ID
|
|
|
|
|
* from it. */
|
2019-01-16 11:39:30 +01:00
|
|
|
const int free_flag = (LIB_ID_FREE_NO_MAIN | LIB_ID_FREE_NO_UI_USER |
|
|
|
|
|
LIB_ID_FREE_NO_USER_REFCOUNT | LIB_ID_FREE_NO_DEG_TAG);
|
2019-01-14 16:15:15 +01:00
|
|
|
|
2024-07-01 14:21:06 +02:00
|
|
|
MEM_SAFE_FREE(bmain.blen_thumb);
|
2018-11-07 16:06:36 +01:00
|
|
|
|
2025-02-11 17:46:07 +01:00
|
|
|
MainListsArray lbarray = BKE_main_lists_get(bmain);
|
|
|
|
|
int a = lbarray.size();
|
2018-11-07 16:06:36 +01:00
|
|
|
while (a--) {
|
|
|
|
|
ListBase *lb = lbarray[a];
|
2019-01-14 16:15:15 +01:00
|
|
|
ID *id, *id_next;
|
2018-11-07 16:06:36 +01:00
|
|
|
|
2023-07-17 10:46:26 +02:00
|
|
|
for (id = static_cast<ID *>(lb->first); id != nullptr; id = id_next) {
|
|
|
|
|
id_next = static_cast<ID *>(id->next);
|
2018-11-07 16:06:36 +01:00
|
|
|
#if 1
|
2024-07-01 14:21:06 +02:00
|
|
|
BKE_id_free_ex(&bmain, id, free_flag, false);
|
2018-11-07 16:06:36 +01:00
|
|
|
#else
|
2023-05-31 13:22:48 +10:00
|
|
|
/* Errors freeing ID's can be hard to track down,
|
|
|
|
|
* enable this so VALGRIND or ASAN will give the line number in its error log. */
|
|
|
|
|
|
|
|
|
|
# define CASE_ID_INDEX(id_index) \
|
|
|
|
|
case id_index: \
|
2024-07-01 14:21:06 +02:00
|
|
|
BKE_id_free_ex(&bmain, id, free_flag, false); \
|
2023-05-31 13:22:48 +10:00
|
|
|
break
|
|
|
|
|
|
|
|
|
|
switch ((eID_Index)a) {
|
|
|
|
|
CASE_ID_INDEX(INDEX_ID_LI);
|
|
|
|
|
CASE_ID_INDEX(INDEX_ID_IP);
|
|
|
|
|
CASE_ID_INDEX(INDEX_ID_AC);
|
|
|
|
|
CASE_ID_INDEX(INDEX_ID_GD_LEGACY);
|
|
|
|
|
CASE_ID_INDEX(INDEX_ID_NT);
|
|
|
|
|
CASE_ID_INDEX(INDEX_ID_VF);
|
|
|
|
|
CASE_ID_INDEX(INDEX_ID_TXT);
|
|
|
|
|
CASE_ID_INDEX(INDEX_ID_SO);
|
|
|
|
|
CASE_ID_INDEX(INDEX_ID_MSK);
|
|
|
|
|
CASE_ID_INDEX(INDEX_ID_IM);
|
|
|
|
|
CASE_ID_INDEX(INDEX_ID_MC);
|
|
|
|
|
CASE_ID_INDEX(INDEX_ID_TE);
|
|
|
|
|
CASE_ID_INDEX(INDEX_ID_MA);
|
|
|
|
|
CASE_ID_INDEX(INDEX_ID_LS);
|
|
|
|
|
CASE_ID_INDEX(INDEX_ID_WO);
|
|
|
|
|
CASE_ID_INDEX(INDEX_ID_CF);
|
|
|
|
|
CASE_ID_INDEX(INDEX_ID_SIM);
|
|
|
|
|
CASE_ID_INDEX(INDEX_ID_PA);
|
|
|
|
|
CASE_ID_INDEX(INDEX_ID_KE);
|
|
|
|
|
CASE_ID_INDEX(INDEX_ID_AR);
|
|
|
|
|
CASE_ID_INDEX(INDEX_ID_ME);
|
|
|
|
|
CASE_ID_INDEX(INDEX_ID_CU_LEGACY);
|
|
|
|
|
CASE_ID_INDEX(INDEX_ID_MB);
|
|
|
|
|
CASE_ID_INDEX(INDEX_ID_CV);
|
|
|
|
|
CASE_ID_INDEX(INDEX_ID_PT);
|
|
|
|
|
CASE_ID_INDEX(INDEX_ID_VO);
|
|
|
|
|
CASE_ID_INDEX(INDEX_ID_LT);
|
|
|
|
|
CASE_ID_INDEX(INDEX_ID_LA);
|
|
|
|
|
CASE_ID_INDEX(INDEX_ID_CA);
|
|
|
|
|
CASE_ID_INDEX(INDEX_ID_SPK);
|
|
|
|
|
CASE_ID_INDEX(INDEX_ID_LP);
|
|
|
|
|
CASE_ID_INDEX(INDEX_ID_OB);
|
|
|
|
|
CASE_ID_INDEX(INDEX_ID_GR);
|
|
|
|
|
CASE_ID_INDEX(INDEX_ID_PAL);
|
|
|
|
|
CASE_ID_INDEX(INDEX_ID_PC);
|
|
|
|
|
CASE_ID_INDEX(INDEX_ID_BR);
|
|
|
|
|
CASE_ID_INDEX(INDEX_ID_SCE);
|
|
|
|
|
CASE_ID_INDEX(INDEX_ID_SCR);
|
|
|
|
|
CASE_ID_INDEX(INDEX_ID_WS);
|
|
|
|
|
CASE_ID_INDEX(INDEX_ID_WM);
|
|
|
|
|
case INDEX_ID_NULL: {
|
2021-03-24 12:38:08 +11:00
|
|
|
BLI_assert_unreachable();
|
2018-11-07 16:06:36 +01:00
|
|
|
break;
|
2023-05-31 13:22:48 +10:00
|
|
|
}
|
2018-11-07 16:06:36 +01:00
|
|
|
}
|
2023-05-31 13:22:48 +10:00
|
|
|
|
|
|
|
|
# undef CASE_ID_INDEX
|
|
|
|
|
|
2018-11-07 16:06:36 +01:00
|
|
|
#endif
|
|
|
|
|
}
|
2019-01-14 16:15:15 +01:00
|
|
|
BLI_listbase_clear(lb);
|
2018-11-07 16:06:36 +01:00
|
|
|
}
|
|
|
|
|
|
2024-07-01 14:21:06 +02:00
|
|
|
if (bmain.relations) {
|
|
|
|
|
BKE_main_relations_free(&bmain);
|
2018-11-07 16:06:36 +01:00
|
|
|
}
|
|
|
|
|
|
2024-07-01 14:21:06 +02:00
|
|
|
if (bmain.id_map) {
|
|
|
|
|
BKE_main_idmap_destroy(bmain.id_map);
|
2021-06-30 15:19:35 +02:00
|
|
|
}
|
|
|
|
|
|
2023-02-06 19:36:02 +01:00
|
|
|
/* NOTE: `name_map` in libraries are freed together with the library IDs above. */
|
2024-07-01 14:21:06 +02:00
|
|
|
if (bmain.name_map) {
|
|
|
|
|
BKE_main_namemap_destroy(&bmain.name_map);
|
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
|
|
|
}
|
2024-07-01 14:21:06 +02:00
|
|
|
if (bmain.name_map_global) {
|
|
|
|
|
BKE_main_namemap_destroy(&bmain.name_map_global);
|
2023-07-08 16:16:49 +02:00
|
|
|
}
|
2024-07-01 14:21:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_main_destroy(Main &bmain)
|
|
|
|
|
{
|
|
|
|
|
BKE_main_clear(bmain);
|
|
|
|
|
|
|
|
|
|
BLI_spin_end(reinterpret_cast<SpinLock *>(bmain.lock));
|
2025-02-20 10:37:10 +01:00
|
|
|
MEM_freeN(static_cast<void *>(bmain.lock));
|
2024-07-01 14:21:06 +02:00
|
|
|
bmain.lock = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_main_free(Main *bmain)
|
|
|
|
|
{
|
|
|
|
|
/* In case this is called on a 'split-by-libraries' list of mains.
|
|
|
|
|
*
|
|
|
|
|
* Should not happen in typical usages, but can occur e.g. if a file reading is aborted. */
|
|
|
|
|
if (bmain->next) {
|
|
|
|
|
BKE_main_free(bmain->next);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Include this check here as the path may be manipulated after creation. */
|
|
|
|
|
BLI_assert_msg(!(bmain->filepath[0] == '/' && bmain->filepath[1] == '/'),
|
|
|
|
|
"'.blend' relative \"//\" must not be used in Main!");
|
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
|
|
|
|
2024-07-01 14:21:06 +02:00
|
|
|
BKE_main_destroy(*bmain);
|
|
|
|
|
MEM_freeN(bmain);
|
2018-11-07 16:06:36 +01:00
|
|
|
}
|
|
|
|
|
|
2023-12-01 15:17:55 +01:00
|
|
|
static bool are_ids_from_different_mains_matching(Main *bmain_1, ID *id_1, Main *bmain_2, ID *id_2)
|
|
|
|
|
{
|
|
|
|
|
/* Both IDs should not be null at the same time.
|
|
|
|
|
*
|
|
|
|
|
* NOTE: E.g. `id_1` may be null, in case `id_2` is a Library ID which path is the filepath of
|
|
|
|
|
* `bmain_1`. */
|
|
|
|
|
BLI_assert(id_1 || id_2);
|
|
|
|
|
|
|
|
|
|
/* Special handling for libraries, since their filepaths is used then, not their ID names.
|
|
|
|
|
*
|
|
|
|
|
* NOTE: In library case, this call should always return true, since given data should always
|
|
|
|
|
* match. The asserts below merely ensure that expected conditions are always met:
|
|
|
|
|
* - A given library absolute filepath should never match its own bmain filepath.
|
|
|
|
|
* - If both given libraries are non-null:
|
|
|
|
|
* - Their absolute filepath should match.
|
|
|
|
|
* - Neither of their absolute filepaths should match any of the bmain filepaths.
|
|
|
|
|
* - If one of the library is null:
|
|
|
|
|
* - The other library should match the bmain filepath of the null library. */
|
|
|
|
|
if ((!id_1 && GS(id_2->name) == ID_LI) || GS(id_1->name) == ID_LI) {
|
|
|
|
|
BLI_assert(!id_1 || !ID_IS_LINKED(id_1));
|
|
|
|
|
BLI_assert(!id_2 || !ID_IS_LINKED(id_2));
|
|
|
|
|
|
|
|
|
|
Library *lib_1 = reinterpret_cast<Library *>(id_1);
|
|
|
|
|
Library *lib_2 = reinterpret_cast<Library *>(id_2);
|
|
|
|
|
|
|
|
|
|
if (lib_1 && lib_2) {
|
2025-02-07 17:47:16 +01:00
|
|
|
BLI_assert(STREQ(lib_1->runtime->filepath_abs, lib_2->runtime->filepath_abs));
|
2023-12-01 15:17:55 +01:00
|
|
|
}
|
|
|
|
|
if (lib_1) {
|
2025-02-07 17:47:16 +01:00
|
|
|
BLI_assert(!STREQ(lib_1->runtime->filepath_abs, bmain_1->filepath));
|
2023-12-01 15:17:55 +01:00
|
|
|
if (lib_2) {
|
2025-02-07 17:47:16 +01:00
|
|
|
BLI_assert(!STREQ(lib_1->runtime->filepath_abs, bmain_2->filepath));
|
2023-12-01 15:17:55 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2025-02-07 17:47:16 +01:00
|
|
|
BLI_assert(STREQ(lib_1->runtime->filepath_abs, bmain_2->filepath));
|
2023-12-01 15:17:55 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (lib_2) {
|
2025-02-07 17:47:16 +01:00
|
|
|
BLI_assert(!STREQ(lib_2->runtime->filepath_abs, bmain_2->filepath));
|
2023-12-01 15:17:55 +01:00
|
|
|
if (lib_1) {
|
2025-02-07 17:47:16 +01:00
|
|
|
BLI_assert(!STREQ(lib_2->runtime->filepath_abs, bmain_1->filepath));
|
2023-12-01 15:17:55 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2025-02-07 17:47:16 +01:00
|
|
|
BLI_assert(STREQ(lib_2->runtime->filepath_abs, bmain_1->filepath));
|
2023-12-01 15:17:55 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Now both IDs are expected to be valid data, and caller is expected to have ensured already
|
|
|
|
|
* that they have the same name. */
|
|
|
|
|
BLI_assert(id_1 && id_2);
|
|
|
|
|
BLI_assert(STREQ(id_1->name, id_2->name));
|
|
|
|
|
|
|
|
|
|
if (!id_1->lib && !id_2->lib) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (id_1->lib && id_2->lib) {
|
|
|
|
|
if (id_1->lib == id_2->lib) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2025-02-07 17:47:16 +01:00
|
|
|
if (STREQ(id_1->lib->runtime->filepath_abs, id_2->lib->runtime->filepath_abs)) {
|
2023-12-01 15:17:55 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* In case one Main is the library of the ID from the other Main. */
|
|
|
|
|
|
|
|
|
|
if (id_1->lib) {
|
2025-02-07 17:47:16 +01:00
|
|
|
if (STREQ(id_1->lib->runtime->filepath_abs, bmain_2->filepath)) {
|
2023-12-01 15:17:55 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (id_2->lib) {
|
2025-02-07 17:47:16 +01:00
|
|
|
if (STREQ(id_2->lib->runtime->filepath_abs, bmain_1->filepath)) {
|
2023-12-01 15:17:55 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BLI_assert_unreachable();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void main_merge_add_id_to_move(Main *bmain_dst,
|
|
|
|
|
blender::Map<std::string, blender::Vector<ID *>> &id_map_dst,
|
|
|
|
|
ID *id_src,
|
2024-02-13 15:36:38 +01:00
|
|
|
id::IDRemapper &id_remapper,
|
2023-12-01 15:17:55 +01:00
|
|
|
blender::Vector<ID *> &ids_to_move,
|
|
|
|
|
const bool is_library,
|
|
|
|
|
MainMergeReport &reports)
|
|
|
|
|
{
|
|
|
|
|
const bool is_id_src_linked(id_src->lib);
|
|
|
|
|
bool is_id_src_from_bmain_dst = false;
|
|
|
|
|
if (is_id_src_linked) {
|
|
|
|
|
BLI_assert(!is_library);
|
2023-12-04 20:33:51 +01:00
|
|
|
UNUSED_VARS_NDEBUG(is_library);
|
2024-04-08 13:08:36 +02:00
|
|
|
blender::Vector<ID *> id_src_lib_dst = id_map_dst.lookup_default(
|
2025-02-07 17:47:16 +01:00
|
|
|
id_src->lib->runtime->filepath_abs, {});
|
2023-12-01 15:17:55 +01:00
|
|
|
/* The current library of the source ID would be remapped to null, which means that it comes
|
|
|
|
|
* from the destination Main. */
|
|
|
|
|
is_id_src_from_bmain_dst = !id_src_lib_dst.is_empty() && !id_src_lib_dst[0];
|
|
|
|
|
}
|
|
|
|
|
std::cout << id_src->name << " is linked from dst Main: " << is_id_src_from_bmain_dst << "\n";
|
|
|
|
|
std::cout.flush();
|
|
|
|
|
|
|
|
|
|
if (is_id_src_from_bmain_dst) {
|
|
|
|
|
/* Do not move an ID supposed to be from `bmain_dst` (used as library in `bmain_src`) into
|
|
|
|
|
* `bmain_src`. Fact that no match was found is worth a warning, although it could happen
|
|
|
|
|
* e.g. in case `bmain_dst` has been updated since it file was loaded as library in
|
|
|
|
|
* `bmain_src`. */
|
|
|
|
|
CLOG_WARN(&LOG,
|
|
|
|
|
"ID '%s' defined in source Main as linked from destination Main (file '%s') not "
|
|
|
|
|
"found in given destination Main",
|
|
|
|
|
id_src->name,
|
|
|
|
|
bmain_dst->filepath);
|
2024-02-13 15:36:38 +01:00
|
|
|
id_remapper.add(id_src, nullptr);
|
2023-12-01 15:17:55 +01:00
|
|
|
reports.num_unknown_ids++;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
ids_to_move.append(id_src);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_main_merge(Main *bmain_dst, Main **r_bmain_src, MainMergeReport &reports)
|
|
|
|
|
{
|
|
|
|
|
Main *bmain_src = *r_bmain_src;
|
2023-12-07 12:15:45 +11:00
|
|
|
/* NOTE: Dedicated mapping type is needed here, to handle properly the library cases. */
|
2023-12-01 15:17:55 +01:00
|
|
|
blender::Map<std::string, blender::Vector<ID *>> id_map_dst;
|
|
|
|
|
ID *id_iter_dst, *id_iter_src;
|
|
|
|
|
FOREACH_MAIN_ID_BEGIN (bmain_dst, id_iter_dst) {
|
|
|
|
|
if (GS(id_iter_dst->name) == ID_LI) {
|
|
|
|
|
/* Libraries need specific handling, as we want to check them by their filepath, not the IDs
|
|
|
|
|
* themselves. */
|
|
|
|
|
Library *lib_dst = reinterpret_cast<Library *>(id_iter_dst);
|
2025-02-07 17:47:16 +01:00
|
|
|
BLI_assert(!id_map_dst.contains(lib_dst->runtime->filepath_abs));
|
|
|
|
|
id_map_dst.add(lib_dst->runtime->filepath_abs, {id_iter_dst});
|
2023-12-01 15:17:55 +01:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
id_map_dst.lookup_or_add(id_iter_dst->name, {}).append(id_iter_dst);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
FOREACH_MAIN_ID_END;
|
|
|
|
|
/* Add the current `bmain_dst` filepath in the mapping as well, as it may be a library of the
|
|
|
|
|
* `bmain_src` Main. */
|
|
|
|
|
id_map_dst.add(bmain_dst->filepath, {nullptr});
|
|
|
|
|
|
|
|
|
|
/* A dedicated remapper for libraries is needed because these need to be remapped _before_ IDs
|
|
|
|
|
* are moved from `bmain_src` to `bmain_dst`, to avoid having to fix naming and ordering of IDs
|
|
|
|
|
* afterwards (especially in case some source linked IDs become local in `bmain_dst`). */
|
2024-02-13 15:36:38 +01:00
|
|
|
id::IDRemapper id_remapper;
|
|
|
|
|
id::IDRemapper id_remapper_libraries;
|
2023-12-01 15:17:55 +01:00
|
|
|
blender::Vector<ID *> ids_to_move;
|
|
|
|
|
|
|
|
|
|
FOREACH_MAIN_ID_BEGIN (bmain_src, id_iter_src) {
|
|
|
|
|
const bool is_library = GS(id_iter_src->name) == ID_LI;
|
|
|
|
|
|
|
|
|
|
blender::Vector<ID *> ids_dst = id_map_dst.lookup_default(
|
2025-02-07 17:47:16 +01:00
|
|
|
is_library ? reinterpret_cast<Library *>(id_iter_src)->runtime->filepath_abs :
|
2024-04-08 13:08:36 +02:00
|
|
|
id_iter_src->name,
|
2023-12-01 15:17:55 +01:00
|
|
|
{});
|
|
|
|
|
if (is_library) {
|
|
|
|
|
BLI_assert(ids_dst.size() <= 1);
|
|
|
|
|
}
|
|
|
|
|
if (ids_dst.is_empty()) {
|
|
|
|
|
main_merge_add_id_to_move(
|
|
|
|
|
bmain_dst, id_map_dst, id_iter_src, id_remapper, ids_to_move, is_library, reports);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool src_has_match_in_dst = false;
|
|
|
|
|
for (ID *id_iter_dst : ids_dst) {
|
|
|
|
|
if (are_ids_from_different_mains_matching(bmain_dst, id_iter_dst, bmain_src, id_iter_src)) {
|
|
|
|
|
/* There should only ever be one potential match, never more. */
|
|
|
|
|
BLI_assert(!src_has_match_in_dst);
|
|
|
|
|
if (!src_has_match_in_dst) {
|
|
|
|
|
if (is_library) {
|
2024-02-13 15:36:38 +01:00
|
|
|
id_remapper_libraries.add(id_iter_src, id_iter_dst);
|
2023-12-01 15:17:55 +01:00
|
|
|
reports.num_remapped_libraries++;
|
|
|
|
|
}
|
|
|
|
|
else {
|
2024-02-13 15:36:38 +01:00
|
|
|
id_remapper.add(id_iter_src, id_iter_dst);
|
2023-12-01 15:17:55 +01:00
|
|
|
reports.num_remapped_ids++;
|
|
|
|
|
}
|
|
|
|
|
src_has_match_in_dst = true;
|
|
|
|
|
}
|
|
|
|
|
#ifdef NDEBUG /* In DEBUG builds, keep looping to ensure there is only one match. */
|
|
|
|
|
break;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!src_has_match_in_dst) {
|
|
|
|
|
main_merge_add_id_to_move(
|
|
|
|
|
bmain_dst, id_map_dst, id_iter_src, id_remapper, ids_to_move, is_library, reports);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
FOREACH_MAIN_ID_END;
|
|
|
|
|
|
|
|
|
|
reports.num_merged_ids = int(ids_to_move.size());
|
|
|
|
|
|
|
|
|
|
/* Rebase relative filepaths in `bmain_src` using `bmain_dst` path as new reference, or make them
|
2024-01-08 11:24:38 +11:00
|
|
|
* absolute if destination bmain has no filepath. */
|
2023-12-01 15:17:55 +01:00
|
|
|
if (bmain_src->filepath[0] != '\0') {
|
|
|
|
|
char dir_src[FILE_MAXDIR];
|
|
|
|
|
BLI_path_split_dir_part(bmain_src->filepath, dir_src, sizeof(dir_src));
|
|
|
|
|
BLI_path_normalize_native(dir_src);
|
|
|
|
|
|
|
|
|
|
if (bmain_dst->filepath[0] != '\0') {
|
|
|
|
|
char dir_dst[FILE_MAXDIR];
|
|
|
|
|
BLI_path_split_dir_part(bmain_dst->filepath, dir_dst, sizeof(dir_dst));
|
|
|
|
|
BLI_path_normalize_native(dir_dst);
|
|
|
|
|
BKE_bpath_relative_rebase(bmain_src, dir_src, dir_dst, reports.reports);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
BKE_bpath_absolute_convert(bmain_src, dir_src, reports.reports);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Libraries need to be remapped before moving IDs into `bmain_dst`, to ensure that the sorting
|
|
|
|
|
* of inserted IDs is correct. Note that no bmain is given here, so this is only a 'raw'
|
|
|
|
|
* remapping. */
|
|
|
|
|
BKE_libblock_relink_multiple(nullptr,
|
|
|
|
|
ids_to_move,
|
|
|
|
|
ID_REMAP_TYPE_REMAP,
|
|
|
|
|
id_remapper_libraries,
|
|
|
|
|
ID_REMAP_DO_LIBRARY_POINTERS);
|
|
|
|
|
|
|
|
|
|
for (ID *id_iter_src : ids_to_move) {
|
|
|
|
|
BKE_libblock_management_main_remove(bmain_src, id_iter_src);
|
|
|
|
|
BKE_libblock_management_main_add(bmain_dst, id_iter_src);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* The other data has to be remapped once all IDs are in `bmain_dst`, to ensure that additional
|
|
|
|
|
* update process (e.g. collection hierarchy handling) happens as expected with the correct set
|
2024-01-08 11:24:38 +11:00
|
|
|
* of data. */
|
2023-12-01 15:17:55 +01:00
|
|
|
BKE_libblock_relink_multiple(bmain_dst, ids_to_move, ID_REMAP_TYPE_REMAP, id_remapper, 0);
|
|
|
|
|
|
|
|
|
|
BKE_reportf(
|
|
|
|
|
reports.reports,
|
|
|
|
|
RPT_INFO,
|
|
|
|
|
"Merged %d IDs from '%s' Main into '%s' Main; %d IDs and %d Libraries already existed as "
|
2023-12-11 00:23:03 +01:00
|
|
|
"part of the destination Main, and %d IDs missing from destination Main, were freed "
|
|
|
|
|
"together with the source Main",
|
2023-12-01 15:17:55 +01:00
|
|
|
reports.num_merged_ids,
|
|
|
|
|
bmain_src->filepath,
|
|
|
|
|
bmain_dst->filepath,
|
|
|
|
|
reports.num_remapped_ids,
|
|
|
|
|
reports.num_remapped_libraries,
|
|
|
|
|
reports.num_unknown_ids);
|
|
|
|
|
|
|
|
|
|
/* Remapping above may have made some IDs local. So namemap needs to be cleared, and moved IDs
|
|
|
|
|
* need to be re-sorted. */
|
|
|
|
|
BKE_main_namemap_clear(bmain_dst);
|
|
|
|
|
|
|
|
|
|
BLI_assert(BKE_main_namemap_validate(bmain_dst));
|
|
|
|
|
|
|
|
|
|
BKE_main_free(bmain_src);
|
|
|
|
|
*r_bmain_src = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-03 08:36:28 +10:00
|
|
|
bool BKE_main_is_empty(Main *bmain)
|
2021-10-06 16:41:08 +02:00
|
|
|
{
|
2023-09-14 11:45:04 +10:00
|
|
|
bool result = true;
|
2021-10-06 16:41:08 +02:00
|
|
|
ID *id_iter;
|
|
|
|
|
FOREACH_MAIN_ID_BEGIN (bmain, id_iter) {
|
2023-09-14 11:45:04 +10:00
|
|
|
result = false;
|
|
|
|
|
break;
|
2021-10-06 16:41:08 +02:00
|
|
|
}
|
|
|
|
|
FOREACH_MAIN_ID_END;
|
2023-09-14 11:45:04 +10:00
|
|
|
return result;
|
2021-10-06 16:41:08 +02:00
|
|
|
}
|
|
|
|
|
|
2024-07-06 21:42:49 +02:00
|
|
|
bool BKE_main_has_issues(const Main *bmain)
|
|
|
|
|
{
|
|
|
|
|
return bmain->has_forward_compatibility_issues || bmain->is_asset_edit_file;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool BKE_main_needs_overwrite_confirm(const Main *bmain)
|
|
|
|
|
{
|
|
|
|
|
return bmain->has_forward_compatibility_issues || bmain->is_asset_edit_file;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-03 08:36:28 +10:00
|
|
|
void BKE_main_lock(Main *bmain)
|
2018-11-07 16:06:36 +01:00
|
|
|
{
|
|
|
|
|
BLI_spin_lock((SpinLock *)bmain->lock);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-03 08:36:28 +10:00
|
|
|
void BKE_main_unlock(Main *bmain)
|
2018-11-07 16:06:36 +01:00
|
|
|
{
|
|
|
|
|
BLI_spin_unlock((SpinLock *)bmain->lock);
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-13 12:56:10 +01:00
|
|
|
static int main_relations_create_idlink_cb(LibraryIDLinkCallbackData *cb_data)
|
2018-11-07 16:06:36 +01:00
|
|
|
{
|
2023-07-17 10:46:26 +02:00
|
|
|
MainIDRelations *bmain_relations = static_cast<MainIDRelations *>(cb_data->user_data);
|
2023-05-16 18:14:43 +02:00
|
|
|
ID *self_id = cb_data->self_id;
|
2020-02-13 12:56:10 +01:00
|
|
|
ID **id_pointer = cb_data->id_pointer;
|
2024-12-12 15:20:22 +01:00
|
|
|
const LibraryForeachIDCallbackFlag cb_flag = cb_data->cb_flag;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-11-07 16:06:36 +01:00
|
|
|
if (*id_pointer) {
|
2021-01-21 14:52:40 +01:00
|
|
|
MainIDRelationsEntry **entry_p;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-05-16 18:14:43 +02:00
|
|
|
/* Add `id_pointer` as child of `self_id`. */
|
2021-01-21 14:52:40 +01:00
|
|
|
{
|
|
|
|
|
if (!BLI_ghash_ensure_p(
|
2024-01-02 18:12:54 +01:00
|
|
|
bmain_relations->relations_from_pointers, self_id, (void ***)&entry_p))
|
|
|
|
|
{
|
2023-07-17 10:46:26 +02:00
|
|
|
*entry_p = static_cast<MainIDRelationsEntry *>(MEM_callocN(sizeof(**entry_p), __func__));
|
2024-01-22 13:47:13 +01:00
|
|
|
(*entry_p)->session_uid = self_id->session_uid;
|
2021-01-21 14:52:40 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2024-01-22 13:47:13 +01:00
|
|
|
BLI_assert((*entry_p)->session_uid == self_id->session_uid);
|
2021-01-21 14:52:40 +01:00
|
|
|
}
|
2023-07-17 10:46:26 +02:00
|
|
|
MainIDRelationsEntryItem *to_id_entry = static_cast<MainIDRelationsEntryItem *>(
|
|
|
|
|
BLI_mempool_alloc(bmain_relations->entry_items_pool));
|
2021-01-21 14:52:40 +01:00
|
|
|
to_id_entry->next = (*entry_p)->to_ids;
|
|
|
|
|
to_id_entry->id_pointer.to = id_pointer;
|
2024-01-22 13:47:13 +01:00
|
|
|
to_id_entry->session_uid = (*id_pointer != nullptr) ? (*id_pointer)->session_uid :
|
|
|
|
|
MAIN_ID_SESSION_UID_UNSET;
|
2021-01-21 14:52:40 +01:00
|
|
|
to_id_entry->usage_flag = cb_flag;
|
|
|
|
|
(*entry_p)->to_ids = to_id_entry;
|
2018-11-07 16:06:36 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-05-16 18:14:43 +02:00
|
|
|
/* Add `self_id` as parent of `id_pointer`. */
|
2023-07-17 10:46:26 +02:00
|
|
|
if (*id_pointer != nullptr) {
|
2021-01-21 14:52:40 +01:00
|
|
|
if (!BLI_ghash_ensure_p(
|
2024-01-02 18:12:54 +01:00
|
|
|
bmain_relations->relations_from_pointers, *id_pointer, (void ***)&entry_p))
|
|
|
|
|
{
|
2023-07-17 10:46:26 +02:00
|
|
|
*entry_p = static_cast<MainIDRelationsEntry *>(MEM_callocN(sizeof(**entry_p), __func__));
|
2024-01-22 13:47:13 +01:00
|
|
|
(*entry_p)->session_uid = (*id_pointer)->session_uid;
|
2021-01-21 14:52:40 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2024-01-22 13:47:13 +01:00
|
|
|
BLI_assert((*entry_p)->session_uid == (*id_pointer)->session_uid);
|
2021-01-21 14:52:40 +01:00
|
|
|
}
|
2023-07-17 10:46:26 +02:00
|
|
|
MainIDRelationsEntryItem *from_id_entry = static_cast<MainIDRelationsEntryItem *>(
|
|
|
|
|
BLI_mempool_alloc(bmain_relations->entry_items_pool));
|
2021-01-21 14:52:40 +01:00
|
|
|
from_id_entry->next = (*entry_p)->from_ids;
|
2023-05-16 18:14:43 +02:00
|
|
|
from_id_entry->id_pointer.from = self_id;
|
2024-01-22 13:47:13 +01:00
|
|
|
from_id_entry->session_uid = self_id->session_uid;
|
2021-01-21 14:52:40 +01:00
|
|
|
from_id_entry->usage_flag = cb_flag;
|
|
|
|
|
(*entry_p)->from_ids = from_id_entry;
|
2018-11-07 16:06:36 +01:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-11-07 16:06:36 +01:00
|
|
|
return IDWALK_RET_NOP;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-18 11:21:34 +01:00
|
|
|
void BKE_main_relations_create(Main *bmain, const short flag)
|
2018-11-07 16:06:36 +01:00
|
|
|
{
|
2023-07-17 10:46:26 +02:00
|
|
|
if (bmain->relations != nullptr) {
|
2018-11-07 16:06:36 +01:00
|
|
|
BKE_main_relations_free(bmain);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-07-17 10:46:26 +02:00
|
|
|
bmain->relations = static_cast<MainIDRelations *>(
|
|
|
|
|
MEM_mallocN(sizeof(*bmain->relations), __func__));
|
2021-01-21 14:52:40 +01:00
|
|
|
bmain->relations->relations_from_pointers = BLI_ghash_new(
|
2018-11-07 16:06:36 +01:00
|
|
|
BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, __func__);
|
2021-01-21 14:52:40 +01:00
|
|
|
bmain->relations->entry_items_pool = BLI_mempool_create(
|
|
|
|
|
sizeof(MainIDRelationsEntryItem), 128, 128, BLI_MEMPOOL_NOP);
|
|
|
|
|
|
|
|
|
|
bmain->relations->flag = flag;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-02-14 16:24:49 +01:00
|
|
|
ID *id;
|
2019-04-21 04:40:16 +10:00
|
|
|
FOREACH_MAIN_ID_BEGIN (bmain, id) {
|
2024-12-12 12:43:14 +01:00
|
|
|
const LibraryForeachIDFlag idwalk_flag = IDWALK_READONLY |
|
|
|
|
|
((flag & MAINIDRELATIONS_INCLUDE_UI) != 0 ?
|
|
|
|
|
IDWALK_INCLUDE_UI :
|
|
|
|
|
IDWALK_NOP);
|
2021-01-22 17:35:47 +01:00
|
|
|
|
|
|
|
|
/* Ensure all IDs do have an entry, even if they are not connected to any other. */
|
|
|
|
|
MainIDRelationsEntry **entry_p;
|
|
|
|
|
if (!BLI_ghash_ensure_p(bmain->relations->relations_from_pointers, id, (void ***)&entry_p)) {
|
2023-07-17 10:46:26 +02:00
|
|
|
*entry_p = static_cast<MainIDRelationsEntry *>(MEM_callocN(sizeof(**entry_p), __func__));
|
2024-01-22 13:47:13 +01:00
|
|
|
(*entry_p)->session_uid = id->session_uid;
|
2021-01-22 17:35:47 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2024-01-22 13:47:13 +01:00
|
|
|
BLI_assert((*entry_p)->session_uid == id->session_uid);
|
2021-01-22 17:35:47 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-14 16:24:49 +01:00
|
|
|
BKE_library_foreach_ID_link(
|
2023-07-17 10:46:26 +02:00
|
|
|
nullptr, id, main_relations_create_idlink_cb, bmain->relations, idwalk_flag);
|
2019-02-14 16:24:49 +01:00
|
|
|
}
|
|
|
|
|
FOREACH_MAIN_ID_END;
|
2018-11-07 16:06:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_main_relations_free(Main *bmain)
|
|
|
|
|
{
|
2023-07-17 10:46:26 +02:00
|
|
|
if (bmain->relations != nullptr) {
|
|
|
|
|
if (bmain->relations->relations_from_pointers != nullptr) {
|
|
|
|
|
BLI_ghash_free(bmain->relations->relations_from_pointers, nullptr, MEM_freeN);
|
2018-11-07 16:06:36 +01:00
|
|
|
}
|
2021-01-21 14:52:40 +01:00
|
|
|
BLI_mempool_destroy(bmain->relations->entry_items_pool);
|
2018-11-07 16:06:36 +01:00
|
|
|
MEM_freeN(bmain->relations);
|
2023-07-17 10:46:26 +02:00
|
|
|
bmain->relations = nullptr;
|
2018-11-07 16:06:36 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-03 08:36:28 +10:00
|
|
|
void BKE_main_relations_tag_set(Main *bmain, const eMainIDRelationsEntryTags tag, const bool value)
|
2021-02-02 17:26:30 +01:00
|
|
|
{
|
2023-07-17 10:46:26 +02:00
|
|
|
if (bmain->relations == nullptr) {
|
2021-02-02 17:26:30 +01:00
|
|
|
return;
|
|
|
|
|
}
|
2021-02-09 21:38:57 +01:00
|
|
|
|
|
|
|
|
GHashIterator *gh_iter;
|
|
|
|
|
for (gh_iter = BLI_ghashIterator_new(bmain->relations->relations_from_pointers);
|
2021-02-02 17:26:30 +01:00
|
|
|
!BLI_ghashIterator_done(gh_iter);
|
|
|
|
|
BLI_ghashIterator_step(gh_iter))
|
|
|
|
|
{
|
2023-07-17 10:46:26 +02:00
|
|
|
MainIDRelationsEntry *entry = static_cast<MainIDRelationsEntry *>(
|
|
|
|
|
BLI_ghashIterator_getValue(gh_iter));
|
2021-02-02 17:26:30 +01:00
|
|
|
if (value) {
|
|
|
|
|
entry->tags |= tag;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
entry->tags &= ~tag;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-02-09 21:38:57 +01:00
|
|
|
BLI_ghashIterator_free(gh_iter);
|
2021-02-02 17:26:30 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-08 18:44:37 +01:00
|
|
|
GSet *BKE_main_gset_create(Main *bmain, GSet *gset)
|
|
|
|
|
{
|
2023-07-17 10:46:26 +02:00
|
|
|
if (gset == nullptr) {
|
2019-02-08 18:44:37 +01:00
|
|
|
gset = BLI_gset_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, __func__);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-02-14 16:24:49 +01:00
|
|
|
ID *id;
|
2019-04-21 04:40:16 +10:00
|
|
|
FOREACH_MAIN_ID_BEGIN (bmain, id) {
|
2019-02-14 16:24:49 +01:00
|
|
|
BLI_gset_add(gset, id);
|
2019-02-07 17:16:15 +01:00
|
|
|
}
|
2019-02-14 16:24:49 +01:00
|
|
|
FOREACH_MAIN_ID_END;
|
|
|
|
|
return gset;
|
2019-02-07 17:16:15 +01:00
|
|
|
}
|
|
|
|
|
|
2021-09-17 16:22:29 +02:00
|
|
|
/* Utils for ID's library weak reference API. */
|
2023-07-17 10:46:26 +02:00
|
|
|
struct LibWeakRefKey {
|
2021-09-17 16:22:29 +02:00
|
|
|
char filepath[FILE_MAX];
|
|
|
|
|
char id_name[MAX_ID_NAME];
|
|
|
|
|
|
2024-07-11 18:43:35 +02:00
|
|
|
LibWeakRefKey(const char *lib_path, const char *id_name)
|
|
|
|
|
{
|
|
|
|
|
STRNCPY(this->filepath, lib_path);
|
|
|
|
|
STRNCPY(this->id_name, id_name);
|
2021-09-17 16:22:29 +02:00
|
|
|
}
|
|
|
|
|
|
2024-07-11 18:43:35 +02:00
|
|
|
friend bool operator==(const LibWeakRefKey &a, const LibWeakRefKey &b)
|
|
|
|
|
{
|
|
|
|
|
return STREQ(a.filepath, b.filepath) && STREQ(a.id_name, b.id_name);
|
|
|
|
|
}
|
2021-09-17 16:22:29 +02:00
|
|
|
|
2024-07-11 18:43:35 +02:00
|
|
|
uint64_t hash() const
|
|
|
|
|
{
|
|
|
|
|
return blender::get_default_hash(blender::StringRef(this->filepath),
|
|
|
|
|
blender::StringRef(this->id_name));
|
|
|
|
|
}
|
|
|
|
|
};
|
2021-09-17 16:22:29 +02:00
|
|
|
|
2024-07-11 18:43:35 +02:00
|
|
|
struct MainLibraryWeakReferenceMap {
|
|
|
|
|
blender::Map<LibWeakRefKey, ID *> map;
|
|
|
|
|
};
|
2021-09-17 16:22:29 +02:00
|
|
|
|
2024-07-11 18:43:35 +02:00
|
|
|
MainLibraryWeakReferenceMap *BKE_main_library_weak_reference_create(Main *bmain)
|
2021-09-17 16:22:29 +02:00
|
|
|
{
|
2024-07-11 18:43:35 +02:00
|
|
|
auto *library_weak_reference_mapping = MEM_new<MainLibraryWeakReferenceMap>(__func__);
|
2021-09-17 16:22:29 +02:00
|
|
|
|
|
|
|
|
ListBase *lb;
|
|
|
|
|
FOREACH_MAIN_LISTBASE_BEGIN (bmain, lb) {
|
2023-07-17 10:46:26 +02:00
|
|
|
ID *id_iter = static_cast<ID *>(lb->first);
|
|
|
|
|
if (id_iter == nullptr) {
|
2021-09-17 16:22:29 +02:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (!BKE_idtype_idcode_append_is_reusable(GS(id_iter->name))) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
BLI_assert(BKE_idtype_idcode_is_linkable(GS(id_iter->name)));
|
|
|
|
|
|
|
|
|
|
FOREACH_MAIN_LISTBASE_ID_BEGIN (lb, id_iter) {
|
2023-07-17 10:46:26 +02:00
|
|
|
if (id_iter->library_weak_reference == nullptr) {
|
2021-09-17 16:22:29 +02:00
|
|
|
continue;
|
|
|
|
|
}
|
2024-07-11 18:43:35 +02:00
|
|
|
const LibWeakRefKey key{id_iter->library_weak_reference->library_filepath,
|
|
|
|
|
id_iter->library_weak_reference->library_id_name};
|
|
|
|
|
library_weak_reference_mapping->map.add(key, id_iter);
|
2021-09-17 16:22:29 +02:00
|
|
|
}
|
|
|
|
|
FOREACH_MAIN_LISTBASE_ID_END;
|
|
|
|
|
}
|
|
|
|
|
FOREACH_MAIN_LISTBASE_END;
|
|
|
|
|
|
|
|
|
|
return library_weak_reference_mapping;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-11 18:43:35 +02:00
|
|
|
void BKE_main_library_weak_reference_destroy(
|
|
|
|
|
MainLibraryWeakReferenceMap *library_weak_reference_mapping)
|
2021-09-17 16:22:29 +02:00
|
|
|
{
|
2024-07-11 18:43:35 +02:00
|
|
|
MEM_delete(library_weak_reference_mapping);
|
2021-09-17 16:22:29 +02:00
|
|
|
}
|
|
|
|
|
|
2024-07-11 18:43:35 +02:00
|
|
|
ID *BKE_main_library_weak_reference_search_item(
|
|
|
|
|
MainLibraryWeakReferenceMap *library_weak_reference_mapping,
|
|
|
|
|
const char *library_filepath,
|
|
|
|
|
const char *library_id_name)
|
2021-09-17 16:22:29 +02:00
|
|
|
{
|
2024-07-11 18:43:35 +02:00
|
|
|
const LibWeakRefKey key{library_filepath, library_id_name};
|
|
|
|
|
return library_weak_reference_mapping->map.lookup_default(key, nullptr);
|
2021-09-17 16:22:29 +02:00
|
|
|
}
|
|
|
|
|
|
2024-07-11 18:43:35 +02:00
|
|
|
void BKE_main_library_weak_reference_add_item(
|
|
|
|
|
MainLibraryWeakReferenceMap *library_weak_reference_mapping,
|
|
|
|
|
const char *library_filepath,
|
|
|
|
|
const char *library_id_name,
|
|
|
|
|
ID *new_id)
|
2021-09-17 16:22:29 +02:00
|
|
|
{
|
|
|
|
|
BLI_assert(GS(library_id_name) == GS(new_id->name));
|
2023-07-17 10:46:26 +02:00
|
|
|
BLI_assert(new_id->library_weak_reference == nullptr);
|
2021-09-17 16:22:29 +02:00
|
|
|
BLI_assert(BKE_idtype_idcode_append_is_reusable(GS(new_id->name)));
|
|
|
|
|
|
2024-07-11 18:43:35 +02:00
|
|
|
const LibWeakRefKey key{library_filepath, library_id_name};
|
|
|
|
|
library_weak_reference_mapping->map.add_new(key, new_id);
|
2021-09-17 16:22:29 +02:00
|
|
|
|
2025-02-07 12:28:56 +01:00
|
|
|
BKE_main_library_weak_reference_add(new_id, library_filepath, library_id_name);
|
2021-09-17 16:22:29 +02:00
|
|
|
}
|
|
|
|
|
|
2024-07-11 18:43:35 +02:00
|
|
|
void BKE_main_library_weak_reference_update_item(
|
|
|
|
|
MainLibraryWeakReferenceMap *library_weak_reference_mapping,
|
|
|
|
|
const char *library_filepath,
|
|
|
|
|
const char *library_id_name,
|
|
|
|
|
ID *old_id,
|
|
|
|
|
ID *new_id)
|
2021-09-17 16:22:29 +02:00
|
|
|
{
|
|
|
|
|
BLI_assert(GS(library_id_name) == GS(old_id->name));
|
|
|
|
|
BLI_assert(GS(library_id_name) == GS(new_id->name));
|
2023-07-17 10:46:26 +02:00
|
|
|
BLI_assert(old_id->library_weak_reference != nullptr);
|
|
|
|
|
BLI_assert(new_id->library_weak_reference == nullptr);
|
2021-09-17 16:22:29 +02:00
|
|
|
BLI_assert(STREQ(old_id->library_weak_reference->library_filepath, library_filepath));
|
|
|
|
|
BLI_assert(STREQ(old_id->library_weak_reference->library_id_name, library_id_name));
|
|
|
|
|
|
2024-07-11 18:43:35 +02:00
|
|
|
const LibWeakRefKey key{library_filepath, library_id_name};
|
|
|
|
|
BLI_assert(library_weak_reference_mapping->map.lookup(key) == old_id);
|
|
|
|
|
library_weak_reference_mapping->map.add_overwrite(key, new_id);
|
2021-09-17 16:22:29 +02:00
|
|
|
|
|
|
|
|
new_id->library_weak_reference = old_id->library_weak_reference;
|
2023-07-17 10:46:26 +02:00
|
|
|
old_id->library_weak_reference = nullptr;
|
2021-09-17 16:22:29 +02:00
|
|
|
}
|
|
|
|
|
|
2024-07-11 18:43:35 +02:00
|
|
|
void BKE_main_library_weak_reference_remove_item(
|
|
|
|
|
MainLibraryWeakReferenceMap *library_weak_reference_mapping,
|
|
|
|
|
const char *library_filepath,
|
|
|
|
|
const char *library_id_name,
|
|
|
|
|
ID *old_id)
|
2021-09-17 16:22:29 +02:00
|
|
|
{
|
|
|
|
|
BLI_assert(GS(library_id_name) == GS(old_id->name));
|
2023-07-17 10:46:26 +02:00
|
|
|
BLI_assert(old_id->library_weak_reference != nullptr);
|
2021-09-17 16:22:29 +02:00
|
|
|
|
2024-07-11 18:43:35 +02:00
|
|
|
const LibWeakRefKey key{library_filepath, library_id_name};
|
2021-09-17 16:22:29 +02:00
|
|
|
|
2024-07-11 18:43:35 +02:00
|
|
|
BLI_assert(library_weak_reference_mapping->map.lookup(key) == old_id);
|
|
|
|
|
library_weak_reference_mapping->map.remove(key);
|
2021-09-17 16:22:29 +02:00
|
|
|
|
|
|
|
|
MEM_SAFE_FREE(old_id->library_weak_reference);
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-07 12:28:56 +01:00
|
|
|
ID *BKE_main_library_weak_reference_find(Main *bmain,
|
|
|
|
|
const char *library_filepath,
|
|
|
|
|
const char *library_id_name)
|
|
|
|
|
{
|
|
|
|
|
ListBase *id_list = which_libbase(bmain, GS(library_id_name));
|
|
|
|
|
LISTBASE_FOREACH (ID *, existing_id, id_list) {
|
|
|
|
|
if (existing_id->library_weak_reference &&
|
|
|
|
|
STREQ(existing_id->library_weak_reference->library_id_name, library_id_name) &&
|
|
|
|
|
STREQ(existing_id->library_weak_reference->library_filepath, library_filepath))
|
|
|
|
|
{
|
|
|
|
|
return existing_id;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_main_library_weak_reference_add(ID *local_id,
|
|
|
|
|
const char *library_filepath,
|
|
|
|
|
const char *library_id_name)
|
|
|
|
|
{
|
|
|
|
|
if (local_id->library_weak_reference == nullptr) {
|
|
|
|
|
local_id->library_weak_reference = MEM_cnew<LibraryWeakReference>(__func__);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
STRNCPY(local_id->library_weak_reference->library_filepath, library_filepath);
|
|
|
|
|
STRNCPY(local_id->library_weak_reference->library_id_name, library_id_name);
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-13 11:18:10 +10:00
|
|
|
BlendThumbnail *BKE_main_thumbnail_from_buffer(Main *bmain, const uint8_t *rect, const int size[2])
|
|
|
|
|
{
|
|
|
|
|
BlendThumbnail *data = nullptr;
|
|
|
|
|
|
|
|
|
|
if (bmain) {
|
|
|
|
|
MEM_SAFE_FREE(bmain->blen_thumb);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (rect) {
|
|
|
|
|
const size_t data_size = BLEN_THUMB_MEMSIZE(size[0], size[1]);
|
|
|
|
|
data = static_cast<BlendThumbnail *>(MEM_mallocN(data_size, __func__));
|
|
|
|
|
data->width = size[0];
|
|
|
|
|
data->height = size[1];
|
|
|
|
|
memcpy(data->rect, rect, data_size - sizeof(*data));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (bmain) {
|
|
|
|
|
bmain->blen_thumb = data;
|
|
|
|
|
}
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-07 16:06:36 +01:00
|
|
|
BlendThumbnail *BKE_main_thumbnail_from_imbuf(Main *bmain, ImBuf *img)
|
|
|
|
|
{
|
2023-07-17 10:46:26 +02:00
|
|
|
BlendThumbnail *data = nullptr;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-11-07 16:06:36 +01:00
|
|
|
if (bmain) {
|
|
|
|
|
MEM_SAFE_FREE(bmain->blen_thumb);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-11-07 16:06:36 +01:00
|
|
|
if (img) {
|
2022-05-11 13:37:10 +10:00
|
|
|
const size_t data_size = BLEN_THUMB_MEMSIZE(img->x, img->y);
|
2023-07-17 10:46:26 +02:00
|
|
|
data = static_cast<BlendThumbnail *>(MEM_mallocN(data_size, __func__));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-11-07 16:06:36 +01:00
|
|
|
IMB_rect_from_float(img); /* Just in case... */
|
|
|
|
|
data->width = img->x;
|
|
|
|
|
data->height = img->y;
|
2023-05-18 10:19:01 +02:00
|
|
|
memcpy(data->rect, img->byte_buffer.data, data_size - sizeof(*data));
|
2018-11-07 16:06:36 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-11-07 16:06:36 +01:00
|
|
|
if (bmain) {
|
|
|
|
|
bmain->blen_thumb = data;
|
|
|
|
|
}
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImBuf *BKE_main_thumbnail_to_imbuf(Main *bmain, BlendThumbnail *data)
|
|
|
|
|
{
|
2023-07-17 10:46:26 +02:00
|
|
|
ImBuf *img = nullptr;
|
2018-11-07 16:06:36 +01:00
|
|
|
|
|
|
|
|
if (!data && bmain) {
|
|
|
|
|
data = bmain->blen_thumb;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (data) {
|
2021-09-06 20:04:25 +10:00
|
|
|
img = IMB_allocFromBuffer(
|
2023-07-18 14:18:07 +10:00
|
|
|
(const uint8_t *)data->rect, nullptr, uint(data->width), uint(data->height), 4);
|
2018-11-07 16:06:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return img;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-03 08:36:28 +10:00
|
|
|
void BKE_main_thumbnail_create(Main *bmain)
|
2018-11-07 16:06:36 +01:00
|
|
|
{
|
|
|
|
|
MEM_SAFE_FREE(bmain->blen_thumb);
|
|
|
|
|
|
2023-07-17 10:46:26 +02:00
|
|
|
bmain->blen_thumb = static_cast<BlendThumbnail *>(
|
|
|
|
|
MEM_callocN(BLEN_THUMB_MEMSIZE(BLEN_THUMB_SIZE, BLEN_THUMB_SIZE), __func__));
|
2018-11-07 16:06:36 +01:00
|
|
|
bmain->blen_thumb->width = BLEN_THUMB_SIZE;
|
|
|
|
|
bmain->blen_thumb->height = BLEN_THUMB_SIZE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char *BKE_main_blendfile_path(const Main *bmain)
|
|
|
|
|
{
|
2021-12-13 16:22:19 +11:00
|
|
|
return bmain->filepath;
|
2018-11-07 16:06:36 +01:00
|
|
|
}
|
|
|
|
|
|
2023-07-18 14:18:07 +10:00
|
|
|
const char *BKE_main_blendfile_path_from_global()
|
2018-11-07 16:06:36 +01:00
|
|
|
{
|
|
|
|
|
return BKE_main_blendfile_path(G_MAIN);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ListBase *which_libbase(Main *bmain, short type)
|
|
|
|
|
{
|
|
|
|
|
switch ((ID_Type)type) {
|
|
|
|
|
case ID_SCE:
|
2019-03-08 09:29:17 +11:00
|
|
|
return &(bmain->scenes);
|
2018-11-07 16:06:36 +01:00
|
|
|
case ID_LI:
|
2019-03-08 09:29:17 +11:00
|
|
|
return &(bmain->libraries);
|
2018-11-07 16:06:36 +01:00
|
|
|
case ID_OB:
|
2019-03-08 09:29:17 +11:00
|
|
|
return &(bmain->objects);
|
2018-11-07 16:06:36 +01:00
|
|
|
case ID_ME:
|
2019-03-08 09:29:17 +11:00
|
|
|
return &(bmain->meshes);
|
2022-02-18 09:50:29 -06:00
|
|
|
case ID_CU_LEGACY:
|
2019-03-08 09:29:17 +11:00
|
|
|
return &(bmain->curves);
|
2018-11-07 16:06:36 +01:00
|
|
|
case ID_MB:
|
2019-03-08 09:29:17 +11:00
|
|
|
return &(bmain->metaballs);
|
2018-11-07 16:06:36 +01:00
|
|
|
case ID_MA:
|
2019-03-08 09:29:17 +11:00
|
|
|
return &(bmain->materials);
|
2018-11-07 16:06:36 +01:00
|
|
|
case ID_TE:
|
2019-03-08 09:29:17 +11:00
|
|
|
return &(bmain->textures);
|
2018-11-07 16:06:36 +01:00
|
|
|
case ID_IM:
|
2019-03-08 09:29:17 +11:00
|
|
|
return &(bmain->images);
|
2018-11-07 16:06:36 +01:00
|
|
|
case ID_LT:
|
2019-03-08 09:29:17 +11:00
|
|
|
return &(bmain->lattices);
|
2018-11-07 16:06:36 +01:00
|
|
|
case ID_LA:
|
2019-03-08 09:29:17 +11:00
|
|
|
return &(bmain->lights);
|
2018-11-07 16:06:36 +01:00
|
|
|
case ID_CA:
|
2019-03-08 09:29:17 +11:00
|
|
|
return &(bmain->cameras);
|
2018-11-07 16:06:36 +01:00
|
|
|
case ID_IP:
|
|
|
|
|
return &(bmain->ipo);
|
|
|
|
|
case ID_KE:
|
2019-03-08 09:29:17 +11:00
|
|
|
return &(bmain->shapekeys);
|
2018-11-07 16:06:36 +01:00
|
|
|
case ID_WO:
|
2019-03-08 09:29:17 +11:00
|
|
|
return &(bmain->worlds);
|
2018-11-07 16:06:36 +01:00
|
|
|
case ID_SCR:
|
2019-03-08 09:29:17 +11:00
|
|
|
return &(bmain->screens);
|
2018-11-07 16:06:36 +01:00
|
|
|
case ID_VF:
|
2019-03-08 09:29:17 +11:00
|
|
|
return &(bmain->fonts);
|
2018-11-07 16:06:36 +01:00
|
|
|
case ID_TXT:
|
2019-03-08 09:29:17 +11:00
|
|
|
return &(bmain->texts);
|
2018-11-07 16:06:36 +01:00
|
|
|
case ID_SPK:
|
2019-03-08 09:29:17 +11:00
|
|
|
return &(bmain->speakers);
|
2018-11-07 16:06:36 +01:00
|
|
|
case ID_LP:
|
2019-03-08 09:29:17 +11:00
|
|
|
return &(bmain->lightprobes);
|
2018-11-07 16:06:36 +01:00
|
|
|
case ID_SO:
|
2019-03-08 09:29:17 +11:00
|
|
|
return &(bmain->sounds);
|
2018-11-07 16:06:36 +01:00
|
|
|
case ID_GR:
|
2019-03-08 09:29:17 +11:00
|
|
|
return &(bmain->collections);
|
2018-11-07 16:06:36 +01:00
|
|
|
case ID_AR:
|
2019-03-08 09:29:17 +11:00
|
|
|
return &(bmain->armatures);
|
2018-11-07 16:06:36 +01:00
|
|
|
case ID_AC:
|
2019-03-08 09:29:17 +11:00
|
|
|
return &(bmain->actions);
|
2018-11-07 16:06:36 +01:00
|
|
|
case ID_NT:
|
2019-03-08 09:29:17 +11:00
|
|
|
return &(bmain->nodetrees);
|
2018-11-07 16:06:36 +01:00
|
|
|
case ID_BR:
|
2019-03-08 09:29:17 +11:00
|
|
|
return &(bmain->brushes);
|
2018-11-07 16:06:36 +01:00
|
|
|
case ID_PA:
|
2019-03-08 09:29:17 +11:00
|
|
|
return &(bmain->particles);
|
2018-11-07 16:06:36 +01:00
|
|
|
case ID_WM:
|
|
|
|
|
return &(bmain->wm);
|
2023-03-08 12:35:58 +01:00
|
|
|
case ID_GD_LEGACY:
|
2019-03-08 09:29:17 +11:00
|
|
|
return &(bmain->gpencils);
|
2023-05-30 11:14:16 +02:00
|
|
|
case ID_GP:
|
|
|
|
|
return &(bmain->grease_pencils);
|
2018-11-07 16:06:36 +01:00
|
|
|
case ID_MC:
|
2019-03-08 09:29:17 +11:00
|
|
|
return &(bmain->movieclips);
|
2018-11-07 16:06:36 +01:00
|
|
|
case ID_MSK:
|
2019-03-08 09:29:17 +11:00
|
|
|
return &(bmain->masks);
|
2018-11-07 16:06:36 +01:00
|
|
|
case ID_LS:
|
2019-03-08 09:29:17 +11:00
|
|
|
return &(bmain->linestyles);
|
2018-11-07 16:06:36 +01:00
|
|
|
case ID_PAL:
|
2019-03-08 09:29:17 +11:00
|
|
|
return &(bmain->palettes);
|
2018-11-07 16:06:36 +01:00
|
|
|
case ID_PC:
|
2019-03-08 09:29:17 +11:00
|
|
|
return &(bmain->paintcurves);
|
2018-11-07 16:06:36 +01:00
|
|
|
case ID_CF:
|
2019-03-08 09:29:17 +11:00
|
|
|
return &(bmain->cachefiles);
|
2018-11-07 16:06:36 +01:00
|
|
|
case ID_WS:
|
2019-03-08 09:29:17 +11:00
|
|
|
return &(bmain->workspaces);
|
Curves: Rename "Hair" types, variables, and functions to "Curves"
Based on discussions from T95355 and T94193, the plan is to use
the name "Curves" to describe the data-block container for multiple
curves. Eventually this will replace the existing "Curve" data-block.
However, it will be a while before the curve data-block can be replaced
so in order to distinguish the two curve types in the UI, "Hair Curves"
will be used, but eventually changed back to "Curves".
This patch renames "hair-related" files, functions, types, and variable
names to this convention. A deep rename is preferred to keep code
consistent and to avoid any "hair" terminology from leaking, since the
new data-block is meant for all curve types, not just hair use cases.
The downside of this naming is that the difference between "Curve"
and "Curves" has become important. That was considered during
design discussons and deemed acceptable, especially given the
non-permanent nature of the somewhat common conflict.
Some points of interest:
- All DNA compatibility is lost, just like rBf59767ff9729.
- I renamed `ID_HA` to `ID_CV` so there is no complete mismatch.
- `hair_curves` is used where necessary to distinguish from the
existing "curves" plural.
- I didn't rename any of the cycles/rendering code function names,
since that is also used by the old hair particle system.
Differential Revision: https://developer.blender.org/D14007
2022-02-07 11:55:54 -06:00
|
|
|
case ID_CV:
|
|
|
|
|
return &(bmain->hair_curves);
|
2020-03-17 14:41:48 +01:00
|
|
|
case ID_PT:
|
|
|
|
|
return &(bmain->pointclouds);
|
|
|
|
|
case ID_VO:
|
|
|
|
|
return &(bmain->volumes);
|
2018-11-07 16:06:36 +01:00
|
|
|
}
|
2023-07-17 10:46:26 +02:00
|
|
|
return nullptr;
|
2018-11-07 16:06:36 +01:00
|
|
|
}
|
|
|
|
|
|
2025-02-11 17:46:07 +01:00
|
|
|
MainListsArray BKE_main_lists_get(Main &bmain)
|
2018-11-07 16:06:36 +01:00
|
|
|
{
|
2025-02-11 17:46:07 +01:00
|
|
|
MainListsArray lb{};
|
2019-08-14 23:29:46 +10:00
|
|
|
/* Libraries may be accessed from pretty much any other ID. */
|
2025-02-11 17:46:07 +01:00
|
|
|
lb[INDEX_ID_LI] = &bmain.libraries;
|
2019-08-14 23:29:46 +10:00
|
|
|
|
2025-02-11 17:46:07 +01:00
|
|
|
lb[INDEX_ID_IP] = &bmain.ipo;
|
2019-08-14 23:29:46 +10:00
|
|
|
|
|
|
|
|
/* Moved here to avoid problems when freeing with animato (aligorith). */
|
2025-02-11 17:46:07 +01:00
|
|
|
lb[INDEX_ID_AC] = &bmain.actions;
|
2019-08-14 23:29:46 +10:00
|
|
|
|
2025-02-11 17:46:07 +01:00
|
|
|
lb[INDEX_ID_KE] = &bmain.shapekeys;
|
2019-08-14 23:29:46 +10:00
|
|
|
|
|
|
|
|
/* Referenced by gpencil, so needs to be before that to avoid crashes. */
|
2025-02-11 17:46:07 +01:00
|
|
|
lb[INDEX_ID_PAL] = &bmain.palettes;
|
2019-08-14 23:29:46 +10:00
|
|
|
|
|
|
|
|
/* Referenced by nodes, objects, view, scene etc, before to free after. */
|
2025-02-11 17:46:07 +01:00
|
|
|
lb[INDEX_ID_GD_LEGACY] = &bmain.gpencils;
|
|
|
|
|
lb[INDEX_ID_GP] = &bmain.grease_pencils;
|
2019-08-14 23:29:46 +10:00
|
|
|
|
2025-02-11 17:46:07 +01:00
|
|
|
lb[INDEX_ID_NT] = &bmain.nodetrees;
|
|
|
|
|
lb[INDEX_ID_IM] = &bmain.images;
|
|
|
|
|
lb[INDEX_ID_TE] = &bmain.textures;
|
|
|
|
|
lb[INDEX_ID_MA] = &bmain.materials;
|
|
|
|
|
lb[INDEX_ID_VF] = &bmain.fonts;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-11-07 16:06:36 +01:00
|
|
|
/* Important!: When adding a new object type,
|
2019-08-14 23:29:46 +10:00
|
|
|
* the specific data should be inserted here. */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2025-02-11 17:46:07 +01:00
|
|
|
lb[INDEX_ID_AR] = &bmain.armatures;
|
|
|
|
|
|
|
|
|
|
lb[INDEX_ID_CF] = &bmain.cachefiles;
|
|
|
|
|
lb[INDEX_ID_ME] = &bmain.meshes;
|
|
|
|
|
lb[INDEX_ID_CU_LEGACY] = &bmain.curves;
|
|
|
|
|
lb[INDEX_ID_MB] = &bmain.metaballs;
|
|
|
|
|
lb[INDEX_ID_CV] = &bmain.hair_curves;
|
|
|
|
|
lb[INDEX_ID_PT] = &bmain.pointclouds;
|
|
|
|
|
lb[INDEX_ID_VO] = &bmain.volumes;
|
|
|
|
|
|
|
|
|
|
lb[INDEX_ID_LT] = &bmain.lattices;
|
|
|
|
|
lb[INDEX_ID_LA] = &bmain.lights;
|
|
|
|
|
lb[INDEX_ID_CA] = &bmain.cameras;
|
|
|
|
|
|
|
|
|
|
lb[INDEX_ID_TXT] = &bmain.texts;
|
|
|
|
|
lb[INDEX_ID_SO] = &bmain.sounds;
|
|
|
|
|
lb[INDEX_ID_GR] = &bmain.collections;
|
|
|
|
|
lb[INDEX_ID_PAL] = &bmain.palettes;
|
|
|
|
|
lb[INDEX_ID_PC] = &bmain.paintcurves;
|
|
|
|
|
lb[INDEX_ID_BR] = &bmain.brushes;
|
|
|
|
|
lb[INDEX_ID_PA] = &bmain.particles;
|
|
|
|
|
lb[INDEX_ID_SPK] = &bmain.speakers;
|
|
|
|
|
lb[INDEX_ID_LP] = &bmain.lightprobes;
|
|
|
|
|
|
|
|
|
|
lb[INDEX_ID_WO] = &bmain.worlds;
|
|
|
|
|
lb[INDEX_ID_MC] = &bmain.movieclips;
|
|
|
|
|
lb[INDEX_ID_SCR] = &bmain.screens;
|
|
|
|
|
lb[INDEX_ID_OB] = &bmain.objects;
|
|
|
|
|
/* referenced by scenes */
|
|
|
|
|
lb[INDEX_ID_LS] = &bmain.linestyles;
|
|
|
|
|
lb[INDEX_ID_SCE] = &bmain.scenes;
|
|
|
|
|
/* before wm, so it's freed after it! */
|
|
|
|
|
lb[INDEX_ID_WS] = &bmain.workspaces;
|
|
|
|
|
lb[INDEX_ID_WM] = &bmain.wm;
|
|
|
|
|
lb[INDEX_ID_MSK] = &bmain.masks;
|
|
|
|
|
|
|
|
|
|
return lb;
|
2018-11-07 16:06:36 +01:00
|
|
|
}
|