More Bpy goodness!

New insertIpoKey() methods for Lamp and World types.
Contributed by Johnny Matthews (guitarGeek)
This commit is contained in:
Stephen Swaney
2005-03-26 17:30:21 +00:00
parent 5c87aefa4b
commit c9c0e8d50c
2 changed files with 144 additions and 4 deletions

View File

@@ -37,6 +37,9 @@
#include <BKE_object.h>
#include <BKE_library.h>
#include <BLI_blenlib.h>
#include <BIF_space.h>
#include <BSE_editipo.h>
#include <mydevice.h>
#include "Lamp.h"
#include "Ipo.h"
@@ -45,8 +48,6 @@
#include "rgbTuple.h"
#include "gen_utils.h"
/*****************************************************************************/
/* Python BPy_Lamp defaults: */
/*****************************************************************************/
@@ -119,6 +120,12 @@
#define EXPP_LAMP_COL_MIN 0.0
#define EXPP_LAMP_COL_MAX 1.0
#define IPOKEY_RGB 0
#define IPOKEY_ENERGY 1
#define IPOKEY_SPOTSIZE 2
#define IPOKEY_OFFSET 3
#define IPOKEY_SIZE 4
/*****************************************************************************/
/* Python API function prototypes for the Lamp module. */
/*****************************************************************************/
@@ -183,6 +190,7 @@ static PyObject *Lamp_getCol( BPy_Lamp * self );
static PyObject *Lamp_getIpo( BPy_Lamp * self );
static PyObject *Lamp_clearIpo( BPy_Lamp * self );
static PyObject *Lamp_setIpo( BPy_Lamp * self, PyObject * args );
static PyObject *Lamp_insertIpoKey( BPy_Lamp * self, PyObject * args );
static PyObject *Lamp_setName( BPy_Lamp * self, PyObject * args );
static PyObject *Lamp_setType( BPy_Lamp * self, PyObject * args );
static PyObject *Lamp_setIntType( BPy_Lamp * self, PyObject * args );
@@ -303,6 +311,9 @@ static PyMethodDef BPy_Lamp_methods[] = {
"() - unlink the IPO for this lamp"},
{"setIpo", ( PyCFunction ) Lamp_setIpo, METH_VARARGS,
"( lamp-ipo ) - link an IPO to this lamp"},
{"insertIpoKey", ( PyCFunction ) Lamp_insertIpoKey, METH_VARARGS,
"( Lamp IPO type ) - Inserts a key into IPO"},
{NULL, NULL, 0, NULL}
};
@@ -552,6 +563,12 @@ PyObject *Lamp_Init( void )
if( Modes )
PyModule_AddObject( submodule, "Modes", Modes );
PyModule_AddIntConstant( submodule, "RGB", IPOKEY_RGB );
PyModule_AddIntConstant( submodule, "ENERGY", IPOKEY_ENERGY );
PyModule_AddIntConstant( submodule, "SPOTSIZE", IPOKEY_SPOTSIZE );
PyModule_AddIntConstant( submodule, "OFFSET", IPOKEY_OFFSET );
PyModule_AddIntConstant( submodule, "SIZE", IPOKEY_SIZE );
return submodule;
}
@@ -1533,3 +1550,49 @@ static PyObject *Lamp_clearIpo( BPy_Lamp * self )
return EXPP_incr_ret_False(); /* no ipo found */
}
/*
* Lamp_insertIpoKey()
* inserts Lamp IPO key for RGB,ENERGY,SPOTSIZE,OFFSET,SIZE
*/
static PyObject *Lamp_insertIpoKey( BPy_Lamp * self, PyObject * args )
{
int key = 0, map;
if( !PyArg_ParseTuple( args, "i", &( key ) ) )
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
"expected int argument" ) );
map = texchannel_to_adrcode(self->lamp->texact);
if (key == IPOKEY_RGB ) {
insertkey((ID *)self->lamp,LA_COL_R);
insertkey((ID *)self->lamp,LA_COL_G);
insertkey((ID *)self->lamp,LA_COL_B);
}
if (key == IPOKEY_ENERGY ) {
insertkey((ID *)self->lamp,LA_ENERGY);
}
if (key == IPOKEY_SPOTSIZE ) {
insertkey((ID *)self->lamp,LA_SPOTSI);
}
if (key == IPOKEY_OFFSET ) {
insertkey((ID *)self->lamp, map+MAP_OFS_X);
insertkey((ID *)self->lamp, map+MAP_OFS_Y);
insertkey((ID *)self->lamp, map+MAP_OFS_Z);
}
if (key == IPOKEY_SIZE ) {
insertkey((ID *)self->lamp, map+MAP_SIZE_X);
insertkey((ID *)self->lamp, map+MAP_SIZE_Y);
insertkey((ID *)self->lamp, map+MAP_SIZE_Z);
}
allspace(REMAKEIPO, 0);
EXPP_allqueue(REDRAWIPO, 0);
EXPP_allqueue(REDRAWVIEW3D, 0);
EXPP_allqueue(REDRAWACTION, 0);
EXPP_allqueue(REDRAWNLA, 0);
return EXPP_incr_ret( Py_None );
}

View File

