This repository has been archived on 2023-10-09. You can view files and clone it, but cannot push or open issues or pull requests.
Files
blender-archive/source/blender/blenkernel/intern/world.c

171 lines
4.3 KiB
C
Raw Normal View History

2011-10-10 09:38:02 +00:00
/*
2002-10-12 11:37:38 +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.
2002-10-12 11:37:38 +00:00
*
* 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,
2010-02-12 13:34:04 +00:00
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2002-10-12 11:37:38 +00:00
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*/
/** \file
* \ingroup bke
2011-02-27 20:40:57 +00:00
*/
2002-10-12 11:37:38 +00:00
#include <string.h>
#include <stdlib.h>
2002-10-12 11:37:38 +00:00
#include <math.h>
2002-10-12 11:37:38 +00:00
#include "MEM_guardedalloc.h"
#include "DNA_world_types.h"
#include "DNA_scene_types.h"
#include "DNA_texture_types.h"
2002-10-12 11:37:38 +00:00
#include "BLI_utildefines.h"
#include "BLI_listbase.h"
#include "BKE_animsys.h"
#include "BKE_icons.h"
#include "BKE_library.h"
#include "BKE_main.h"
#include "BKE_node.h"
#include "BKE_world.h"
2002-10-12 11:37:38 +00:00
#include "DRW_engine.h"
2018-06-07 19:15:36 +02:00
#include "DEG_depsgraph.h"
#include "GPU_material.h"
ID-Remap - Step one: core work (cleanup and rework of generic ID datablock handling). This commit changes a lot of how IDs are handled internally, especially the unlinking/freeing processes. So far, this was very fuzy, to summarize cleanly deleting or replacing a datablock was pretty much impossible, except for a few special cases. Also, unlinking was handled by each datatype, in a rather messy and prone-to-errors way (quite a few ID usages were missed or wrongly handled that way). One of the main goal of id-remap branch was to cleanup this, and fatorize ID links handling by using library_query utils to allow generic handling of those, which is now the case (now, generic ID links handling is only "knwon" from readfile.c and library_query.c). This commit also adds backends to allow live replacement and deletion of datablocks in Blender (so-called 'remapping' process, where we replace all usages of a given ID pointer by a new one, or NULL one in case of unlinking). This will allow nice new features, like ability to easily reload or relocate libraries, real immediate deletion of datablocks in blender, replacement of one datablock by another, etc. Some of those are for next commits. A word of warning: this commit is highly risky, because it affects potentially a lot in Blender core. Though it was tested rather deeply, being totally impossible to check all possible ID usage cases, it's likely there are some remaining issues and bugs in new code... Please report them! ;) Review task: D2027 (https://developer.blender.org/D2027). Reviewed by campbellbarton, thanks a bunch.
2016-06-22 17:29:38 +02:00
/** Free (or release) any data used by this world (does not free the world itself). */
void BKE_world_free(World *wrld)
2002-10-12 11:37:38 +00:00
{
BKE_animdata_free((ID *)wrld, false);
ID-Remap - Step one: core work (cleanup and rework of generic ID datablock handling). This commit changes a lot of how IDs are handled internally, especially the unlinking/freeing processes. So far, this was very fuzy, to summarize cleanly deleting or replacing a datablock was pretty much impossible, except for a few special cases. Also, unlinking was handled by each datatype, in a rather messy and prone-to-errors way (quite a few ID usages were missed or wrongly handled that way). One of the main goal of id-remap branch was to cleanup this, and fatorize ID links handling by using library_query utils to allow generic handling of those, which is now the case (now, generic ID links handling is only "knwon" from readfile.c and library_query.c). This commit also adds backends to allow live replacement and deletion of datablocks in Blender (so-called 'remapping' process, where we replace all usages of a given ID pointer by a new one, or NULL one in case of unlinking). This will allow nice new features, like ability to easily reload or relocate libraries, real immediate deletion of datablocks in blender, replacement of one datablock by another, etc. Some of those are for next commits. A word of warning: this commit is highly risky, because it affects potentially a lot in Blender core. Though it was tested rather deeply, being totally impossible to check all possible ID usage cases, it's likely there are some remaining issues and bugs in new code... Please report them! ;) Review task: D2027 (https://developer.blender.org/D2027). Reviewed by campbellbarton, thanks a bunch.
2016-06-22 17:29:38 +02:00
DRW_drawdata_free((ID *)wrld);
/* is no lib link block, but world extension */
if (wrld->nodetree) {
ntreeFreeNestedTree(wrld->nodetree);
MEM_freeN(wrld->nodetree);
wrld->nodetree = NULL;
}
GPU_material_free(&wrld->gpumaterial);
2018-06-17 17:05:51 +02:00
BKE_icon_id_delete((struct ID *)wrld);
BKE_previewimg_free(&wrld->preview);
}
2002-10-12 11:37:38 +00:00
void BKE_world_init(World *wrld)
2002-10-12 11:37:38 +00:00
{
BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(wrld, id));
2002-10-12 11:37:38 +00:00
wrld->horr = 0.05f;
wrld->horg = 0.05f;
wrld->horb = 0.05f;
wrld->aodist = 10.0f;
wrld->aoenergy = 1.0f;
2018-06-17 17:05:51 +02:00
wrld->preview = NULL;
wrld->miststa = 5.0f;
wrld->mistdist = 25.0f;
}
World *BKE_world_add(Main *bmain, const char *name)
{
World *wrld;
wrld = BKE_libblock_alloc(bmain, ID_WO, name, 0);
BKE_world_init(wrld);
return wrld;
2002-10-12 11:37:38 +00:00
}
/**
* Only copy internal data of World ID from source to already allocated/initialized destination.
2019-02-04 20:39:59 +01:00
* You probably never want to use that directly, use BKE_id_copy or BKE_id_copy_ex for typical needs.
*
* WARNING! This function will not handle ID user count!
*
* \param flag: Copying options (see BKE_library.h's LIB_ID_COPY_... flags for more).
*/
void BKE_world_copy_data(Main *bmain, World *wrld_dst, const World *wrld_src, const int flag)
2002-10-12 11:37:38 +00:00
{
if (wrld_src->nodetree) {
/* Note: nodetree is *not* in bmain, however this specific case is handled at lower level
* (see BKE_libblock_copy_ex()). */
BKE_id_copy_ex(bmain, (ID *)wrld_src->nodetree, (ID **)&wrld_dst->nodetree, flag);
}
BLI_listbase_clear(&wrld_dst->gpumaterial);
BLI_listbase_clear((ListBase *)&wrld_dst->drawdata);
if ((flag & LIB_ID_COPY_NO_PREVIEW) == 0) {
BKE_previewimg_id_copy(&wrld_dst->id, &wrld_src->id);
}
else {
wrld_dst->preview = NULL;
}
}
World *BKE_world_copy(Main *bmain, const World *wrld)
{
World *wrld_copy;
BKE_id_copy(bmain, &wrld->id, (ID **)&wrld_copy);
return wrld_copy;
}
World *BKE_world_localize(World *wrld)
{
/* TODO(bastien): Replace with something like:
*
* World *wrld_copy;
* BKE_id_copy_ex(bmain, &wrld->id, (ID **)&wrld_copy,
* LIB_ID_COPY_NO_MAIN | LIB_ID_COPY_NO_PREVIEW | LIB_ID_COPY_NO_USER_REFCOUNT,
* false);
* return wrld_copy;
*
* NOTE: Only possible once nested node trees are fully converted to that too. */
World *wrldn;
2018-06-17 17:05:51 +02:00
wrldn = BKE_libblock_copy_for_localize(&wrld->id);
2018-06-17 17:05:51 +02:00
if (wrld->nodetree) {
wrldn->nodetree = ntreeLocalize(wrld->nodetree);
}
2018-06-17 17:05:51 +02:00
wrldn->preview = NULL;
2018-06-17 17:05:51 +02:00
BLI_listbase_clear(&wrldn->gpumaterial);
BLI_listbase_clear((ListBase *)&wrldn->drawdata);
2018-06-17 17:05:51 +02:00
wrldn->id.tag |= LIB_TAG_LOCALIZED;
2018-11-15 16:36:35 +01:00
return wrldn;
2002-10-12 11:37:38 +00:00
}
void BKE_world_make_local(Main *bmain, World *wrld, const bool lib_local)
2002-10-12 11:37:38 +00:00
{
BKE_id_make_local_generic(bmain, &wrld->id, true, lib_local);
2002-10-12 11:37:38 +00:00
}
void BKE_world_eval(struct Depsgraph *depsgraph, World *world)
{
DEG_debug_print_eval(depsgraph, __func__, world->id.name, world);
GPU_material_free(&world->gpumaterial);
}