2011-11-05 13:11:49 +00:00
|
|
|
/*
|
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
*
|
|
|
|
* Contributor(s): none yet.
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file blender/blenkernel/intern/lamp.c
|
|
|
|
* \ingroup bke
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
2012-11-09 13:57:09 +00:00
|
|
|
#include "DNA_anim_types.h"
|
2011-11-05 13:11:49 +00:00
|
|
|
#include "DNA_lamp_types.h"
|
|
|
|
#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"
|
|
|
|
|
|
|
|
#include "BKE_animsys.h"
|
|
|
|
#include "BKE_colortools.h"
|
|
|
|
#include "BKE_icons.h"
|
|
|
|
#include "BKE_global.h"
|
|
|
|
#include "BKE_lamp.h"
|
|
|
|
#include "BKE_library.h"
|
|
|
|
#include "BKE_main.h"
|
|
|
|
#include "BKE_node.h"
|
|
|
|
|
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
|
|
|
void BKE_lamp_init(Lamp *la)
|
2011-11-05 13:11:49 +00:00
|
|
|
{
|
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
|
|
|
BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(la, id));
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
la->r = la->g = la->b = la->k = 1.0f;
|
|
|
|
la->haint = la->energy = 1.0f;
|
|
|
|
la->dist = 25.0f;
|
Cleanup: Internal degrees removal.
This patch changes most of the reamining degrees usage in internal code into radians.
I let a few which I know off asside, for reasons explained below - and I'm not sure to have found out all of them.
WARNING: this introduces forward incompatibility, which means files saved from this version won't open 100% correctly
in previous versions (a few angle properties would use radians values as degrees...).
Details:
- Data:
-- Lamp.spotsize: Game engine exposed this setting in degrees, to not break the API here I kept it as such
(using getter/setter functions), still using radians internally.
-- Mesh.smoothresh: Didn't touch to this one, as we will hopefully replace it completely by loop normals currently in dev.
- Modifiers:
-- EdgeSplitModifierData.split_angle, BevelModifierData.bevel_angle: Done.
- Postprocessing:
-- WipeVars.angle (sequencer's effect), NodeBokehImage.angle, NodeBoxMask.rotation, NodeEllipseMask.rotation: Done.
- BGE:
-- bConstraintActuator: Orientation type done (the minloc[0] & maxloc[0] cases). Did not touch to 'limit location' type,
it can also limit rotation, but it exposes through RNA the same limit_min/limit_max, which hence
can be either distance or angle values, depending on the mode. Will leave this to BGE team.
-- bSoundActuator.cone_outer_angle_3d, bSoundActuator.cone_inner_angle_3d: Done (note I kept degrees in BGE itself,
as it seems this is the expected value here...).
-- bRadarSensor.angle: Done.
Reviewers: brecht, campbellbarton, sergey, gaiaclary, dfelinto, moguri, jbakker, lukastoenne, howardt
Reviewed By: brecht, campbellbarton, sergey, gaiaclary, moguri, jbakker, lukastoenne, howardt
Thanks to all!
Differential Revision: http://developer.blender.org/D59
2013-12-03 20:09:25 +01:00
|
|
|
la->spotsize = DEG2RADF(45.0f);
|
2012-05-06 15:15:33 +00:00
|
|
|
la->spotblend = 0.15f;
|
|
|
|
la->att2 = 1.0f;
|
|
|
|
la->mode = LA_SHAD_BUF;
|
|
|
|
la->bufsize = 512;
|
|
|
|
la->clipsta = 0.5f;
|
|
|
|
la->clipend = 40.0f;
|
|
|
|
la->samp = 3;
|
|
|
|
la->bias = 1.0f;
|
|
|
|
la->soft = 3.0f;
|
|
|
|
la->compressthresh = 0.05f;
|
|
|
|
la->ray_samp = la->ray_sampy = la->ray_sampz = 1;
|
2012-11-08 16:35:10 +00:00
|
|
|
la->area_size = la->area_sizey = la->area_sizez = 0.1f;
|
2012-05-06 15:15:33 +00:00
|
|
|
la->buffers = 1;
|
|
|
|
la->buftype = LA_SHADBUF_HALFWAY;
|
2011-11-05 13:11:49 +00:00
|
|
|
la->ray_samp_method = LA_SAMP_HALTON;
|
|
|
|
la->adapt_thresh = 0.001f;
|
2012-05-06 15:15:33 +00:00
|
|
|
la->preview = NULL;
|
2011-11-05 13:11:49 +00:00
|
|
|
la->falloff_type = LA_FALLOFF_INVSQUARE;
|
|
|
|
la->curfalloff = curvemapping_add(1, 0.0f, 1.0f, 1.0f, 0.0f);
|
|
|
|
la->sun_effect_type = 0;
|
|
|
|
la->horizon_brightness = 1.0;
|
|
|
|
la->spread = 1.0;
|
|
|
|
la->sun_brightness = 1.0;
|
|
|
|
la->sun_size = 1.0;
|
|
|
|
la->backscattered_light = 1.0f;
|
|
|
|
la->atm_turbidity = 2.0f;
|
|
|
|
la->atm_inscattering_factor = 1.0f;
|
|
|
|
la->atm_extinction_factor = 1.0f;
|
|
|
|
la->atm_distance_factor = 1.0f;
|
|
|
|
la->sun_intensity = 1.0f;
|
2012-05-06 15:15:33 +00:00
|
|
|
la->skyblendtype = MA_RAMP_ADD;
|
|
|
|
la->skyblendfac = 1.0f;
|
|
|
|
la->sky_colorspace = BLI_XYZ_CIE;
|
|
|
|
la->sky_exposure = 1.0f;
|
|
|
|
la->shadow_frustum_size = 10.0f;
|
2011-11-05 13:11:49 +00:00
|
|
|
|
|
|
|
curvemapping_initialize(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
|
|
|
}
|
|
|
|
|
|
|
|
Lamp *BKE_lamp_add(Main *bmain, const char *name)
|
|
|
|
{
|
|
|
|
Lamp *la;
|
|
|
|
|
|
|
|
la = BKE_libblock_alloc(bmain, ID_LA, name);
|
|
|
|
|
|
|
|
BKE_lamp_init(la);
|
|
|
|
|
2011-11-05 13:11:49 +00:00
|
|
|
return la;
|
|
|
|
}
|
|
|
|
|
2012-05-05 14:03:12 +00:00
|
|
|
Lamp *BKE_lamp_copy(Lamp *la)
|
2011-11-05 13:11:49 +00:00
|
|
|
{
|
|
|
|
Lamp *lan;
|
|
|
|
int a;
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
lan = BKE_libblock_copy(&la->id);
|
2011-11-05 13:11:49 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (a = 0; a < MAX_MTEX; a++) {
|
2012-03-24 06:18:31 +00:00
|
|
|
if (lan->mtex[a]) {
|
2012-05-06 15:15:33 +00:00
|
|
|
lan->mtex[a] = MEM_mallocN(sizeof(MTex), "copylamptex");
|
2011-11-05 13:11:49 +00:00
|
|
|
memcpy(lan->mtex[a], la->mtex[a], sizeof(MTex));
|
|
|
|
id_us_plus((ID *)lan->mtex[a]->tex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lan->curfalloff = curvemapping_copy(la->curfalloff);
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (la->nodetree)
|
2012-08-22 09:35:46 +00:00
|
|
|
lan->nodetree = ntreeCopyTree(la->nodetree);
|
2011-11-05 13:11:49 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (la->preview)
|
2011-11-05 13:11:49 +00:00
|
|
|
lan->preview = BKE_previewimg_copy(la->preview);
|
|
|
|
|
2015-01-09 09:52:51 +01:00
|
|
|
if (la->id.lib) {
|
|
|
|
BKE_id_lib_local_paths(G.main, la->id.lib, &lan->id);
|
|
|
|
}
|
|
|
|
|
2011-11-05 13:11:49 +00:00
|
|
|
return lan;
|
|
|
|
}
|
|
|
|
|
|
|
|
Lamp *localize_lamp(Lamp *la)
|
|
|
|
{
|
|
|
|
Lamp *lan;
|
|
|
|
int a;
|
|
|
|
|
2014-09-29 15:05:02 +06:00
|
|
|
lan = BKE_libblock_copy_nolib(&la->id, false);
|
2011-11-05 13:11:49 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (a = 0; a < MAX_MTEX; a++) {
|
2012-03-24 06:18:31 +00:00
|
|
|
if (lan->mtex[a]) {
|
2012-05-06 15:15:33 +00:00
|
|
|
lan->mtex[a] = MEM_mallocN(sizeof(MTex), "localize_lamp");
|
2011-11-05 13:11:49 +00:00
|
|
|
memcpy(lan->mtex[a], la->mtex[a], sizeof(MTex));
|
|
|
|
/* free lamp decrements */
|
|
|
|
id_us_plus((ID *)lan->mtex[a]->tex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lan->curfalloff = curvemapping_copy(la->curfalloff);
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (la->nodetree)
|
2012-05-06 15:15:33 +00:00
|
|
|
lan->nodetree = ntreeLocalize(la->nodetree);
|
2011-11-05 13:11:49 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
lan->preview = NULL;
|
2011-11-05 13:11:49 +00:00
|
|
|
|
|
|
|
return lan;
|
|
|
|
}
|
|
|
|
|
2012-05-05 16:03:57 +00:00
|
|
|
void BKE_lamp_make_local(Lamp *la)
|
2011-11-05 13:11:49 +00:00
|
|
|
{
|
2012-05-06 15:15:33 +00:00
|
|
|
Main *bmain = G.main;
|
2011-11-05 13:11:49 +00:00
|
|
|
Object *ob;
|
2014-04-01 11:34:00 +11:00
|
|
|
bool is_local = false, is_lib = false;
|
2011-11-05 13:11:49 +00:00
|
|
|
|
|
|
|
/* - only lib users: do nothing
|
2012-03-03 20:19:11 +00:00
|
|
|
* - only local users: set flag
|
|
|
|
* - mixed: make copy
|
|
|
|
*/
|
2011-11-05 13:11:49 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
if (la->id.lib == NULL) return;
|
|
|
|
if (la->id.us == 1) {
|
2011-11-05 13:11:49 +00:00
|
|
|
id_clear_lib_data(bmain, &la->id);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
ob = bmain->object.first;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (ob) {
|
2012-05-06 15:15:33 +00:00
|
|
|
if (ob->data == la) {
|
2014-04-01 11:34:00 +11:00
|
|
|
if (ob->id.lib) is_lib = true;
|
|
|
|
else is_local = true;
|
2011-11-05 13:11:49 +00:00
|
|
|
}
|
2012-05-06 15:15:33 +00:00
|
|
|
ob = ob->id.next;
|
2011-11-05 13:11:49 +00:00
|
|
|
}
|
|
|
|
|
2014-04-01 11:34:00 +11:00
|
|
|
if (is_local && is_lib == false) {
|
2011-11-05 13:11:49 +00:00
|
|
|
id_clear_lib_data(bmain, &la->id);
|
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
else if (is_local && is_lib) {
|
2012-05-06 15:15:33 +00:00
|
|
|
Lamp *la_new = BKE_lamp_copy(la);
|
|
|
|
la_new->id.us = 0;
|
2011-11-05 13:11:49 +00:00
|
|
|
|
|
|
|
/* Remap paths of new ID using old library as base. */
|
2011-11-30 00:32:13 +00:00
|
|
|
BKE_id_lib_local_paths(bmain, la->id.lib, &la_new->id);
|
2011-11-05 13:11:49 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
ob = bmain->object.first;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (ob) {
|
2012-05-06 15:15:33 +00:00
|
|
|
if (ob->data == la) {
|
2011-11-05 13:11:49 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
if (ob->id.lib == NULL) {
|
|
|
|
ob->data = la_new;
|
2011-11-30 00:32:13 +00:00
|
|
|
la_new->id.us++;
|
2011-11-05 13:11:49 +00:00
|
|
|
la->id.us--;
|
|
|
|
}
|
|
|
|
}
|
2012-05-06 15:15:33 +00:00
|
|
|
ob = ob->id.next;
|
2011-11-05 13:11:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-05 14:03:12 +00:00
|
|
|
void BKE_lamp_free(Lamp *la)
|
2011-11-05 13:11:49 +00:00
|
|
|
{
|
|
|
|
MTex *mtex;
|
|
|
|
int a;
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (a = 0; a < MAX_MTEX; a++) {
|
|
|
|
mtex = la->mtex[a];
|
2012-03-24 06:18:31 +00:00
|
|
|
if (mtex && mtex->tex) mtex->tex->id.us--;
|
|
|
|
if (mtex) MEM_freeN(mtex);
|
2011-11-05 13:11:49 +00:00
|
|
|
}
|
|
|
|
|
2015-04-04 15:13:56 +11:00
|
|
|
BKE_animdata_free((ID *)la);
|
2011-11-05 13:11:49 +00:00
|
|
|
|
|
|
|
curvemapping_free(la->curfalloff);
|
|
|
|
|
|
|
|
/* is no lib link block, but lamp extension */
|
2012-03-24 06:18:31 +00:00
|
|
|
if (la->nodetree) {
|
2012-08-22 09:35:46 +00:00
|
|
|
ntreeFreeTree(la->nodetree);
|
2011-11-05 13:11:49 +00:00
|
|
|
MEM_freeN(la->nodetree);
|
|
|
|
}
|
|
|
|
|
|
|
|
BKE_previewimg_free(&la->preview);
|
2015-05-11 16:29:12 +02:00
|
|
|
BKE_icon_id_delete(&la->id);
|
2011-11-05 13:11:49 +00:00
|
|
|
la->id.icon_id = 0;
|
|
|
|
}
|
|
|
|
|
2012-11-09 13:57:09 +00:00
|
|
|
/* Calculate all drivers for lamps, see material_drivers_update for why this is a bad hack */
|
|
|
|
|
|
|
|
static void lamp_node_drivers_update(Scene *scene, bNodeTree *ntree, float ctime)
|
|
|
|
{
|
|
|
|
bNode *node;
|
|
|
|
|
|
|
|
/* nodetree itself */
|
|
|
|
if (ntree->adt && ntree->adt->drivers.first)
|
|
|
|
BKE_animsys_evaluate_animdata(scene, &ntree->id, ntree->adt, ctime, ADT_RECALC_DRIVERS);
|
|
|
|
|
|
|
|
/* nodes */
|
|
|
|
for (node = ntree->nodes.first; node; node = node->next)
|
|
|
|
if (node->id && node->type == NODE_GROUP)
|
|
|
|
lamp_node_drivers_update(scene, (bNodeTree *)node->id, ctime);
|
|
|
|
}
|
|
|
|
|
|
|
|
void lamp_drivers_update(Scene *scene, Lamp *la, float ctime)
|
|
|
|
{
|
|
|
|
/* Prevent infinite recursion by checking (and tagging the lamp) as having been visited already
|
|
|
|
* (see BKE_scene_update_tagged()). This assumes la->id.flag & LIB_DOIT isn't set by anything else
|
|
|
|
* in the meantime... [#32017] */
|
|
|
|
if (la->id.flag & LIB_DOIT)
|
|
|
|
return;
|
2013-05-12 13:33:20 +00:00
|
|
|
|
|
|
|
la->id.flag |= LIB_DOIT;
|
2012-11-09 13:57:09 +00:00
|
|
|
|
|
|
|
/* lamp itself */
|
|
|
|
if (la->adt && la->adt->drivers.first)
|
|
|
|
BKE_animsys_evaluate_animdata(scene, &la->id, la->adt, ctime, ADT_RECALC_DRIVERS);
|
|
|
|
|
|
|
|
/* nodes */
|
|
|
|
if (la->nodetree)
|
|
|
|
lamp_node_drivers_update(scene, la->nodetree, ctime);
|
2013-05-12 13:33:20 +00:00
|
|
|
|
|
|
|
la->id.flag &= ~LIB_DOIT;
|
2012-11-09 13:57:09 +00:00
|
|
|
}
|
|
|
|
|