@@ -25,7 +25,7 @@
*
* This is a new part of Blender.
*
* Contributor(s): Jacques Guignot
* Contributor(s): Jacques Guignot, Johnny Matthews
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
@@ -48,16 +48,26 @@
#include <BKE_object.h>
#include <BKE_library.h>
#include <BLI_blenlib.h>
#include <BSE_editipo.h>
#include <BIF_space.h>
#include <mydevice.h>
#include <DNA_scene_types.h> /* for G.scene */
#include "World.h"
#include "Ipo.h"
#include "constant.h"
#include "rgbTuple.h"
#include "gen_utils.h"
#define IPOKEY_ZENITH 0
#define IPOKEY_HORIZON 1
#define IPOKEY_MIST 2
#define IPOKEY_STARS 3
#define IPOKEY_OFFSET 4
#define IPOKEY_SIZE 5
/*****************************************************************************/
/* Python BPy_World methods declarations: */
/*****************************************************************************/
@@ -66,6 +76,7 @@ static PyObject *World_setRange( BPy_World * self, PyObject * args );
static PyObject *World_getIpo( BPy_World * self );
static PyObject *World_setIpo( BPy_World * self, PyObject * args );
static PyObject *World_clearIpo( BPy_World * self );
static PyObject *World_insertIpoKey( BPy_World * self, PyObject * args );
static PyObject *World_getName( BPy_World * self );
static PyObject *World_setName( BPy_World * self, PyObject * args );
static PyObject *World_getMode( BPy_World * self );
@@ -212,6 +223,8 @@ static PyMethodDef BPy_World_methods[] = {
"() - Makes this world the active world for the current scene."},
{"makeActive", ( PyCFunction ) World_setCurrent, METH_NOARGS,
"please use setCurrent instead, this alias will be removed."},
{"insertIpoKey", ( PyCFunction ) World_insertIpoKey, METH_VARARGS,
"( World IPO type ) - Inserts a key into the IPO"},
{NULL, NULL, 0, NULL}
};
@@ -399,6 +412,13 @@ PyObject *World_Init( void )
submodule = Py_InitModule3( "Blender.World",
M_World_methods, M_World_doc );
PyModule_AddIntConstant( submodule, "ZENITH", IPOKEY_ZENITH );
PyModule_AddIntConstant( submodule, "HORIZON", IPOKEY_HORIZON );
PyModule_AddIntConstant( submodule, "MIST", IPOKEY_MIST );
PyModule_AddIntConstant( submodule, "STARS", IPOKEY_STARS );
PyModule_AddIntConstant( submodule, "OFFSET", IPOKEY_OFFSET );
PyModule_AddIntConstant( submodule, "SIZE", IPOKEY_SIZE );
return ( submodule );
}
@@ -1071,3 +1091,60 @@ World *GetWorldByName( char *name )
/* There is no object with the given name */
return ( NULL );
}
/*
* World_insertIpoKey()
* inserts World IPO key for ZENITH,HORIZON,MIST,STARS,OFFSET,SIZE
*/
static PyObject *World_insertIpoKey( BPy_World * self, PyObject * args )
{
int key = 0, map;
if( !PyArg_ParseTuple( args, "i", &( key ) ) )
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
"expected int argument" ) );
map = texchannel_to_adrcode(self->world->texact);
if(key == IPOKEY_ZENITH) {
insertkey((ID *)self->world, WO_ZEN_R);
insertkey((ID *)self->world, WO_ZEN_G);
insertkey((ID *)self->world, WO_ZEN_B);
}
if(key == IPOKEY_HORIZON) {
insertkey((ID *)self->world, WO_HOR_R);
insertkey((ID *)self->world, WO_HOR_G);
insertkey((ID *)self->world, WO_HOR_B);
}
if(key == IPOKEY_MIST) {
insertkey((ID *)self->world, WO_MISI);
insertkey((ID *)self->world, WO_MISTDI);
insertkey((ID *)self->world, WO_MISTSTA);
insertkey((ID *)self->world, WO_MISTHI);
}
if(key == IPOKEY_STARS) {
insertkey((ID *)self->world, WO_STAR_R);
insertkey((ID *)self->world, WO_STAR_G);
insertkey((ID *)self->world, WO_STAR_B);
insertkey((ID *)self->world, WO_STARDIST);
insertkey((ID *)self->world, WO_STARSIZE);
}
if(key == IPOKEY_OFFSET) {
insertkey((ID *)self->world, map+MAP_OFS_X);
insertkey((ID *)self->world, map+MAP_OFS_Y);
insertkey((ID *)self->world, map+MAP_OFS_Z);
}
if(key == IPOKEY_SIZE) {
insertkey((ID *)self->world, map+MAP_SIZE_X);
insertkey((ID *)self->world, map+MAP_SIZE_Y);
insertkey((ID *)self->world, map+MAP_SIZE_Z);
}
allspace(REMAKEIPO, 0);
EXPP_allqueue(REDRAWIPO, 0);
EXPP_allqueue(REDRAWVIEW3D, 0);
EXPP_allqueue(REDRAWACTION, 0);
EXPP_allqueue(REDRAWNLA, 0);
return EXPP_incr_ret( Py_None );
}