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>
|
2018-11-07 16:06:36 +01:00
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
|
|
#include "BLI_blenlib.h"
|
|
|
|
|
#include "BLI_ghash.h"
|
|
|
|
|
#include "BLI_mempool.h"
|
|
|
|
|
#include "BLI_threads.h"
|
|
|
|
|
|
|
|
|
|
#include "DNA_ID.h"
|
|
|
|
|
|
|
|
|
|
#include "BKE_global.h"
|
2021-09-17 16:22:29 +02:00
|
|
|
#include "BKE_idtype.h"
|
2020-02-10 12:58:59 +01:00
|
|
|
#include "BKE_lib_id.h"
|
|
|
|
|
#include "BKE_lib_query.h"
|
2018-11-07 16:06:36 +01:00
|
|
|
#include "BKE_main.h"
|
2021-06-30 15:19:35 +02:00
|
|
|
#include "BKE_main_idmap.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"
|
2018-11-07 16:06:36 +01:00
|
|
|
|
|
|
|
|
#include "IMB_imbuf.h"
|
|
|
|
|
#include "IMB_imbuf_types.h"
|
|
|
|
|
|
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"));
|
|
|
|
|
bmain->lock = static_cast<MainLock *>(MEM_mallocN(sizeof(SpinLock), "main lock"));
|
2018-11-07 16:06:36 +01:00
|
|
|
BLI_spin_init((SpinLock *)bmain->lock);
|
2022-10-05 12:55:32 +02:00
|
|
|
bmain->is_global_main = false;
|
2018-11-07 16:06:36 +01:00
|
|
|
return bmain;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_main_free(Main *mainvar)
|
|
|
|
|
{
|
2023-02-22 16:37:15 +01:00
|
|
|
/* 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 (mainvar->next) {
|
|
|
|
|
BKE_main_free(mainvar->next);
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-04 13:40:32 +10:00
|
|
|
/* Include this check here as the path may be manipulated after creation. */
|
|
|
|
|
BLI_assert_msg(!(mainvar->filepath[0] == '/' && mainvar->filepath[1] == '/'),
|
|
|
|
|
"'.blend' relative \"//\" must not be used in Main!");
|
|
|
|
|
|
2018-11-07 16:06:36 +01:00
|
|
|
/* also call when reading a file, erase all, etc */
|
2021-03-04 18:39:07 +01:00
|
|
|
ListBase *lbarray[INDEX_ID_MAX];
|
2018-11-07 16:06:36 +01:00
|
|
|
int a;
|
|
|
|
|
|
2019-04-27 12:07:07 +10: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
|
|
|
|
2018-11-07 16:06:36 +01:00
|
|
|
MEM_SAFE_FREE(mainvar->blen_thumb);
|
|
|
|
|
|
|
|
|
|
a = set_listbasepointers(mainvar, lbarray);
|
|
|
|
|
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
|
2019-01-14 16:15:15 +01:00
|
|
|
BKE_id_free_ex(mainvar, 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: \
|
|
|
|
|
BKE_id_free_ex(mainvar, id, free_flag, false); \
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mainvar->relations) {
|
|
|
|
|
BKE_main_relations_free(mainvar);
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-30 15:19:35 +02:00
|
|
|
if (mainvar->id_map) {
|
|
|
|
|
BKE_main_idmap_destroy(mainvar->id_map);
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-06 19:36:02 +01:00
|
|
|
/* NOTE: `name_map` in libraries are freed together with the library IDs above. */
|
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
|
|
|
if (mainvar->name_map) {
|
|
|
|
|
BKE_main_namemap_destroy(&mainvar->name_map);
|
|
|
|
|
}
|
2023-07-08 16:16:49 +02:00
|
|
|
if (mainvar->name_map_global) {
|
|
|
|
|
BKE_main_namemap_destroy(&mainvar->name_map_global);
|
|
|
|
|
}
|
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
|
|
|
|
2018-11-07 16:06:36 +01:00
|
|
|
BLI_spin_end((SpinLock *)mainvar->lock);
|
|
|
|
|
MEM_freeN(mainvar->lock);
|
|
|
|
|
MEM_freeN(mainvar);
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
const int 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(
|
2023-05-16 18:14:43 +02: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__));
|
2023-05-16 18:14:43 +02:00
|
|
|
(*entry_p)->session_uuid = self_id->session_uuid;
|
2021-01-21 14:52:40 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2023-05-16 18:14:43 +02:00
|
|
|
BLI_assert((*entry_p)->session_uuid == self_id->session_uuid);
|
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;
|
2023-07-17 10:46:26 +02:00
|
|
|
to_id_entry->session_uuid = (*id_pointer != nullptr) ? (*id_pointer)->session_uuid :
|
|
|
|
|
MAIN_ID_SESSION_UUID_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(
|
|
|
|
|
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__));
|
2021-01-21 14:52:40 +01:00
|
|
|
(*entry_p)->session_uuid = (*id_pointer)->session_uuid;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
BLI_assert((*entry_p)->session_uuid == (*id_pointer)->session_uuid);
|
|
|
|
|
}
|
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;
|
|
|
|
|
from_id_entry->session_uuid = self_id->session_uuid;
|
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) {
|
2020-02-18 11:21:34 +01:00
|
|
|
const int idwalk_flag = IDWALK_READONLY |
|
|
|
|
|
((flag & MAINIDRELATIONS_INCLUDE_UI) != 0 ? IDWALK_INCLUDE_UI : 0);
|
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__));
|
2021-01-22 17:35:47 +01:00
|
|
|
(*entry_p)->session_uuid = id->session_uuid;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
BLI_assert((*entry_p)->session_uuid == id->session_uuid);
|
|
|
|
|
}
|
|
|
|
|
|
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];
|
2023-07-17 10:46:26 +02:00
|
|
|
};
|
2021-09-17 16:22:29 +02:00
|
|
|
|
|
|
|
|
static LibWeakRefKey *lib_weak_key_create(LibWeakRefKey *key,
|
|
|
|
|
const char *lib_path,
|
|
|
|
|
const char *id_name)
|
|
|
|
|
{
|
2023-07-17 10:46:26 +02:00
|
|
|
if (key == nullptr) {
|
|
|
|
|
key = static_cast<LibWeakRefKey *>(MEM_mallocN(sizeof(*key), __func__));
|
2021-09-17 16:22:29 +02:00
|
|
|
}
|
2023-05-09 12:50:37 +10:00
|
|
|
STRNCPY(key->filepath, lib_path);
|
|
|
|
|
STRNCPY(key->id_name, id_name);
|
2021-09-17 16:22:29 +02:00
|
|
|
return key;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static uint lib_weak_key_hash(const void *ptr)
|
|
|
|
|
{
|
2023-07-17 10:46:26 +02:00
|
|
|
const LibWeakRefKey *string_pair = static_cast<const LibWeakRefKey *>(ptr);
|
2021-09-17 16:22:29 +02:00
|
|
|
uint hash = BLI_ghashutil_strhash_p_murmur(string_pair->filepath);
|
|
|
|
|
return hash ^ BLI_ghashutil_strhash_p_murmur(string_pair->id_name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool lib_weak_key_cmp(const void *a, const void *b)
|
|
|
|
|
{
|
2023-07-17 10:46:26 +02:00
|
|
|
const LibWeakRefKey *string_pair_a = static_cast<const LibWeakRefKey *>(a);
|
|
|
|
|
const LibWeakRefKey *string_pair_b = static_cast<const LibWeakRefKey *>(b);
|
2021-09-17 16:22:29 +02:00
|
|
|
|
|
|
|
|
return !(STREQ(string_pair_a->filepath, string_pair_b->filepath) &&
|
|
|
|
|
STREQ(string_pair_a->id_name, string_pair_b->id_name));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GHash *BKE_main_library_weak_reference_create(Main *bmain)
|
|
|
|
|
{
|
|
|
|
|
GHash *library_weak_reference_mapping = BLI_ghash_new(
|
|
|
|
|
lib_weak_key_hash, lib_weak_key_cmp, __func__);
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
2023-07-17 10:46:26 +02:00
|
|
|
LibWeakRefKey *key = lib_weak_key_create(nullptr,
|
2021-09-17 16:22:29 +02:00
|
|
|
id_iter->library_weak_reference->library_filepath,
|
|
|
|
|
id_iter->library_weak_reference->library_id_name);
|
|
|
|
|
BLI_ghash_insert(library_weak_reference_mapping, key, id_iter);
|
|
|
|
|
}
|
|
|
|
|
FOREACH_MAIN_LISTBASE_ID_END;
|
|
|
|
|
}
|
|
|
|
|
FOREACH_MAIN_LISTBASE_END;
|
|
|
|
|
|
|
|
|
|
return library_weak_reference_mapping;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_main_library_weak_reference_destroy(GHash *library_weak_reference_mapping)
|
|
|
|
|
{
|
2023-07-17 10:46:26 +02:00
|
|
|
BLI_ghash_free(library_weak_reference_mapping, MEM_freeN, nullptr);
|
2021-09-17 16:22:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ID *BKE_main_library_weak_reference_search_item(GHash *library_weak_reference_mapping,
|
|
|
|
|
const char *library_filepath,
|
|
|
|
|
const char *library_id_name)
|
|
|
|
|
{
|
|
|
|
|
LibWeakRefKey key;
|
|
|
|
|
lib_weak_key_create(&key, library_filepath, library_id_name);
|
|
|
|
|
return (ID *)BLI_ghash_lookup(library_weak_reference_mapping, &key);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_main_library_weak_reference_add_item(GHash *library_weak_reference_mapping,
|
|
|
|
|
const char *library_filepath,
|
|
|
|
|
const char *library_id_name,
|
|
|
|
|
ID *new_id)
|
|
|
|
|
{
|
|
|
|
|
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)));
|
|
|
|
|
|
2023-07-17 10:46:26 +02:00
|
|
|
new_id->library_weak_reference = static_cast<LibraryWeakReference *>(
|
|
|
|
|
MEM_mallocN(sizeof(*(new_id->library_weak_reference)), __func__));
|
2021-09-17 16:22:29 +02:00
|
|
|
|
2023-07-17 10:46:26 +02:00
|
|
|
LibWeakRefKey *key = lib_weak_key_create(nullptr, library_filepath, library_id_name);
|
2021-09-17 16:22:29 +02:00
|
|
|
void **id_p;
|
|
|
|
|
const bool already_exist_in_mapping = BLI_ghash_ensure_p(
|
|
|
|
|
library_weak_reference_mapping, key, &id_p);
|
|
|
|
|
BLI_assert(!already_exist_in_mapping);
|
2021-09-23 12:30:07 +02:00
|
|
|
UNUSED_VARS_NDEBUG(already_exist_in_mapping);
|
2021-09-17 16:22:29 +02:00
|
|
|
|
2023-05-09 12:50:37 +10:00
|
|
|
STRNCPY(new_id->library_weak_reference->library_filepath, library_filepath);
|
|
|
|
|
STRNCPY(new_id->library_weak_reference->library_id_name, library_id_name);
|
2021-09-17 16:22:29 +02:00
|
|
|
*id_p = new_id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_main_library_weak_reference_update_item(GHash *library_weak_reference_mapping,
|
|
|
|
|
const char *library_filepath,
|
|
|
|
|
const char *library_id_name,
|
|
|
|
|
ID *old_id,
|
|
|
|
|
ID *new_id)
|
|
|
|
|
{
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
|
|
LibWeakRefKey key;
|
|
|
|
|
lib_weak_key_create(&key, library_filepath, library_id_name);
|
|
|
|
|
void **id_p = BLI_ghash_lookup_p(library_weak_reference_mapping, &key);
|
2023-07-17 10:46:26 +02:00
|
|
|
BLI_assert(id_p != nullptr && *id_p == old_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
|
|
|
*id_p = new_id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_main_library_weak_reference_remove_item(GHash *library_weak_reference_mapping,
|
|
|
|
|
const char *library_filepath,
|
|
|
|
|
const char *library_id_name,
|
|
|
|
|
ID *old_id)
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
|
|
|
LibWeakRefKey key;
|
|
|
|
|
lib_weak_key_create(&key, library_filepath, library_id_name);
|
|
|
|
|
|
|
|
|
|
BLI_assert(BLI_ghash_lookup(library_weak_reference_mapping, &key) == old_id);
|
2023-07-17 10:46:26 +02:00
|
|
|
BLI_ghash_remove(library_weak_reference_mapping, &key, MEM_freeN, nullptr);
|
2021-09-17 16:22:29 +02:00
|
|
|
|
|
|
|
|
MEM_SAFE_FREE(old_id->library_weak_reference);
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2021-06-10 01:55:41 +10:00
|
|
|
int set_listbasepointers(Main *bmain, ListBase *lb[/*INDEX_ID_MAX*/])
|
2018-11-07 16:06:36 +01:00
|
|
|
{
|
2019-08-14 23:29:46 +10:00
|
|
|
/* Libraries may be accessed from pretty much any other ID. */
|
|
|
|
|
lb[INDEX_ID_LI] = &(bmain->libraries);
|
|
|
|
|
|
2018-11-07 16:06:36 +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). */
|
|
|
|
|
lb[INDEX_ID_AC] = &(bmain->actions);
|
|
|
|
|
|
2019-03-08 09:29:17 +11: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. */
|
|
|
|
|
lb[INDEX_ID_PAL] = &(bmain->palettes);
|
|
|
|
|
|
|
|
|
|
/* Referenced by nodes, objects, view, scene etc, before to free after. */
|
2023-03-08 12:35:58 +01:00
|
|
|
lb[INDEX_ID_GD_LEGACY] = &(bmain->gpencils);
|
2023-05-30 11:14:16 +02:00
|
|
|
lb[INDEX_ID_GP] = &(bmain->grease_pencils);
|
2019-08-14 23:29:46 +10:00
|
|
|
|
2019-03-08 09:29:17 +11: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
|
|
|
|
2019-03-08 09:29:17 +11:00
|
|
|
lb[INDEX_ID_AR] = &(bmain->armatures);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-08 09:29:17 +11:00
|
|
|
lb[INDEX_ID_CF] = &(bmain->cachefiles);
|
|
|
|
|
lb[INDEX_ID_ME] = &(bmain->meshes);
|
2022-02-18 09:50:29 -06:00
|
|
|
lb[INDEX_ID_CU_LEGACY] = &(bmain->curves);
|
2019-03-08 09:29:17 +11:00
|
|
|
lb[INDEX_ID_MB] = &(bmain->metaballs);
|
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
|
|
|
lb[INDEX_ID_CV] = &(bmain->hair_curves);
|
2020-03-17 14:41:48 +01:00
|
|
|
lb[INDEX_ID_PT] = &(bmain->pointclouds);
|
|
|
|
|
lb[INDEX_ID_VO] = &(bmain->volumes);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-08 09:29:17 +11:00
|
|
|
lb[INDEX_ID_LT] = &(bmain->lattices);
|
|
|
|
|
lb[INDEX_ID_LA] = &(bmain->lights);
|
|
|
|
|
lb[INDEX_ID_CA] = &(bmain->cameras);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-08 09:29:17 +11:00
|
|
|
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);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-08 09:29:17 +11:00
|
|
|
lb[INDEX_ID_WO] = &(bmain->worlds);
|
|
|
|
|
lb[INDEX_ID_MC] = &(bmain->movieclips);
|
|
|
|
|
lb[INDEX_ID_SCR] = &(bmain->screens);
|
|
|
|
|
lb[INDEX_ID_OB] = &(bmain->objects);
|
|
|
|
|
lb[INDEX_ID_LS] = &(bmain->linestyles); /* referenced by scenes */
|
|
|
|
|
lb[INDEX_ID_SCE] = &(bmain->scenes);
|
|
|
|
|
lb[INDEX_ID_WS] = &(bmain->workspaces); /* before wm, so it's freed after it! */
|
2018-11-07 16:06:36 +01:00
|
|
|
lb[INDEX_ID_WM] = &(bmain->wm);
|
2019-03-08 09:29:17 +11:00
|
|
|
lb[INDEX_ID_MSK] = &(bmain->masks);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-07-17 10:46:26 +02:00
|
|
|
lb[INDEX_ID_NULL] = nullptr;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-03-04 18:39:07 +01:00
|
|
|
return (INDEX_ID_MAX - 1);
|
2018-11-07 16:06:36 +01:00
|
|
|
}
|