2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
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
|
2008-04-16 22:40:48 +00:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
*
|
|
|
|
* Contributor(s): none yet.
|
|
|
|
*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
|
|
|
|
2011-02-25 13:35:59 +00:00
|
|
|
/** \file gameengine/Ketsji/KX_Light.cpp
|
|
|
|
* \ingroup ketsji
|
|
|
|
*/
|
|
|
|
|
2012-10-15 02:15:07 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
# pragma warning (disable:4786)
|
2002-10-12 11:37:38 +00:00
|
|
|
#endif
|
|
|
|
|
2012-07-29 17:49:14 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "KX_Light.h"
|
2008-07-10 12:47:20 +00:00
|
|
|
#include "KX_Camera.h"
|
|
|
|
#include "RAS_IRasterizer.h"
|
2013-11-04 19:22:10 +00:00
|
|
|
#include "RAS_ICanvas.h"
|
2014-03-28 05:32:06 +00:00
|
|
|
#include "RAS_ILightObject.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2004-05-30 11:09:46 +00:00
|
|
|
#include "KX_PyMath.h"
|
|
|
|
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
#include "DNA_object_types.h"
|
2009-06-09 13:51:32 +00:00
|
|
|
#include "DNA_scene_types.h"
|
2012-05-01 02:50:17 +00:00
|
|
|
#include "DNA_lamp_types.h"
|
2013-08-17 04:37:25 +00:00
|
|
|
|
|
|
|
#include "BKE_scene.h"
|
|
|
|
#include "MEM_guardedalloc.h"
|
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 19:09:25 +00:00
|
|
|
|
|
|
|
#include "BLI_math.h"
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
KX_LightObject::KX_LightObject(void* sgReplicationInfo,SG_Callbacks callbacks,
|
2013-11-04 19:21:07 +00:00
|
|
|
RAS_IRasterizer* rasterizer,
|
2014-03-28 05:32:06 +00:00
|
|
|
RAS_ILightObject* lightobj,
|
2012-10-15 02:15:07 +00:00
|
|
|
bool glsl)
|
2009-06-28 11:22:26 +00:00
|
|
|
: KX_GameObject(sgReplicationInfo,callbacks),
|
2013-11-04 19:21:07 +00:00
|
|
|
m_rasterizer(rasterizer)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
m_lightobj = lightobj;
|
2014-03-28 05:32:06 +00:00
|
|
|
m_lightobj->m_scene = sgReplicationInfo;
|
|
|
|
m_lightobj->m_light = this;
|
|
|
|
m_rasterizer->AddLight(m_lightobj);
|
|
|
|
m_lightobj->m_glsl = glsl;
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
m_blenderscene = ((KX_Scene*)sgReplicationInfo)->GetBlenderScene();
|
2013-08-17 04:37:25 +00:00
|
|
|
m_base = NULL;
|
2002-10-12 11:37:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
KX_LightObject::~KX_LightObject()
|
|
|
|
{
|
2014-03-28 05:32:06 +00:00
|
|
|
if (m_lightobj) {
|
|
|
|
m_rasterizer->RemoveLight(m_lightobj);
|
|
|
|
delete(m_lightobj);
|
2008-09-10 09:51:06 +00:00
|
|
|
}
|
|
|
|
|
2013-08-17 04:37:25 +00:00
|
|
|
if (m_base) {
|
|
|
|
BKE_scene_base_unlink(m_blenderscene, m_base);
|
|
|
|
MEM_freeN(m_base);
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CValue* KX_LightObject::GetReplica()
|
|
|
|
{
|
|
|
|
|
|
|
|
KX_LightObject* replica = new KX_LightObject(*this);
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
2009-04-22 12:16:41 +00:00
|
|
|
replica->ProcessReplica();
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2014-03-28 05:32:06 +00:00
|
|
|
replica->m_lightobj = m_lightobj->Clone();
|
|
|
|
replica->m_lightobj->m_light = replica;
|
|
|
|
m_rasterizer->AddLight(replica->m_lightobj);
|
2014-02-04 18:54:09 +00:00
|
|
|
if (m_base)
|
|
|
|
m_base = NULL;
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
return replica;
|
|
|
|
}
|
2004-05-30 11:09:46 +00:00
|
|
|
|
2013-08-17 04:37:25 +00:00
|
|
|
void KX_LightObject::UpdateScene(KX_Scene *kxscene)
|
|
|
|
{
|
2014-03-28 05:32:06 +00:00
|
|
|
m_lightobj->m_scene = (void*)kxscene;
|
2013-08-17 04:37:25 +00:00
|
|
|
m_blenderscene = kxscene->GetBlenderScene();
|
|
|
|
m_base = BKE_scene_base_add(m_blenderscene, GetBlenderObject());
|
|
|
|
}
|
|
|
|
|
2014-03-28 05:32:06 +00:00
|
|
|
void KX_LightObject::SetLayer(int layer)
|
2008-07-10 12:47:20 +00:00
|
|
|
{
|
2014-03-28 05:32:06 +00:00
|
|
|
m_lightobj->m_layer = layer;
|
2012-05-01 02:50:17 +00:00
|
|
|
}
|
|
|
|
|
2010-10-31 04:11:39 +00:00
|
|
|
#ifdef WITH_PYTHON
|
2009-04-21 23:15:18 +00:00
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
/* Python Integration Hooks */
|
|
|
|
/* ------------------------------------------------------------------------- */
|
2004-05-30 11:09:46 +00:00
|
|
|
|
|
|
|
PyTypeObject KX_LightObject::Type = {
|
2009-04-29 16:54:45 +00:00
|
|
|
PyVarObject_HEAD_INIT(NULL, 0)
|
2009-08-10 00:07:34 +00:00
|
|
|
"KX_LightObject",
|
|
|
|
sizeof(PyObjectPlus_Proxy),
|
|
|
|
0,
|
|
|
|
py_base_dealloc,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
py_base_repr,
|
|
|
|
0,
|
|
|
|
&KX_GameObject::Sequence,
|
|
|
|
&KX_GameObject::Mapping,
|
|
|
|
0,0,0,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
|
|
|
|
0,0,0,0,0,0,0,
|
|
|
|
Methods,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
&KX_GameObject::Type,
|
|
|
|
0,0,0,0,0,0,
|
|
|
|
py_base_new
|
2004-05-30 11:09:46 +00:00
|
|
|
};
|
2009-04-21 23:15:18 +00:00
|
|
|
|
|
|
|
PyMethodDef KX_LightObject::Methods[] = {
|
|
|
|
{NULL,NULL} //Sentinel
|
|
|
|
};
|
|
|
|
|
|
|
|
PyAttributeDef KX_LightObject::Attributes[] = {
|
2014-03-28 05:32:06 +00:00
|
|
|
KX_PYATTRIBUTE_RW_FUNCTION("layer", KX_LightObject, pyattr_get_layer, pyattr_set_layer),
|
|
|
|
KX_PYATTRIBUTE_RW_FUNCTION("energy", KX_LightObject, pyattr_get_energy, pyattr_set_energy),
|
|
|
|
KX_PYATTRIBUTE_RW_FUNCTION("distance", KX_LightObject, pyattr_get_distance, pyattr_set_distance),
|
2009-04-21 23:15:18 +00:00
|
|
|
KX_PYATTRIBUTE_RW_FUNCTION("color", KX_LightObject, pyattr_get_color, pyattr_set_color),
|
2014-03-28 05:32:06 +00:00
|
|
|
KX_PYATTRIBUTE_RW_FUNCTION("lin_attenuation", KX_LightObject, pyattr_get_lin_attenuation, pyattr_set_lin_attenuation),
|
|
|
|
KX_PYATTRIBUTE_RW_FUNCTION("quad_attenuation", KX_LightObject, pyattr_get_quad_attenuation, pyattr_set_quad_attenuation),
|
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 19:09:25 +00:00
|
|
|
KX_PYATTRIBUTE_RW_FUNCTION("spotsize", KX_LightObject, pyattr_get_spotsize, pyattr_set_spotsize),
|
2014-03-28 05:32:06 +00:00
|
|
|
KX_PYATTRIBUTE_RW_FUNCTION("spotblend", KX_LightObject, pyattr_get_spotblend, pyattr_set_spotblend),
|
2009-04-21 23:15:18 +00:00
|
|
|
KX_PYATTRIBUTE_RO_FUNCTION("SPOT", KX_LightObject, pyattr_get_typeconst),
|
|
|
|
KX_PYATTRIBUTE_RO_FUNCTION("SUN", KX_LightObject, pyattr_get_typeconst),
|
|
|
|
KX_PYATTRIBUTE_RO_FUNCTION("NORMAL", KX_LightObject, pyattr_get_typeconst),
|
|
|
|
KX_PYATTRIBUTE_RW_FUNCTION("type", KX_LightObject, pyattr_get_type, pyattr_set_type),
|
|
|
|
{ NULL } //Sentinel
|
|
|
|
};
|
|
|
|
|
2014-03-28 05:32:06 +00:00
|
|
|
PyObject *KX_LightObject::pyattr_get_layer(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
|
|
|
{
|
|
|
|
KX_LightObject* self = static_cast<KX_LightObject*>(self_v);
|
|
|
|
return PyLong_FromLong(self->m_lightobj->m_layer);
|
|
|
|
}
|
|
|
|
|
|
|
|
int KX_LightObject::pyattr_set_layer(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
|
|
|
|
{
|
|
|
|
KX_LightObject* self = static_cast<KX_LightObject*>(self_v);
|
|
|
|
|
|
|
|
if (PyLong_Check(value)) {
|
|
|
|
int val = PyLong_AsLong(value);
|
|
|
|
if (val < 1)
|
|
|
|
val = 1;
|
|
|
|
else if (val > 20)
|
|
|
|
val = 20;
|
|
|
|
|
|
|
|
self->m_lightobj->m_layer = val;
|
|
|
|
return PY_SET_ATTR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyErr_Format(PyExc_TypeError, "expected an integer for attribute \"%s\"", attrdef->m_name);
|
|
|
|
return PY_SET_ATTR_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyObject *KX_LightObject::pyattr_get_energy(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
|
|
|
{
|
|
|
|
KX_LightObject* self = static_cast<KX_LightObject*>(self_v);
|
|
|
|
return PyFloat_FromDouble(self->m_lightobj->m_energy);
|
|
|
|
}
|
|
|
|
|
|
|
|
int KX_LightObject::pyattr_set_energy(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
|
|
|
|
{
|
|
|
|
KX_LightObject* self = static_cast<KX_LightObject*>(self_v);
|
|
|
|
|
|
|
|
if (PyFloat_Check(value)) {
|
|
|
|
float val = PyFloat_AsDouble(value);
|
|
|
|
if (val < 0)
|
|
|
|
val = 0;
|
|
|
|
else if (val > 10)
|
|
|
|
val = 10;
|
|
|
|
|
|
|
|
self->m_lightobj->m_energy = val;
|
|
|
|
return PY_SET_ATTR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyErr_Format(PyExc_TypeError, "expected float value for attribute \"%s\"", attrdef->m_name);
|
|
|
|
return PY_SET_ATTR_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyObject *KX_LightObject::pyattr_get_distance(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
|
|
|
{
|
|
|
|
KX_LightObject* self = static_cast<KX_LightObject*>(self_v);
|
|
|
|
return PyFloat_FromDouble(self->m_lightobj->m_distance);
|
|
|
|
}
|
|
|
|
|
|
|
|
int KX_LightObject::pyattr_set_distance(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
|
|
|
|
{
|
|
|
|
KX_LightObject* self = static_cast<KX_LightObject*>(self_v);
|
|
|
|
|
|
|
|
if (PyFloat_Check(value)) {
|
|
|
|
float val = PyFloat_AsDouble(value);
|
|
|
|
if (val < 0.01)
|
|
|
|
val = 0.01;
|
|
|
|
else if (val > 5000.f)
|
|
|
|
val = 5000.f;
|
|
|
|
|
2014-07-29 03:12:17 +00:00
|
|
|
self->m_lightobj->m_distance = val;
|
2014-03-28 05:32:06 +00:00
|
|
|
return PY_SET_ATTR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyErr_Format(PyExc_TypeError, "expected float value for attribute \"%s\"", attrdef->m_name);
|
|
|
|
return PY_SET_ATTR_FAIL;
|
|
|
|
}
|
|
|
|
|
2012-09-16 04:58:18 +00:00
|
|
|
PyObject *KX_LightObject::pyattr_get_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
2009-04-21 23:15:18 +00:00
|
|
|
{
|
|
|
|
KX_LightObject* self = static_cast<KX_LightObject*>(self_v);
|
2014-08-23 18:24:19 +00:00
|
|
|
return Py_BuildValue("[fff]", self->m_lightobj->m_color[0], self->m_lightobj->m_color[1], self->m_lightobj->m_color[2]);
|
2009-04-21 23:15:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int KX_LightObject::pyattr_set_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
|
|
|
|
{
|
|
|
|
KX_LightObject* self = static_cast<KX_LightObject*>(self_v);
|
|
|
|
|
|
|
|
MT_Vector3 color;
|
|
|
|
if (PyVecTo(value, color))
|
|
|
|
{
|
2014-03-28 05:32:06 +00:00
|
|
|
self->m_lightobj->m_color[0] = color[0];
|
|
|
|
self->m_lightobj->m_color[1] = color[1];
|
|
|
|
self->m_lightobj->m_color[2] = color[2];
|
2009-05-19 07:16:40 +00:00
|
|
|
return PY_SET_ATTR_SUCCESS;
|
2009-04-21 23:15:18 +00:00
|
|
|
}
|
2009-05-19 07:16:40 +00:00
|
|
|
return PY_SET_ATTR_FAIL;
|
2009-04-21 23:15:18 +00:00
|
|
|
}
|
|
|
|
|
2014-03-28 05:32:06 +00:00
|
|
|
PyObject *KX_LightObject::pyattr_get_lin_attenuation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
|
|
|
{
|
|
|
|
KX_LightObject* self = static_cast<KX_LightObject*>(self_v);
|
|
|
|
return PyFloat_FromDouble(self->m_lightobj->m_att1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int KX_LightObject::pyattr_set_lin_attenuation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
|
|
|
|
{
|
|
|
|
KX_LightObject* self = static_cast<KX_LightObject*>(self_v);
|
|
|
|
|
|
|
|
if (PyFloat_Check(value)) {
|
|
|
|
float val = PyFloat_AsDouble(value);
|
|
|
|
if (val < 0.f)
|
|
|
|
val = 0.f;
|
|
|
|
else if (val > 1.f)
|
|
|
|
val = 1.f;
|
|
|
|
|
|
|
|
self->m_lightobj->m_att1 = val;
|
|
|
|
return PY_SET_ATTR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyErr_Format(PyExc_TypeError, "expected float value for attribute \"%s\"", attrdef->m_name);
|
|
|
|
return PY_SET_ATTR_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyObject *KX_LightObject::pyattr_get_quad_attenuation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
|
|
|
{
|
|
|
|
KX_LightObject* self = static_cast<KX_LightObject*>(self_v);
|
|
|
|
return PyFloat_FromDouble(self->m_lightobj->m_att2);
|
|
|
|
}
|
|
|
|
|
|
|
|
int KX_LightObject::pyattr_set_quad_attenuation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
|
|
|
|
{
|
|
|
|
KX_LightObject* self = static_cast<KX_LightObject*>(self_v);
|
|
|
|
|
|
|
|
if (PyFloat_Check(value)) {
|
|
|
|
float val = PyFloat_AsDouble(value);
|
|
|
|
if (val < 0.f)
|
|
|
|
val = 0.f;
|
|
|
|
else if (val > 1.f)
|
|
|
|
val = 1.f;
|
|
|
|
|
|
|
|
self->m_lightobj->m_att2 = val;
|
|
|
|
return PY_SET_ATTR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyErr_Format(PyExc_TypeError, "expected float value for attribute \"%s\"", attrdef->m_name);
|
|
|
|
return PY_SET_ATTR_FAIL;
|
|
|
|
}
|
|
|
|
|
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 19:09:25 +00:00
|
|
|
PyObject *KX_LightObject::pyattr_get_spotsize(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
|
|
|
{
|
|
|
|
KX_LightObject* self = static_cast<KX_LightObject*>(self_v);
|
2014-03-28 05:32:06 +00:00
|
|
|
return PyFloat_FromDouble(RAD2DEG(self->m_lightobj->m_spotsize));
|
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 19:09:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int KX_LightObject::pyattr_set_spotsize(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
|
|
|
|
{
|
|
|
|
KX_LightObject* self = static_cast<KX_LightObject*>(self_v);
|
|
|
|
|
2014-03-28 05:32:06 +00:00
|
|
|
if (PyFloat_Check(value)) {
|
|
|
|
float val = PyFloat_AsDouble(value);
|
|
|
|
if (val < 0.f)
|
|
|
|
val = 0.f;
|
|
|
|
else if (val > 180.f)
|
|
|
|
val = 180.f;
|
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 19:09:25 +00:00
|
|
|
|
2014-03-28 05:32:06 +00:00
|
|
|
self->m_lightobj->m_spotsize = DEG2RAD(val);
|
|
|
|
return PY_SET_ATTR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyErr_Format(PyExc_TypeError, "expected float value for attribute \"%s\"", attrdef->m_name);
|
|
|
|
return PY_SET_ATTR_FAIL;
|
|
|
|
}
|
|
|
|
PyObject *KX_LightObject::pyattr_get_spotblend(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
|
|
|
{
|
|
|
|
KX_LightObject* self = static_cast<KX_LightObject*>(self_v);
|
|
|
|
return PyFloat_FromDouble(self->m_lightobj->m_spotblend);
|
|
|
|
}
|
|
|
|
|
|
|
|
int KX_LightObject::pyattr_set_spotblend(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
|
|
|
|
{
|
|
|
|
KX_LightObject* self = static_cast<KX_LightObject*>(self_v);
|
|
|
|
|
|
|
|
if (PyFloat_Check(value)) {
|
|
|
|
float val = PyFloat_AsDouble(value);
|
|
|
|
if (val < 0.f)
|
|
|
|
val = 0.f;
|
|
|
|
else if (val > 1.f)
|
|
|
|
val = 1.f;
|
|
|
|
|
|
|
|
self->m_lightobj->m_spotblend = val;
|
|
|
|
return PY_SET_ATTR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyErr_Format(PyExc_TypeError, "expected float value for attribute \"%s\"", attrdef->m_name);
|
|
|
|
return PY_SET_ATTR_FAIL;
|
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 19:09:25 +00:00
|
|
|
}
|
|
|
|
|
2012-09-16 04:58:18 +00:00
|
|
|
PyObject *KX_LightObject::pyattr_get_typeconst(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
2009-04-21 23:15:18 +00:00
|
|
|
{
|
2012-09-16 04:58:18 +00:00
|
|
|
PyObject *retvalue;
|
2009-04-21 23:15:18 +00:00
|
|
|
|
|
|
|
const char* type = attrdef->m_name;
|
|
|
|
|
2012-03-24 07:52:14 +00:00
|
|
|
if (!strcmp(type, "SPOT")) {
|
2014-03-28 05:32:06 +00:00
|
|
|
retvalue = PyLong_FromLong(RAS_ILightObject::LIGHT_SPOT);
|
2010-02-04 23:51:41 +00:00
|
|
|
} else if (!strcmp(type, "SUN")) {
|
2014-03-28 05:32:06 +00:00
|
|
|
retvalue = PyLong_FromLong(RAS_ILightObject::LIGHT_SUN);
|
2010-02-04 23:51:41 +00:00
|
|
|
} else if (!strcmp(type, "NORMAL")) {
|
2014-03-28 05:32:06 +00:00
|
|
|
retvalue = PyLong_FromLong(RAS_ILightObject::LIGHT_NORMAL);
|
2009-04-21 23:15:18 +00:00
|
|
|
}
|
2011-09-01 02:12:53 +00:00
|
|
|
else {
|
|
|
|
/* should never happen */
|
|
|
|
PyErr_SetString(PyExc_TypeError, "light.type: internal error, invalid light type");
|
|
|
|
retvalue = NULL;
|
|
|
|
}
|
2009-04-21 23:15:18 +00:00
|
|
|
|
|
|
|
return retvalue;
|
|
|
|
}
|
|
|
|
|
2012-09-16 04:58:18 +00:00
|
|
|
PyObject *KX_LightObject::pyattr_get_type(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
2009-04-21 23:15:18 +00:00
|
|
|
{
|
|
|
|
KX_LightObject* self = static_cast<KX_LightObject*>(self_v);
|
2014-03-28 05:32:06 +00:00
|
|
|
return PyLong_FromLong(self->m_lightobj->m_type);
|
2009-04-21 23:15:18 +00:00
|
|
|
}
|
|
|
|
|
2012-09-16 04:58:18 +00:00
|
|
|
int KX_LightObject::pyattr_set_type(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
|
2009-04-21 23:15:18 +00:00
|
|
|
{
|
|
|
|
KX_LightObject* self = static_cast<KX_LightObject*>(self_v);
|
2012-11-21 02:28:36 +00:00
|
|
|
const int val = PyLong_AsLong(value);
|
2012-03-24 07:52:14 +00:00
|
|
|
if ((val==-1 && PyErr_Occurred()) || val<0 || val>2) {
|
2009-05-19 07:16:40 +00:00
|
|
|
PyErr_SetString(PyExc_ValueError, "light.type= val: KX_LightObject, expected an int between 0 and 2");
|
|
|
|
return PY_SET_ATTR_FAIL;
|
|
|
|
}
|
|
|
|
|
2012-10-21 07:58:38 +00:00
|
|
|
switch (val) {
|
2009-04-21 23:15:18 +00:00
|
|
|
case 0:
|
2014-03-28 05:32:06 +00:00
|
|
|
self->m_lightobj->m_type = self->m_lightobj->LIGHT_SPOT;
|
2009-04-21 23:15:18 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2014-03-28 05:32:06 +00:00
|
|
|
self->m_lightobj->m_type = self->m_lightobj->LIGHT_SUN;
|
2009-04-21 23:15:18 +00:00
|
|
|
break;
|
2009-05-19 07:16:40 +00:00
|
|
|
case 2:
|
2014-03-28 05:32:06 +00:00
|
|
|
self->m_lightobj->m_type = self->m_lightobj->LIGHT_NORMAL;
|
2009-04-21 23:15:18 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PY_SET_ATTR_SUCCESS;
|
|
|
|
}
|
2010-10-31 04:11:39 +00:00
|
|
|
#endif // WITH_PYTHON
|