2011-11-05 13:11:49 +00:00
|
|
|
/*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup bke
|
2011-11-05 13:11:49 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
|
|
#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_math.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_colortools.h"
|
|
|
|
|
#include "BKE_icons.h"
|
2020-03-06 11:51:17 +01:00
|
|
|
#include "BKE_idtype.h"
|
2020-02-10 12:58:59 +01:00
|
|
|
#include "BKE_lib_id.h"
|
2020-05-12 18:54:38 +02:00
|
|
|
#include "BKE_lib_query.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BKE_light.h"
|
2011-11-05 13:11:49 +00:00
|
|
|
#include "BKE_main.h"
|
|
|
|
|
#include "BKE_node.h"
|
|
|
|
|
|
2020-03-06 11:51:17 +01:00
|
|
|
#include "BLT_translation.h"
|
|
|
|
|
|
2020-05-25 10:07:10 +02:00
|
|
|
#include "DEG_depsgraph.h"
|
|
|
|
|
|
2020-09-10 16:13:18 +02:00
|
|
|
#include "BLO_read_write.h"
|
|
|
|
|
|
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);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-09-12 04:34:55 +10:00
|
|
|
la->curfalloff = BKE_curvemapping_add(1, 0.0f, 1.0f, 1.0f, 0.0f);
|
2020-08-01 13:02:21 +10:00
|
|
|
BKE_curvemapping_init(la->curfalloff);
|
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!
|
|
|
|
|
*
|
2020-02-10 12:58:59 +01:00
|
|
|
* \param flag: Copying options (see BKE_lib_id.h'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
|
|
|
|
2019-08-07 03:21:55 +10:00
|
|
|
la_dst->curfalloff = BKE_curvemapping_copy(la_src->curfalloff);
|
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 (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);
|
|
|
|
|
}
|
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 {
|
|
|
|
|
la_dst->preview = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
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;
|
|
|
|
|
|
|
|
|
|
BKE_curvemapping_free(la->curfalloff);
|
|
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
|
la->nodetree = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
Light *lamp = (Light *)id;
|
|
|
|
|
if (lamp->nodetree) {
|
|
|
|
|
/* nodetree **are owned by IDs**, treat them as mere sub-data and not real ID! */
|
|
|
|
|
BKE_library_foreach_ID_embedded(data, (ID **)&lamp->nodetree);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
if (la->id.us > 0 || BLO_write_is_undo(writer)) {
|
|
|
|
|
/* write LibData */
|
|
|
|
|
BLO_write_id_struct(writer, Light, id_address, &la->id);
|
|
|
|
|
BKE_id_blend_write(writer, &la->id);
|
|
|
|
|
|
|
|
|
|
if (la->adt) {
|
|
|
|
|
BKE_animdata_blend_write(writer, la->adt);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (la->curfalloff) {
|
|
|
|
|
BKE_curvemapping_blend_write(writer, la->curfalloff);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Node-tree is integral part of lights, no libdata. */
|
|
|
|
|
if (la->nodetree) {
|
|
|
|
|
BLO_write_struct(writer, bNodeTree, la->nodetree);
|
|
|
|
|
ntreeBlendWrite(writer, la->nodetree);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BKE_previewimg_blend_write(writer, la->preview);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void light_blend_read_data(BlendDataReader *reader, ID *id)
|
|
|
|
|
{
|
|
|
|
|
Light *la = (Light *)id;
|
|
|
|
|
BLO_read_data_address(reader, &la->adt);
|
|
|
|
|
BKE_animdata_blend_read_data(reader, la->adt);
|
|
|
|
|
|
|
|
|
|
BLO_read_data_address(reader, &la->curfalloff);
|
|
|
|
|
if (la->curfalloff) {
|
|
|
|
|
BKE_curvemapping_blend_read(reader, la->curfalloff);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BLO_read_data_address(reader, &la->preview);
|
|
|
|
|
BKE_previewimg_blend_read(reader, la->preview);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void light_blend_read_lib(BlendLibReader *reader, ID *id)
|
|
|
|
|
{
|
|
|
|
|
Light *la = (Light *)id;
|
|
|
|
|
BLO_read_id_address(reader, la->id.lib, &la->ipo); // XXX deprecated - old animation system
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void light_blend_read_expand(BlendExpander *expander, ID *id)
|
|
|
|
|
{
|
|
|
|
|
Light *la = (Light *)id;
|
|
|
|
|
BLO_expand(expander, la->ipo); // XXX deprecated - old animation system
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-20 11:18:20 +02:00
|
|
|
IDTypeInfo IDType_ID_LA = {
|
|
|
|
|
.id_code = ID_LA,
|
|
|
|
|
.id_filter = FILTER_ID_LA,
|
|
|
|
|
.main_listbase_index = INDEX_ID_LA,
|
|
|
|
|
.struct_size = sizeof(Light),
|
|
|
|
|
.name = "Light",
|
|
|
|
|
.name_plural = "lights",
|
|
|
|
|
.translation_context = BLT_I18NCONTEXT_ID_LIGHT,
|
|
|
|
|
.flags = 0,
|
|
|
|
|
|
|
|
|
|
.init_data = light_init_data,
|
|
|
|
|
.copy_data = light_copy_data,
|
|
|
|
|
.free_data = light_free_data,
|
|
|
|
|
.make_local = NULL,
|
2020-05-12 18:54:38 +02:00
|
|
|
.foreach_id = light_foreach_id,
|
2020-08-28 13:05:48 +02:00
|
|
|
.foreach_cache = NULL,
|
2021-02-25 10:17:31 +01:00
|
|
|
.owner_get = NULL,
|
2020-08-28 13:05:48 +02:00
|
|
|
|
2020-09-10 16:13:18 +02:00
|
|
|
.blend_write = light_blend_write,
|
|
|
|
|
.blend_read_data = light_blend_read_data,
|
|
|
|
|
.blend_read_lib = light_blend_read_lib,
|
|
|
|
|
.blend_read_expand = light_blend_read_expand,
|
2020-11-03 11:39:36 +01:00
|
|
|
|
|
|
|
|
.blend_read_undo_preserve = NULL,
|
2021-01-22 14:52:50 +01:00
|
|
|
|
|
|
|
|
.lib_override_apply_post = NULL,
|
2020-04-20 11:18:20 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Light *BKE_light_add(Main *bmain, const char *name)
|
|
|
|
|
{
|
|
|
|
|
Light *la;
|
|
|
|
|
|
2020-10-08 12:50:04 +02:00
|
|
|
la = BKE_id_new(bmain, ID_LA, name);
|
2020-04-20 11:18:20 +02:00
|
|
|
|
|
|
|
|
return la;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-25 10:07:10 +02:00
|
|
|
void BKE_light_eval(struct Depsgraph *depsgraph, Light *la)
|
|
|
|
|
{
|
|
|
|
|
DEG_debug_print_eval(depsgraph, __func__, la->id.name, la);
|
|
|
|
|
}
|