2002-10-12 11:37:38 +00:00
|
|
|
/**
|
|
|
|
* $Id$
|
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,
|
|
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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.
|
|
|
|
*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
|
|
|
|
2002-11-25 15:29:57 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
|
|
|
|
#pragma warning (disable : 4786)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "KX_Light.h"
|
2008-07-10 12:47:20 +00:00
|
|
|
#include "KX_Camera.h"
|
|
|
|
#include "RAS_IRasterizer.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "RAS_IRenderTools.h"
|
|
|
|
|
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"
|
2008-07-10 12:47:20 +00:00
|
|
|
#include "GPU_material.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
KX_LightObject::KX_LightObject(void* sgReplicationInfo,SG_Callbacks callbacks,
|
|
|
|
class RAS_IRenderTools* rendertools,
|
2004-05-30 11:09:46 +00:00
|
|
|
const RAS_LightObject& lightobj,
|
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
|
|
|
bool glsl,
|
2004-05-30 11:09:46 +00:00
|
|
|
PyTypeObject* T
|
2002-10-12 11:37:38 +00:00
|
|
|
)
|
|
|
|
:
|
2004-05-30 11:09:46 +00:00
|
|
|
KX_GameObject(sgReplicationInfo,callbacks,T),
|
2002-10-12 11:37:38 +00:00
|
|
|
m_rendertools(rendertools)
|
|
|
|
{
|
|
|
|
m_lightobj = lightobj;
|
|
|
|
m_lightobj.m_worldmatrix = GetOpenGLMatrixPtr();
|
2009-04-20 15:06:46 +00:00
|
|
|
m_lightobj.m_scene = sgReplicationInfo;
|
2002-10-12 11:37:38 +00:00
|
|
|
m_rendertools->AddLight(&m_lightobj);
|
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_glsl = glsl;
|
|
|
|
m_blenderscene = ((KX_Scene*)sgReplicationInfo)->GetBlenderScene();
|
2002-10-12 11:37:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
KX_LightObject::~KX_LightObject()
|
|
|
|
{
|
2008-09-10 09:51:06 +00:00
|
|
|
GPULamp *lamp;
|
|
|
|
|
|
|
|
if((lamp = GetGPULamp())) {
|
|
|
|
float obmat[4][4] = {{0}};
|
|
|
|
GPU_lamp_update(lamp, 0, obmat);
|
|
|
|
}
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
m_rendertools->RemoveLight(&m_lightobj);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
// this will copy properties and so on...
|
|
|
|
CValue::AddDataToReplica(replica);
|
|
|
|
|
|
|
|
ProcessReplica(replica);
|
|
|
|
|
|
|
|
replica->m_lightobj.m_worldmatrix = replica->GetOpenGLMatrixPtr();
|
|
|
|
m_rendertools->AddLight(&replica->m_lightobj);
|
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
|
|
|
|
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
|
|
|
GPULamp *KX_LightObject::GetGPULamp()
|
|
|
|
{
|
|
|
|
if(m_glsl)
|
|
|
|
return GPU_lamp_from_blender(m_blenderscene, GetBlenderObject(), GetBlenderGroupObject());
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-07-10 12:47:20 +00:00
|
|
|
void KX_LightObject::Update()
|
|
|
|
{
|
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
|
|
|
GPULamp *lamp;
|
|
|
|
|
|
|
|
if((lamp = GetGPULamp())) {
|
2008-07-10 12:47:20 +00:00
|
|
|
float obmat[4][4];
|
|
|
|
double *dobmat = GetOpenGLMatrixPtr()->getPointer();
|
|
|
|
|
|
|
|
for(int i=0; i<4; i++)
|
|
|
|
for(int j=0; j<4; j++, dobmat++)
|
|
|
|
obmat[i][j] = (float)*dobmat;
|
|
|
|
|
2008-09-05 14:33:36 +00:00
|
|
|
GPU_lamp_update(lamp, m_lightobj.m_layer, obmat);
|
2008-07-10 12:47:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool KX_LightObject::HasShadowBuffer()
|
|
|
|
{
|
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
|
|
|
GPULamp *lamp;
|
|
|
|
|
|
|
|
if((lamp = GetGPULamp()))
|
|
|
|
return GPU_lamp_has_shadow_buffer(lamp);
|
|
|
|
else
|
|
|
|
return false;
|
2008-07-10 12:47:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int KX_LightObject::GetShadowLayer()
|
|
|
|
{
|
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
|
|
|
GPULamp *lamp;
|
|
|
|
|
|
|
|
if((lamp = GetGPULamp()))
|
|
|
|
return GPU_lamp_shadow_layer(lamp);
|
2008-07-10 12:47:20 +00:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void KX_LightObject::BindShadowBuffer(RAS_IRasterizer *ras, KX_Camera *cam, MT_Transform& camtrans)
|
|
|
|
{
|
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
|
|
|
GPULamp *lamp;
|
2008-07-10 12:47:20 +00:00
|
|
|
float viewmat[4][4], winmat[4][4];
|
|
|
|
int winsize;
|
|
|
|
|
|
|
|
/* bind framebuffer */
|
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
|
|
|
lamp = GetGPULamp();
|
|
|
|
GPU_lamp_shadow_buffer_bind(lamp, viewmat, &winsize, winmat);
|
2008-07-10 12:47:20 +00:00
|
|
|
|
|
|
|
/* setup camera transformation */
|
|
|
|
MT_Matrix4x4 modelviewmat((float*)viewmat);
|
|
|
|
MT_Matrix4x4 projectionmat((float*)winmat);
|
|
|
|
|
|
|
|
MT_Transform trans = MT_Transform((float*)viewmat);
|
|
|
|
camtrans.invert(trans);
|
|
|
|
|
|
|
|
cam->SetModelviewMatrix(modelviewmat);
|
|
|
|
cam->SetProjectionMatrix(projectionmat);
|
|
|
|
|
|
|
|
cam->NodeSetLocalPosition(camtrans.getOrigin());
|
|
|
|
cam->NodeSetLocalOrientation(camtrans.getBasis());
|
2009-04-20 15:06:46 +00:00
|
|
|
cam->NodeUpdateGS(0);
|
2008-07-10 12:47:20 +00:00
|
|
|
|
|
|
|
/* setup rasterizer transformations */
|
|
|
|
ras->SetProjectionMatrix(projectionmat);
|
|
|
|
ras->SetViewMatrix(modelviewmat, cam->NodeGetWorldPosition(),
|
|
|
|
cam->GetCameraLocation(), cam->GetCameraOrientation());
|
|
|
|
}
|
|
|
|
|
|
|
|
void KX_LightObject::UnbindShadowBuffer(RAS_IRasterizer *ras)
|
|
|
|
{
|
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
|
|
|
GPULamp *lamp = GetGPULamp();
|
|
|
|
GPU_lamp_shadow_buffer_unbind(lamp);
|
2008-07-10 12:47:20 +00:00
|
|
|
}
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
PyObject* KX_LightObject::py_getattro(PyObject *attr)
|
2004-05-30 11:09:46 +00:00
|
|
|
{
|
2009-04-20 15:06:46 +00:00
|
|
|
char *attr_str= PyString_AsString(attr);
|
|
|
|
|
|
|
|
if (!strcmp(attr_str, "layer"))
|
2004-05-30 11:09:46 +00:00
|
|
|
return PyInt_FromLong(m_lightobj.m_layer);
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
if (!strcmp(attr_str, "energy"))
|
2004-05-30 11:09:46 +00:00
|
|
|
return PyFloat_FromDouble(m_lightobj.m_energy);
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
if (!strcmp(attr_str, "distance"))
|
2004-05-30 11:09:46 +00:00
|
|
|
return PyFloat_FromDouble(m_lightobj.m_distance);
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
if (!strcmp(attr_str, "colour") || !strcmp(attr_str, "color"))
|
2004-05-30 11:09:46 +00:00
|
|
|
return Py_BuildValue("[fff]", m_lightobj.m_red, m_lightobj.m_green, m_lightobj.m_blue);
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
if (!strcmp(attr_str, "lin_attenuation"))
|
2004-05-30 11:09:46 +00:00
|
|
|
return PyFloat_FromDouble(m_lightobj.m_att1);
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
if (!strcmp(attr_str, "quad_attenuation"))
|
2004-06-07 11:01:31 +00:00
|
|
|
return PyFloat_FromDouble(m_lightobj.m_att2);
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
if (!strcmp(attr_str, "spotsize"))
|
2004-05-30 11:09:46 +00:00
|
|
|
return PyFloat_FromDouble(m_lightobj.m_spotsize);
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
if (!strcmp(attr_str, "spotblend"))
|
2004-05-30 11:09:46 +00:00
|
|
|
return PyFloat_FromDouble(m_lightobj.m_spotblend);
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
if (!strcmp(attr_str, "SPOT"))
|
2004-05-30 11:09:46 +00:00
|
|
|
return PyInt_FromLong(RAS_LightObject::LIGHT_SPOT);
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
if (!strcmp(attr_str, "SUN"))
|
2004-05-30 11:09:46 +00:00
|
|
|
return PyInt_FromLong(RAS_LightObject::LIGHT_SUN);
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
if (!strcmp(attr_str, "NORMAL"))
|
2004-05-30 11:09:46 +00:00
|
|
|
return PyInt_FromLong(RAS_LightObject::LIGHT_NORMAL);
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
if (!strcmp(attr_str, "type"))
|
2004-05-30 11:09:46 +00:00
|
|
|
return PyInt_FromLong(m_lightobj.m_type);
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
py_getattro_up(KX_GameObject);
|
2004-05-30 11:09:46 +00:00
|
|
|
}
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
|
|
|
|
int KX_LightObject::py_setattro(PyObject *attr, PyObject *pyvalue)
|
|
|
|
{
|
|
|
|
char *attr_str= PyString_AsString(attr);
|
|
|
|
|
2004-05-30 11:09:46 +00:00
|
|
|
if (PyInt_Check(pyvalue))
|
|
|
|
{
|
|
|
|
int value = PyInt_AsLong(pyvalue);
|
2009-04-20 15:06:46 +00:00
|
|
|
if (!strcmp(attr_str, "layer"))
|
2004-05-30 11:09:46 +00:00
|
|
|
{
|
|
|
|
m_lightobj.m_layer = value;
|
2009-04-20 15:06:46 +00:00
|
|
|
return PY_SET_ATTR_SUCCESS;
|
2004-05-30 11:09:46 +00:00
|
|
|
}
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
if (!strcmp(attr_str, "type"))
|
2004-05-30 11:09:46 +00:00
|
|
|
{
|
|
|
|
if (value >= RAS_LightObject::LIGHT_SPOT && value <= RAS_LightObject::LIGHT_NORMAL)
|
|
|
|
m_lightobj.m_type = (RAS_LightObject::LightType) value;
|
2009-04-20 15:06:46 +00:00
|
|
|
return PY_SET_ATTR_SUCCESS;
|
2004-05-30 11:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
if (PyFloat_Check(pyvalue) || PyInt_Check(pyvalue))
|
2004-05-30 11:09:46 +00:00
|
|
|
{
|
|
|
|
float value = PyFloat_AsDouble(pyvalue);
|
2009-04-20 15:06:46 +00:00
|
|
|
if (!strcmp(attr_str, "energy"))
|
2004-05-30 11:09:46 +00:00
|
|
|
{
|
|
|
|
m_lightobj.m_energy = value;
|
2009-04-20 15:06:46 +00:00
|
|
|
return PY_SET_ATTR_SUCCESS;
|
2004-05-30 11:09:46 +00:00
|
|
|
}
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
if (!strcmp(attr_str, "distance"))
|
2004-05-30 11:09:46 +00:00
|
|
|
{
|
|
|
|
m_lightobj.m_distance = value;
|
2009-04-20 15:06:46 +00:00
|
|
|
return PY_SET_ATTR_SUCCESS;
|
2004-05-30 11:09:46 +00:00
|
|
|
}
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
if (!strcmp(attr_str, "lin_attenuation"))
|
2004-05-30 11:09:46 +00:00
|
|
|
{
|
|
|
|
m_lightobj.m_att1 = value;
|
2009-04-20 15:06:46 +00:00
|
|
|
return PY_SET_ATTR_SUCCESS;
|
2004-05-30 11:09:46 +00:00
|
|
|
}
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
if (!strcmp(attr_str, "quad_attenuation"))
|
2004-06-07 11:01:31 +00:00
|
|
|
{
|
|
|
|
m_lightobj.m_att2 = value;
|
2009-04-20 15:06:46 +00:00
|
|
|
return PY_SET_ATTR_SUCCESS;
|
2004-06-07 11:01:31 +00:00
|
|
|
}
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
if (!strcmp(attr_str, "spotsize"))
|
2004-05-30 11:09:46 +00:00
|
|
|
{
|
|
|
|
m_lightobj.m_spotsize = value;
|
2009-04-20 15:06:46 +00:00
|
|
|
return PY_SET_ATTR_SUCCESS;
|
2004-05-30 11:09:46 +00:00
|
|
|
}
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
if (!strcmp(attr_str, "spotblend"))
|
2004-05-30 11:09:46 +00:00
|
|
|
{
|
|
|
|
m_lightobj.m_spotblend = value;
|
2009-04-20 15:06:46 +00:00
|
|
|
return PY_SET_ATTR_SUCCESS;
|
2004-05-30 11:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PySequence_Check(pyvalue))
|
|
|
|
{
|
2009-04-20 15:06:46 +00:00
|
|
|
if (!strcmp(attr_str, "colour") || !strcmp(attr_str, "color"))
|
2004-05-30 11:09:46 +00:00
|
|
|
{
|
2007-04-04 13:18:41 +00:00
|
|
|
MT_Vector3 color;
|
|
|
|
if (PyVecTo(pyvalue, color))
|
2004-07-17 05:28:23 +00:00
|
|
|
{
|
2007-04-04 13:18:41 +00:00
|
|
|
m_lightobj.m_red = color[0];
|
|
|
|
m_lightobj.m_green = color[1];
|
|
|
|
m_lightobj.m_blue = color[2];
|
2009-04-20 15:06:46 +00:00
|
|
|
return PY_SET_ATTR_SUCCESS;
|
2004-07-17 05:28:23 +00:00
|
|
|
}
|
2009-04-20 15:06:46 +00:00
|
|
|
return PY_SET_ATTR_FAIL;
|
2004-05-30 11:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
if (!strcmp(attr_str, "SPOT") || !strcmp(attr_str, "SUN") || !strcmp(attr_str, "NORMAL"))
|
2009-02-19 13:42:07 +00:00
|
|
|
{
|
2009-04-20 15:06:46 +00:00
|
|
|
PyErr_Format(PyExc_RuntimeError, "Attribute %s is read only.", attr_str);
|
|
|
|
return PY_SET_ATTR_FAIL;
|
2009-02-19 13:42:07 +00:00
|
|
|
}
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
return KX_GameObject::py_setattro(attr, pyvalue);
|
2004-05-30 11:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PyMethodDef KX_LightObject::Methods[] = {
|
|
|
|
{NULL,NULL} //Sentinel
|
|
|
|
};
|
|
|
|
|
2009-02-26 09:04:06 +00:00
|
|
|
PyAttributeDef KX_LightObject::Attributes[] = {
|
2009-04-20 15:06:46 +00:00
|
|
|
KX_PYATTRIBUTE_DUMMY("layer"),
|
|
|
|
KX_PYATTRIBUTE_DUMMY("energy"),
|
|
|
|
KX_PYATTRIBUTE_DUMMY("distance"),
|
|
|
|
KX_PYATTRIBUTE_DUMMY("colour"),
|
|
|
|
KX_PYATTRIBUTE_DUMMY("color"),
|
|
|
|
KX_PYATTRIBUTE_DUMMY("lin_attenuation"),
|
|
|
|
KX_PYATTRIBUTE_DUMMY("quad_attenuation"),
|
|
|
|
KX_PYATTRIBUTE_DUMMY("spotsize"),
|
|
|
|
KX_PYATTRIBUTE_DUMMY("spotblend"),
|
|
|
|
KX_PYATTRIBUTE_DUMMY("SPOT"),
|
|
|
|
KX_PYATTRIBUTE_DUMMY("SUN"),
|
|
|
|
KX_PYATTRIBUTE_DUMMY("NORMAL"),
|
|
|
|
KX_PYATTRIBUTE_DUMMY("type"),
|
2009-02-26 09:04:06 +00:00
|
|
|
{ NULL } //Sentinel
|
|
|
|
};
|
|
|
|
|
2004-05-30 11:09:46 +00:00
|
|
|
PyTypeObject KX_LightObject::Type = {
|
2009-04-20 15:06:46 +00:00
|
|
|
PyObject_HEAD_INIT(NULL)
|
2004-05-30 11:09:46 +00:00
|
|
|
0,
|
|
|
|
"KX_LightObject",
|
2009-04-20 15:06:46 +00:00
|
|
|
sizeof(PyObjectPlus_Proxy),
|
2004-05-30 11:09:46 +00:00
|
|
|
0,
|
2009-04-20 15:06:46 +00:00
|
|
|
py_base_dealloc,
|
2004-05-30 11:09:46 +00:00
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
2009-04-20 15:06:46 +00:00
|
|
|
py_base_repr,
|
|
|
|
0,0,
|
|
|
|
&KX_GameObject::Mapping,
|
|
|
|
0,0,0,
|
|
|
|
py_base_getattro,
|
|
|
|
py_base_setattro,
|
|
|
|
0,0,0,0,0,0,0,0,0,
|
|
|
|
Methods
|
2004-05-30 11:09:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
PyParentObject KX_LightObject::Parents[] = {
|
|
|
|
&KX_LightObject::Type,
|
|
|
|
&KX_GameObject::Type,
|
|
|
|
&SCA_IObject::Type,
|
|
|
|
&CValue::Type,
|
|
|
|
NULL
|
|
|
|
};
|