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 */
|
2011-11-05 13:11:49 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup bke
|
2011-11-05 13:11:49 +00:00
|
|
|
*/
|
|
|
|
|
|
2023-07-22 11:27:25 +10:00
|
|
|
#include <cstdlib>
|
2011-11-05 13:11:49 +00:00
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
2020-09-10 16:13:18 +02:00
|
|
|
/* Allow using deprecated functionality for .blend file I/O. */
|
|
|
|
|
#define DNA_DEPRECATED_ALLOW
|
|
|
|
|
|
2012-11-09 13:57:09 +00:00
|
|
|
#include "DNA_anim_types.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "DNA_defaults.h"
|
2019-02-27 12:34:56 +11:00
|
|
|
#include "DNA_light_types.h"
|
2011-11-05 13:11:49 +00:00
|
|
|
#include "DNA_material_types.h"
|
2012-11-09 13:57:09 +00:00
|
|
|
#include "DNA_node_types.h"
|
2011-11-05 13:11:49 +00:00
|
|
|
#include "DNA_object_types.h"
|
2012-11-09 13:57:09 +00:00
|
|
|
#include "DNA_scene_types.h"
|
2011-11-05 13:11:49 +00:00
|
|
|
#include "DNA_texture_types.h"
|
|
|
|
|
|
|
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
|
2020-09-10 16:13:18 +02:00
|
|
|
#include "BKE_anim_data.h"
|
2011-11-05 13:11:49 +00:00
|
|
|
#include "BKE_icons.h"
|
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"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BKE_light.h"
|
2023-12-01 19:43:16 +01:00
|
|
|
#include "BKE_main.hh"
|
2011-11-05 13:11:49 +00:00
|
|
|
#include "BKE_node.h"
|
2023-09-04 18:02:16 +02:00
|
|
|
#include "BKE_preview_image.hh"
|
2011-11-05 13:11:49 +00:00
|
|
|
|
2020-03-06 11:51:17 +01:00
|
|
|
#include "BLT_translation.h"
|
|
|
|
|
|
2023-09-22 03:18:17 +02:00
|
|
|
#include "DEG_depsgraph.hh"
|
2020-05-25 10:07:10 +02:00
|
|
|
|
2023-08-28 15:01:05 +02:00
|
|
|
#include "BLO_read_write.hh"
|
2020-09-10 16:13:18 +02:00
|
|
|
|
2020-03-06 11:51:17 +01:00
|
|
|
static void light_init_data(ID *id)
|
2011-11-05 13:11:49 +00:00
|
|
|
{
|
2020-03-06 11:51:17 +01:00
|
|
|
Light *la = (Light *)id;
|
2019-03-12 16:59:04 +11:00
|
|
|
BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(la, id));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-09-12 04:34:55 +10:00
|
|
|
MEMCPY_STRUCT_AFTER(la, DNA_struct_default_get(Light), id);
|
First step to handle missing libs/datablocks when reading a file.
Idea is, instead of ignoring completely missing linked datablocks, to
create void placeholders for them.
That way, you can work on your file, save it, and find again your missing data once
lib becomes available again. Or you can edit missing lib's path (in Outliner),
save and reload the file, and you are done.
Also, Outliner now shows broken libraries (and placeholders) with a 'broken lib' icon.
Future plans are also to be able to relocate missing libs and reload them at runtime.
Code notes:
- Placeholder ID is just a regular datablock of same type as expected linked one,
with 'default' data, and a LIB_MISSING bitflag set.
- To allow creation of such datablocks, creation of datablocks in BKE was split in two step:
+ Allocation of memory itself.
+ Setting of all internal data to default values.
See also the design task (T43351).
Reviewed by @campbellbarton, thanks a bunch!
Differential Revision: https://developer.blender.org/D1394
2015-10-20 14:44:57 +02:00
|
|
|
}
|
|
|
|
|
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
/**
|
2019-04-27 12:07:07 +10:00
|
|
|
* Only copy internal data of Light ID from source
|
|
|
|
|
* to already allocated/initialized destination.
|
|
|
|
|
* You probably never want to use that directly,
|
|
|
|
|
* use #BKE_id_copy or #BKE_id_copy_ex for typical needs.
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
*
|
|
|
|
|
* WARNING! This function will not handle ID user count!
|
|
|
|
|
*
|
2024-01-15 12:44:04 -05:00
|
|
|
* \param flag: Copying options (see BKE_lib_id.hh's LIB_ID_COPY_... flags for more).
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
*/
|
2020-03-06 11:51:17 +01:00
|
|
|
static void light_copy_data(Main *bmain, ID *id_dst, const ID *id_src, const int flag)
|
2011-11-05 13:11:49 +00:00
|
|
|
{
|
2020-03-06 11:51:17 +01:00
|
|
|
Light *la_dst = (Light *)id_dst;
|
|
|
|
|
const Light *la_src = (const Light *)id_src;
|
2020-10-06 17:43:12 +02:00
|
|
|
|
|
|
|
|
const bool is_localized = (flag & LIB_ID_CREATE_LOCAL) != 0;
|
2019-09-02 17:34:56 +02:00
|
|
|
/* We always need allocation of our private ID data. */
|
2019-09-12 12:24:24 +02:00
|
|
|
const int flag_private_id_data = flag & ~LIB_ID_CREATE_NO_ALLOCATE;
|
2019-09-02 17:34:56 +02:00
|
|
|
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
if (la_src->nodetree) {
|
2020-10-06 17:43:12 +02:00
|
|
|
if (is_localized) {
|
|
|
|
|
la_dst->nodetree = ntreeLocalize(la_src->nodetree);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
BKE_id_copy_ex(
|
|
|
|
|
bmain, (ID *)la_src->nodetree, (ID **)&la_dst->nodetree, flag_private_id_data);
|
|
|
|
|
}
|
2022-09-06 14:57:44 +02:00
|
|
|
la_dst->nodetree->owner_id = &la_dst->id;
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
if ((flag & LIB_ID_COPY_NO_PREVIEW) == 0) {
|
|
|
|
|
BKE_previewimg_id_copy(&la_dst->id, &la_src->id);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2023-07-17 10:46:26 +02:00
|
|
|
la_dst->preview = nullptr;
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
}
|
|
|
|
|
}
|
2015-01-09 09:52:51 +01:00
|
|
|
|
2020-04-20 11:18:20 +02:00
|
|
|
static void light_free_data(ID *id)
|
|
|
|
|
{
|
|
|
|
|
Light *la = (Light *)id;
|
|
|
|
|
|
|
|
|
|
/* is no lib link block, but light extension */
|
|
|
|
|
if (la->nodetree) {
|
2020-04-20 16:14:45 +02:00
|
|
|
ntreeFreeEmbeddedTree(la->nodetree);
|
2020-04-20 11:18:20 +02:00
|
|
|
MEM_freeN(la->nodetree);
|
2023-07-17 10:46:26 +02:00
|
|
|
la->nodetree = nullptr;
|
2020-04-20 11:18:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BKE_previewimg_free(&la->preview);
|
|
|
|
|
BKE_icon_id_delete(&la->id);
|
|
|
|
|
la->id.icon_id = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-12 18:54:38 +02:00
|
|
|
static void light_foreach_id(ID *id, LibraryForeachIDData *data)
|
|
|
|
|
{
|
2023-08-22 15:42:19 +02:00
|
|
|
Light *lamp = reinterpret_cast<Light *>(id);
|
|
|
|
|
const int flag = BKE_lib_query_foreachid_process_flags_get(data);
|
|
|
|
|
|
2020-05-12 18:54:38 +02:00
|
|
|
if (lamp->nodetree) {
|
|
|
|
|
/* nodetree **are owned by IDs**, treat them as mere sub-data and not real ID! */
|
2021-10-27 11:30:43 +02:00
|
|
|
BKE_LIB_FOREACHID_PROCESS_FUNCTION_CALL(
|
|
|
|
|
data, BKE_library_foreach_ID_embedded(data, (ID **)&lamp->nodetree));
|
2020-05-12 18:54:38 +02:00
|
|
|
}
|
2023-08-22 15:42:19 +02:00
|
|
|
|
|
|
|
|
if (flag & IDWALK_DO_DEPRECATED_POINTERS) {
|
|
|
|
|
BKE_LIB_FOREACHID_PROCESS_ID_NOCHECK(data, lamp->ipo, IDWALK_CB_USER);
|
|
|
|
|
}
|
2020-05-12 18:54:38 +02:00
|
|
|
}
|
|
|
|
|
|
2020-09-10 16:13:18 +02:00
|
|
|
static void light_blend_write(BlendWriter *writer, ID *id, const void *id_address)
|
|
|
|
|
{
|
|
|
|
|
Light *la = (Light *)id;
|
|
|
|
|
|
2023-07-07 17:03:02 +02:00
|
|
|
/* Forward compatibility for energy. */
|
|
|
|
|
la->energy_deprecated = la->energy;
|
|
|
|
|
if (la->type == LA_AREA) {
|
|
|
|
|
la->energy_deprecated /= M_PI_4;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-19 11:13:55 +02:00
|
|
|
/* write LibData */
|
|
|
|
|
BLO_write_id_struct(writer, Light, id_address, &la->id);
|
|
|
|
|
BKE_id_blend_write(writer, &la->id);
|
2020-09-10 16:13:18 +02:00
|
|
|
|
2021-08-19 11:13:55 +02:00
|
|
|
/* Node-tree is integral part of lights, no libdata. */
|
|
|
|
|
if (la->nodetree) {
|
2023-04-14 10:35:31 +02:00
|
|
|
BLO_Write_IDBuffer *temp_embedded_id_buffer = BLO_write_allocate_id_buffer();
|
|
|
|
|
BLO_write_init_id_buffer_from_id(
|
|
|
|
|
temp_embedded_id_buffer, &la->nodetree->id, BLO_write_is_undo(writer));
|
|
|
|
|
BLO_write_struct_at_address(
|
|
|
|
|
writer, bNodeTree, la->nodetree, BLO_write_get_id_buffer_temp_id(temp_embedded_id_buffer));
|
|
|
|
|
ntreeBlendWrite(writer, (bNodeTree *)BLO_write_get_id_buffer_temp_id(temp_embedded_id_buffer));
|
|
|
|
|
BLO_write_destroy_id_buffer(&temp_embedded_id_buffer);
|
2020-09-10 16:13:18 +02:00
|
|
|
}
|
2021-08-19 11:13:55 +02:00
|
|
|
|
|
|
|
|
BKE_previewimg_blend_write(writer, la->preview);
|
2020-09-10 16:13:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void light_blend_read_data(BlendDataReader *reader, ID *id)
|
|
|
|
|
{
|
|
|
|
|
Light *la = (Light *)id;
|
|
|
|
|
|
|
|
|
|
BLO_read_data_address(reader, &la->preview);
|
|
|
|
|
BKE_previewimg_blend_read(reader, la->preview);
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-20 11:18:20 +02:00
|
|
|
IDTypeInfo IDType_ID_LA = {
|
2023-07-17 10:46:26 +02:00
|
|
|
/*id_code*/ ID_LA,
|
|
|
|
|
/*id_filter*/ FILTER_ID_LA,
|
|
|
|
|
/*main_listbase_index*/ INDEX_ID_LA,
|
|
|
|
|
/*struct_size*/ sizeof(Light),
|
|
|
|
|
/*name*/ "Light",
|
2023-10-04 02:53:31 +02:00
|
|
|
/*name_plural*/ N_("lights"),
|
2023-07-17 10:46:26 +02:00
|
|
|
/*translation_context*/ BLT_I18NCONTEXT_ID_LIGHT,
|
|
|
|
|
/*flags*/ IDTYPE_FLAGS_APPEND_IS_REUSABLE,
|
|
|
|
|
/*asset_type_info*/ nullptr,
|
|
|
|
|
|
|
|
|
|
/*init_data*/ light_init_data,
|
|
|
|
|
/*copy_data*/ light_copy_data,
|
|
|
|
|
/*free_data*/ light_free_data,
|
|
|
|
|
/*make_local*/ nullptr,
|
|
|
|
|
/*foreach_id*/ light_foreach_id,
|
|
|
|
|
/*foreach_cache*/ nullptr,
|
|
|
|
|
/*foreach_path*/ nullptr,
|
|
|
|
|
/*owner_pointer_get*/ nullptr,
|
|
|
|
|
|
|
|
|
|
/*blend_write*/ light_blend_write,
|
|
|
|
|
/*blend_read_data*/ light_blend_read_data,
|
2023-03-11 18:07:59 +01:00
|
|
|
/*blend_read_after_liblink*/ nullptr,
|
2023-07-17 10:46:26 +02:00
|
|
|
|
|
|
|
|
/*blend_read_undo_preserve*/ nullptr,
|
|
|
|
|
|
|
|
|
|
/*lib_override_apply_post*/ nullptr,
|
2020-04-20 11:18:20 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Light *BKE_light_add(Main *bmain, const char *name)
|
|
|
|
|
{
|
|
|
|
|
Light *la;
|
|
|
|
|
|
2023-07-17 10:46:26 +02:00
|
|
|
la = static_cast<Light *>(BKE_id_new(bmain, ID_LA, name));
|
2020-04-20 11:18:20 +02:00
|
|
|
|
|
|
|
|
return la;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-03 08:36:28 +10:00
|
|
|
void BKE_light_eval(Depsgraph *depsgraph, Light *la)
|
2020-05-25 10:07:10 +02:00
|
|
|
{
|
|
|
|
|
DEG_debug_print_eval(depsgraph, __func__, la->id.name, la);
|
|
|
|
|
}
|