Python API Additions

New
Ipo Drivers access in IpoCurve
key.getChannelIpo(index) returns the ipocurve of a given shape index

Docs included for usage :)
This commit is contained in:
Johnny Matthews
2005-10-26 16:30:50 +00:00
parent 5463fe20b9
commit 94915fde5f
5 changed files with 582 additions and 184 deletions

View File

@@ -25,14 +25,16 @@
*
* This is a new part of Blender.
*
* Contributor(s): Jacques Guignot, Nathan Letwory, Ken Hughes
* Contributor(s): Jacques Guignot, Nathan Letwory, Ken Hughes, Johnny Matthews
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#include "Ipocurve.h" /*This must come first*/
#include "Object.h"
#include "BKE_global.h"
#include "BKE_depsgraph.h"
#include "BKE_ipo.h"
#include "BSE_editipo.h"
#include "MEM_guardedalloc.h"
@@ -81,9 +83,17 @@ static PyObject *IpoCurve_setExtrapolation( C_IpoCurve * self,
PyObject * args );
static PyObject *IpoCurve_getExtrapolation( C_IpoCurve * self );
static PyObject *IpoCurve_getPoints( C_IpoCurve * self );
static int IpoCurve_setPoints( C_IpoCurve * self, PyObject * value );
static int IpoCurve_setPoints( C_IpoCurve * self, PyObject * value );
static PyObject *IpoCurve_evaluate( C_IpoCurve * self, PyObject * args );
static PyObject *IpoCurve_getDriver( C_IpoCurve * self );
static int IpoCurve_setDriver( C_IpoCurve * self, PyObject * args );
static PyObject *IpoCurve_getDriverObject( C_IpoCurve * self);
static int IpoCurve_setDriverObject( C_IpoCurve * self, PyObject * args );
static PyObject *IpoCurve_getDriverChannel( C_IpoCurve * self);
static int IpoCurve_setDriverChannel( C_IpoCurve * self, PyObject * args );
/*****************************************************************************/
/* Python C_IpoCurve methods table: */
/*****************************************************************************/
@@ -116,40 +126,117 @@ static PyMethodDef C_IpoCurve_methods[] = {
{NULL, NULL, 0, NULL}
};
static PyGetSetDef C_IpoCurve_getseters[] = {
{"name",
(getter)IpoCurve_getName, (setter)NULL,
"the IpoCurve name",
NULL},
{"bezierPoints",
(getter)IpoCurve_getPoints, (setter)NULL,
"list of all bezTriples of the curve",
NULL},
{"driver",
(getter)IpoCurve_getDriver, (setter)IpoCurve_setDriver,
"(int) The Status of the driver 1-on, 0-off",
NULL},
{"driverObject",
(getter)IpoCurve_getDriverObject, (setter)IpoCurve_setDriverObject,
"(object) The Object Used to Drive the IpoCurve",
NULL},
{"driverChannel",
(getter)IpoCurve_getDriverChannel, (setter)IpoCurve_setDriverChannel,
"(int) The Channel on the Driver Object Used to Drive the IpoCurve",
NULL},
{NULL,NULL,NULL,NULL,NULL}
};
/*****************************************************************************/
/* Python IpoCurve_Type callback function prototypes: */
/*****************************************************************************/
static void IpoCurveDeAlloc( C_IpoCurve * self );
//static int IpoCurvePrint (C_IpoCurve *self, FILE *fp, int flags);
static int IpoCurveSetAttr( C_IpoCurve * self, char *name, PyObject * v );
static PyObject *IpoCurveGetAttr( C_IpoCurve * self, char *name );
static PyObject *IpoCurveRepr( C_IpoCurve * self );
/*****************************************************************************/
/* Python IpoCurve_Type structure definition: */
/*****************************************************************************/
PyTypeObject IpoCurve_Type = {
PyObject_HEAD_INIT( NULL ) /* required macro */
0, /* ob_size */
"IpoCurve", /* tp_name */
sizeof( C_IpoCurve ), /* tp_basicsize */
0, /* tp_itemsize */
PyObject_HEAD_INIT( NULL ) /* required macro */
0, /* ob_size */
"IpoCurve", /* tp_name */
sizeof( C_IpoCurve ), /* tp_basicsize */
0, /* tp_itemsize */
/* methods */
( destructor ) IpoCurveDeAlloc, /* tp_dealloc */
0, /* tp_print */
( getattrfunc ) IpoCurveGetAttr, /* tp_getattr */
( setattrfunc ) IpoCurveSetAttr, /* tp_setattr */
0, /* tp_compare */
( reprfunc ) IpoCurveRepr, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_as_hash */
0, 0, 0, 0, 0, 0,
0, /* tp_doc */
0, 0, 0, 0, 0, 0,
C_IpoCurve_methods, /* tp_methods */
0, /* tp_members */
( destructor ) IpoCurveDeAlloc, /* tp_dealloc */
0, /* tp_print */
( getattrfunc ) NULL, /* tp_getattr */
( setattrfunc ) NULL, /* tp_setattr */
0, /* tp_compare */
( reprfunc ) IpoCurveRepr, /* tp_repr */
/* Method suites for standard classes */
NULL, /* PyNumberMethods *tp_as_number; */
NULL, /* PySequenceMethods *tp_as_sequence; */
NULL, /* PyMappingMethods *tp_as_mapping; */
/* More standard operations (here for binary compatibility) */
NULL, /* hashfunc tp_hash; */
NULL, /* ternaryfunc tp_call; */
NULL, /* reprfunc tp_str; */
NULL, /* getattrofunc tp_getattro; */
NULL, /* setattrofunc tp_setattro; */
/* Functions to access object as input/output buffer */
NULL, /* PyBufferProcs *tp_as_buffer; */
/*** Flags to define presence of optional/expanded features ***/
Py_TPFLAGS_DEFAULT, /* long tp_flags; */
NULL, /* char *tp_doc; Documentation string */
/*** Assigned meaning in release 2.0 ***/
/* call function for all accessible objects */
NULL, /* traverseproc tp_traverse; */
/* delete references to contained objects */
NULL, /* inquiry tp_clear; */
/*** Assigned meaning in release 2.1 ***/
/*** rich comparisons ***/
NULL, /* richcmpfunc tp_richcompare; */
/*** weak reference enabler ***/
0, /* long tp_weaklistoffset; */
/*** Added in release 2.2 ***/
/* Iterators */
NULL, /* getiterfunc tp_iter; */
NULL, /* iternextfunc tp_iternext; */
/*** Attribute descriptor and subclassing stuff ***/
C_IpoCurve_methods, /* struct PyMethodDef *tp_methods; */
NULL, /* struct PyMemberDef *tp_members; */
C_IpoCurve_getseters, /* struct PyGetSetDef *tp_getset; */
NULL, /* struct _typeobject *tp_base; */
NULL, /* PyObject *tp_dict; */
NULL, /* descrgetfunc tp_descr_get; */
NULL, /* descrsetfunc tp_descr_set; */
0, /* long tp_dictoffset; */
NULL, /* initproc tp_init; */
NULL, /* allocfunc tp_alloc; */
NULL, /* newfunc tp_new; */
/* Low-level free-memory routine */
NULL, /* freefunc tp_free; */
/* For PyObject_IS_GC */
NULL, /* inquiry tp_is_gc; */
NULL, /* PyObject *tp_bases; */
/* method resolution order */
NULL, /* PyObject *tp_mro; */
NULL, /* PyObject *tp_cache; */
NULL, /* PyObject *tp_subclasses; */
NULL, /* PyObject *tp_weaklist; */
NULL
};
/*****************************************************************************/
@@ -168,12 +255,23 @@ PyObject *IpoCurve_Init( void )
{
PyObject *submodule;
IpoCurve_Type.ob_type = &PyType_Type;
if( PyType_Ready( &IpoCurve_Type ) < 0)
return NULL;
submodule =
Py_InitModule3( "Blender.IpoCurve", M_IpoCurve_methods,
M_IpoCurve_doc );
PyModule_AddIntConstant( submodule, "LOC_X", OB_LOC_X );
PyModule_AddIntConstant( submodule, "LOC_Y", OB_LOC_Y );
PyModule_AddIntConstant( submodule, "LOC_Z", OB_LOC_Z );
PyModule_AddIntConstant( submodule, "ROT_X", OB_ROT_X );
PyModule_AddIntConstant( submodule, "ROT_Y", OB_ROT_Y );
PyModule_AddIntConstant( submodule, "ROT_Z", OB_ROT_Z );
PyModule_AddIntConstant( submodule, "SIZE_X", OB_SIZE_X );
PyModule_AddIntConstant( submodule, "SIZE_Y", OB_SIZE_Y );
PyModule_AddIntConstant( submodule, "SIZE_Z", OB_SIZE_Z );
return ( submodule );
}
@@ -467,7 +565,7 @@ static PyObject *IpoCurve_getPoints( C_IpoCurve * self )
}
int IpoCurve_setPoints( C_IpoCurve * self, PyObject * value )
static int IpoCurve_setPoints( C_IpoCurve * self, PyObject * value )
{
struct BezTriple *bezt;
PyObject *l = PyList_New( 0 );
@@ -480,33 +578,6 @@ int IpoCurve_setPoints( C_IpoCurve * self, PyObject * value )
}
/*****************************************************************************/
/* Function: IpoCurveGetAttr */
/* Description: This is a callback function for the C_IpoCurve type. It is */
/* the function that accesses C_IpoCurve "member variables" and */
/* methods. */
/*****************************************************************************/
static PyObject *IpoCurveGetAttr( C_IpoCurve * self, char *name )
{
if( strcmp( name, "bezierPoints" ) == 0 )
return IpoCurve_getPoints( self );
if( strcmp( name, "name" ) == 0 )
return IpoCurve_getName( self );
return Py_FindMethod( C_IpoCurve_methods, ( PyObject * ) self, name );
}
/*****************************************************************************/
/* Function: IpoCurveSetAttr */
/* Description: This is a callback function for the C_IpoCurve type. It */
/* sets IpoCurve Data attributes (member variables).*/
/*****************************************************************************/
static int IpoCurveSetAttr( C_IpoCurve * self, char *name, PyObject * value )
{
if( strcmp( name, "bezierPoints" ) == 0 )
return IpoCurve_setPoints( self, value );
return 0; /* normal exit */
}
/*****************************************************************************/
/* Function: IpoCurveRepr */
/* Description: This is a callback function for the C_IpoCurve type. It */
@@ -618,3 +689,84 @@ char *getIpoCurveName( IpoCurve * icu )
}
return NULL;
}
static PyObject *IpoCurve_getDriver( C_IpoCurve * self ){
IpoCurve *ipo = self->ipocurve;
if(ipo->driver == NULL){
return PyInt_FromLong( 0 );
} else {
return PyInt_FromLong( 1 );
}
}
static int IpoCurve_setDriver( C_IpoCurve * self, PyObject * args ){
IpoCurve *ipo = self->ipocurve;
short mode;
mode = (short)PyInt_AS_LONG ( args );
if(mode == 1){
if(ipo->driver == NULL){
ipo->driver = MEM_callocN(sizeof(IpoDriver), "ipo driver");
ipo->driver->blocktype = ID_OB;
ipo->driver->adrcode = OB_LOC_X;
}
return 0;
} else if(mode == 0){
if(ipo->driver != NULL){
MEM_freeN(ipo->driver);
ipo->driver= NULL;
}
return 0;
}
return EXPP_ReturnIntError( PyExc_RuntimeError,
"expected int argument: 1 or 0 " );
}
static PyObject *IpoCurve_getDriverObject( C_IpoCurve * self ){
BPy_Object *blen_object;
IpoCurve *ipo = self->ipocurve;
if(ipo->driver == NULL)
return Py_None;
blen_object = ( BPy_Object * ) PyObject_NEW( BPy_Object,&Object_Type );
blen_object->object = ipo->driver->ob;
return ( ( PyObject * ) blen_object );
}
static int IpoCurve_setDriverObject( C_IpoCurve * self, PyObject * arg ){
IpoCurve *ipo = self->ipocurve;
if(ipo->driver == NULL)
return EXPP_ReturnIntError( PyExc_RuntimeError,
"This IpoCurve does not have an active driver" );
if(!BPy_Object_Check(arg) )
return EXPP_ReturnIntError( PyExc_RuntimeError,
"expected an object argument" );
ipo->driver->ob = ((BPy_Object *)arg)->object;
DAG_scene_sort(G.scene);
return 0;
}
static PyObject *IpoCurve_getDriverChannel( C_IpoCurve * self ){
return PyInt_FromLong( self->ipocurve->driver->adrcode );
}
static int IpoCurve_setDriverChannel( C_IpoCurve * self, PyObject * args ){
int code;
IpoCurve *ipo = self->ipocurve;
if(ipo->driver == NULL)
return EXPP_ReturnIntError( PyExc_RuntimeError,
"This IpoCurve does not have an active driver" );
code = (short)PyInt_AS_LONG ( args );
ipo->driver->adrcode = code;
return 0;
}

View File

@@ -44,7 +44,7 @@ typedef struct {
IpoCurve * ipocurve;
} C_IpoCurve;
extern PyTypeObject IpoCurve_Type;
PyObject *IpoCurve_Init( void );
PyObject *IpoCurve_CreatePyObject( IpoCurve * ipo );

View File

@@ -25,20 +25,27 @@
*
* This is a new part of Blender.
*
* Contributor(s): Pontus Lidman
* Contributor(s): Pontus Lidman, Johnny Matthews
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#include "DNA_scene_types.h"
#include <BLI_blenlib.h>
#include <BKE_global.h>
#include <BKE_main.h>
#include "Ipocurve.h"
#include "Key.h"
#include "NMesh.h" /* we create NMesh.NMVert objects */
#include "Ipo.h"
#include "BezTriple.h"
#include "BSE_editipo.h"
#include "mydevice.h"
#include "BKE_depsgraph.h"
#include "blendef.h"
#include "constant.h"
#include "gen_utils.h"
@@ -50,27 +57,148 @@
#define GS(a) (*((short *)(a)))
static void Key_dealloc( PyObject * self );
static PyObject *Key_getattr( PyObject * self, char *name );
static void KeyBlock_dealloc( PyObject * self );
static PyObject *KeyBlock_getattr( PyObject * self, char *name );
static PyObject *Key_repr( BPy_Key * self );
static PyObject *Key_getBlocks( PyObject * self );
static PyObject *Key_getChannelIpo(PyObject *self, PyObject *args);
static PyObject *Key_getType( PyObject * self );
static PyObject *Key_getIpo( PyObject * self );
static PyObject *Key_getValue( PyObject * self );
static struct PyMethodDef Key_methods[] = {
{ "getBlocks", (PyCFunction) Key_getBlocks, METH_NOARGS, "Get key blocks" },
{ "getChannelIpo", (PyCFunction) Key_getChannelIpo, METH_VARARGS, "Get a Particular shape channel's IpoCurve key blocks" },
{ "getIpo", (PyCFunction) Key_getIpo, METH_NOARGS, "Get key Ipo" },
{ 0, 0, 0, 0 }
};
static PyGetSetDef BPy_Key_getsetters[] = {
{"type",(getter)Key_getType, (setter)NULL,
"Key Type",NULL},
{"value",(getter)Key_getValue, (setter)NULL,
"Key value",NULL},
{NULL,NULL,NULL,NULL,NULL} /* Sentinel */
};
static PyObject *KeyBlock_getData( PyObject * self );
static PyObject *KeyBlock_getName( BPy_KeyBlock * self );
static PyObject *KeyBlock_getPos( BPy_KeyBlock * self );
static PyObject *KeyBlock_getSlidermin( BPy_KeyBlock * self );
static PyObject *KeyBlock_getSlidermax( BPy_KeyBlock * self );
static PyObject *KeyBlock_getVgroup( BPy_KeyBlock * self );
static int KeyBlock_setName( BPy_KeyBlock *, PyObject * args );
static int KeyBlock_setVgroup( BPy_KeyBlock *, PyObject * args );
static int KeyBlock_setSlidermin( BPy_KeyBlock *, PyObject * args );
static int KeyBlock_setSlidermax( BPy_KeyBlock *, PyObject * args );
static struct PyMethodDef KeyBlock_methods[] = {
{ "getData", (PyCFunction) KeyBlock_getData, METH_NOARGS,
"Get keyblock data" },
{ 0, 0, 0, 0 }
};
static PyGetSetDef BPy_KeyBlock_getsetters[] = {
{"name",(getter)KeyBlock_getName, (setter)KeyBlock_setName,
"Keyblock Name",NULL},
{"pos",(getter)KeyBlock_getPos, (setter)NULL,
"Keyblock Pos",NULL},
{"slidermin",(getter)KeyBlock_getSlidermin, (setter)KeyBlock_setSlidermin,
"Keyblock Slider Minimum",NULL},
{"slidermax",(getter)KeyBlock_getSlidermax, (setter)KeyBlock_setSlidermax,
"Keyblock Slider Maximum",NULL},
{"vgroup",(getter)KeyBlock_getVgroup, (setter)KeyBlock_setVgroup,
"Keyblock VGroup",NULL},
{NULL,NULL,NULL,NULL,NULL} /* Sentinel */
};
PyTypeObject Key_Type = {
PyObject_HEAD_INIT( NULL ) 0, /*ob_size */
"Blender Key", /*tp_name */
sizeof( BPy_Key ), /*tp_basicsize */
0, /*tp_itemsize */
"Blender Key", /*tp_name */
sizeof( BPy_Key ), /*tp_basicsize */
0, /*tp_itemsize */
/* methods */
( destructor ) Key_dealloc, /*tp_dealloc */
( printfunc ) 0, /*tp_print */
( getattrfunc ) Key_getattr, /*tp_getattr */
( setattrfunc ) 0, /*tp_setattr */
0, /*tp_compare*/
( reprfunc ) Key_repr, /* tp_repr */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
( destructor ) Key_dealloc, /*tp_dealloc */
( printfunc ) 0, /*tp_print */
( getattrfunc ) 0, /*tp_getattr */
( setattrfunc ) 0, /*tp_setattr */
0, /*tp_compare*/
( reprfunc ) Key_repr, /* tp_repr */
/* Method suites for standard classes */
NULL, /* PyNumberMethods *tp_as_number; */
NULL, /* PySequenceMethods *tp_as_sequence; */
NULL, /* PyMappingMethods *tp_as_mapping; */
/* More standard operations (here for binary compatibility) */
NULL, /* hashfunc tp_hash; */
NULL, /* ternaryfunc tp_call; */
NULL, /* reprfunc tp_str; */
NULL, /* getattrofunc tp_getattro; */
NULL, /* setattrofunc tp_setattro; */
/* Functions to access object as input/output buffer */
NULL, /* PyBufferProcs *tp_as_buffer; */
/*** Flags to define presence of optional/expanded features ***/
Py_TPFLAGS_DEFAULT, /* long tp_flags; */
NULL, /* char *tp_doc; Documentation string */
/*** Assigned meaning in release 2.0 ***/
/* call function for all accessible objects */
NULL, /* traverseproc tp_traverse; */
/* delete references to contained objects */
NULL, /* inquiry tp_clear; */
/*** Assigned meaning in release 2.1 ***/
/*** rich comparisons ***/
NULL, /* richcmpfunc tp_richcompare; */
/*** weak reference enabler ***/
0, /* long tp_weaklistoffset; */
/*** Added in release 2.2 ***/
/* Iterators */
NULL, /* getiterfunc tp_iter; */
NULL, /* iternextfunc tp_iternext; */
/*** Attribute descriptor and subclassing stuff ***/
Key_methods, /* struct PyMethodDef *tp_methods; */
NULL, /* struct PyMemberDef *tp_members; */
BPy_Key_getsetters, /* struct PyGetSetDef *tp_getset; */
NULL, /* struct _typeobject *tp_base; */
NULL, /* PyObject *tp_dict; */
NULL, /* descrgetfunc tp_descr_get; */
NULL, /* descrsetfunc tp_descr_set; */
0, /* long tp_dictoffset; */
NULL, /* initproc tp_init; */
NULL, /* allocfunc tp_alloc; */
NULL, /* newfunc tp_new; */
/* Low-level free-memory routine */
NULL, /* freefunc tp_free; */
/* For PyObject_IS_GC */
NULL, /* inquiry tp_is_gc; */
NULL, /* PyObject *tp_bases; */
/* method resolution order */
NULL, /* PyObject *tp_mro; */
NULL, /* PyObject *tp_cache; */
NULL, /* PyObject *tp_subclasses; */
NULL, /* PyObject *tp_weaklist; */
NULL
};
PyTypeObject KeyBlock_Type = {
PyObject_HEAD_INIT( NULL ) 0, /*ob_size */
"Blender KeyBlock", /*tp_name */
@@ -78,39 +206,77 @@ PyTypeObject KeyBlock_Type = {
0, /*tp_itemsize */
/* methods */
( destructor ) KeyBlock_dealloc, /*tp_dealloc */
( printfunc ) 0, /*tp_print */
( getattrfunc ) KeyBlock_getattr, /*tp_getattr */
( setattrfunc ) 0, /*tp_setattr */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
NULL, /*tp_print */
NULL, /*tp_getattr */
NULL, /*tp_setattr */
NULL, /*tp_compare*/
NULL, /* tp_repr */
/* Method suites for standard classes */
NULL, /* PyNumberMethods *tp_as_number; */
NULL, /* PySequenceMethods *tp_as_sequence; */
NULL, /* PyMappingMethods *tp_as_mapping; */
/* More standard operations (here for binary compatibility) */
NULL, /* hashfunc tp_hash; */
NULL, /* ternaryfunc tp_call; */
NULL, /* reprfunc tp_str; */
NULL, /* getattrofunc tp_getattro; */
NULL, /* setattrofunc tp_setattro; */
/* Functions to access object as input/output buffer */
NULL, /* PyBufferProcs *tp_as_buffer; */
/*** Flags to define presence of optional/expanded features ***/
Py_TPFLAGS_DEFAULT, /* long tp_flags; */
NULL, /* char *tp_doc; Documentation string */
/*** Assigned meaning in release 2.0 ***/
/* call function for all accessible objects */
NULL, /* traverseproc tp_traverse; */
/* delete references to contained objects */
NULL, /* inquiry tp_clear; */
/*** Assigned meaning in release 2.1 ***/
/*** rich comparisons ***/
NULL, /* richcmpfunc tp_richcompare; */
/*** weak reference enabler ***/
0, /* long tp_weaklistoffset; */
/*** Added in release 2.2 ***/
/* Iterators */
NULL, /* getiterfunc tp_iter; */
NULL, /* iternextfunc tp_iternext; */
/*** Attribute descriptor and subclassing stuff ***/
KeyBlock_methods, /* struct PyMethodDef *tp_methods; */
NULL, /* struct PyMemberDef *tp_members; */
BPy_KeyBlock_getsetters, /* struct PyGetSetDef *tp_getset; */
NULL, /* struct _typeobject *tp_base; */
NULL, /* PyObject *tp_dict; */
NULL, /* descrgetfunc tp_descr_get; */
NULL, /* descrsetfunc tp_descr_set; */
0, /* long tp_dictoffset; */
NULL, /* initproc tp_init; */
NULL, /* allocfunc tp_alloc; */
NULL, /* newfunc tp_new; */
/* Low-level free-memory routine */
NULL, /* freefunc tp_free; */
/* For PyObject_IS_GC */
NULL, /* inquiry tp_is_gc; */
NULL, /* PyObject *tp_bases; */
/* method resolution order */
NULL, /* PyObject *tp_mro; */
NULL, /* PyObject *tp_cache; */
NULL, /* PyObject *tp_subclasses; */
NULL, /* PyObject *tp_weaklist; */
NULL
};
static PyObject *Key_getBlocks( PyObject * self );
static PyObject *Key_getType( PyObject * self );
static PyObject *Key_getIpo( PyObject * self );
static PyObject *Key_getValue( PyObject * self );
static struct PyMethodDef Key_methods[] = {
{ "getType", (PyCFunction) Key_getType, METH_NOARGS, "Get key type" },
{ "getValue", (PyCFunction) Key_getValue, METH_NOARGS, "Get key value" },
{ "getBlocks", (PyCFunction) Key_getBlocks, METH_NOARGS, "Get key blocks" },
{ "getIpo", (PyCFunction) Key_getIpo, METH_NOARGS, "Get key Ipo" },
{ 0, 0, 0, 0 }
};
static PyObject *KeyBlock_getData( PyObject * self );
static PyObject *KeyBlock_getPos( PyObject * self );
static PyObject *KeyBlock_getName( PyObject * self );
static struct PyMethodDef KeyBlock_methods[] = {
{ "getPos", (PyCFunction) KeyBlock_getPos, METH_NOARGS,
"Get keyblock position"},
{ "getData", (PyCFunction) KeyBlock_getData, METH_NOARGS,
"Get keyblock data" },
{ "getName", (PyCFunction) KeyBlock_getName, METH_NOARGS,
"Get keyblock name"},
{ 0, 0, 0, 0 }
};
static void Key_dealloc( PyObject * self )
{
@@ -136,36 +302,11 @@ PyObject *Key_CreatePyObject( Key * k )
return ( PyObject * ) key;
}
static PyObject *Key_getattr( PyObject * self, char *name )
{
BPy_Key *k = ( BPy_Key * ) self;
if ( strcmp( name, "id" ) == 0 ) {
return PyString_FromString( k->key->id.name );
} else if ( strcmp( name, "type" ) == 0 ) {
return Key_getType(self);
} else if ( strcmp( name, "value" ) == 0 ) {
return Key_getValue(self);
} else if ( strcmp( name, "blocks" ) == 0 ) {
return Key_getBlocks(self);
} else if ( strcmp( name, "ipo" ) == 0 ) {
return Key_getIpo(self);
}
return Py_FindMethod( Key_methods, ( PyObject * ) self, name );
}
static PyObject *Key_repr( BPy_Key * self )
{
return PyString_FromFormat( "[Key \"%s\"]", self->key->id.name + 2 );
}
static PyObject *Key_getValue( PyObject * self )
{
BPy_Key *k = ( BPy_Key * ) self;
return PyFloat_FromDouble( k->key->curval );
}
static PyObject *Key_getIpo( PyObject * self )
{
BPy_Key *k = ( BPy_Key * ) self;
@@ -220,6 +361,19 @@ static PyObject *Key_getBlocks( PyObject * self )
return l;
}
static PyObject *Key_getValue( PyObject * self )
{
BPy_Key *k = ( BPy_Key * ) self;
return PyFloat_FromDouble( k->key->curval );
}
// ------------ Key Block Functions --------------//
static void KeyBlock_dealloc( PyObject * self )
{
PyObject_DEL( self );
@@ -246,30 +400,74 @@ PyObject *KeyBlock_CreatePyObject( KeyBlock * kb, Key *parentKey )
return ( PyObject * ) keyBlock;
}
static PyObject *KeyBlock_getattr( PyObject * self, char *name )
{
if ( strcmp( name, "pos" ) == 0 ) {
return KeyBlock_getPos(self);
} else if ( strcmp( name, "data" ) == 0 ) {
return KeyBlock_getData(self);
} else if ( strcmp( name, "name" ) == 0 ) {
return KeyBlock_getName(self);
}
return Py_FindMethod( KeyBlock_methods, ( PyObject * ) self, name );
}
static PyObject *KeyBlock_getName( PyObject * self ) {
static PyObject *KeyBlock_getName( BPy_KeyBlock * self ) {
BPy_KeyBlock *kb = ( BPy_KeyBlock * ) self;
PyObject *name = Py_BuildValue( "s", kb->keyblock->name);
return name;
}
static PyObject *KeyBlock_getPos( PyObject * self )
{
static PyObject *KeyBlock_getPos( BPy_KeyBlock * self ){
BPy_KeyBlock *kb = ( BPy_KeyBlock * ) self;
return PyFloat_FromDouble( kb->keyblock->pos );
return PyFloat_FromDouble( kb->keyblock->pos );
}
static PyObject *KeyBlock_getSlidermin( BPy_KeyBlock * self ){
BPy_KeyBlock *kb = ( BPy_KeyBlock * ) self;
return PyFloat_FromDouble( kb->keyblock->slidermin );
}
static PyObject *KeyBlock_getSlidermax( BPy_KeyBlock * self ){
BPy_KeyBlock *kb = ( BPy_KeyBlock * ) self;
return PyFloat_FromDouble( kb->keyblock->slidermax );
}
static PyObject *KeyBlock_getVgroup( BPy_KeyBlock * self ){
BPy_KeyBlock *kb = ( BPy_KeyBlock * ) self;
PyObject *name = Py_BuildValue( "s", kb->keyblock->vgroup);
return name;
}
static int KeyBlock_setName( BPy_KeyBlock * self, PyObject * args ){
char* text = NULL;
BPy_KeyBlock *kb = ( BPy_KeyBlock * ) self;
text = PyString_AsString ( args );
if( !text )
return EXPP_ReturnIntError( PyExc_TypeError,
"expected string argument" );
strncpy( kb->keyblock->name, text , 32);
return 0;
}
static int KeyBlock_setVgroup( BPy_KeyBlock * self, PyObject * args ){
char* text = NULL;
BPy_KeyBlock *kb = ( BPy_KeyBlock * ) self;
text = PyString_AsString ( args );
if( !text )
return EXPP_ReturnIntError( PyExc_TypeError,
"expected string argument" );
strncpy( kb->keyblock->vgroup, text , 32);
return 0;
}
static int KeyBlock_setSlidermin( BPy_KeyBlock * self, PyObject * args ){
return EXPP_setFloatClamped ( args, &self->keyblock->slidermin,
-10.0f,
10.0f );
}
static int KeyBlock_setSlidermax( BPy_KeyBlock * self, PyObject * args ){
return EXPP_setFloatClamped ( args, &self->keyblock->slidermax,
-10.0f,
10.0f );
}
static PyObject *KeyBlock_getData( PyObject * self )
{
@@ -405,8 +603,13 @@ PyObject *Key_Init( void )
{
PyObject *submodule, *KeyTypes;
if( PyType_Ready( &Key_Type ) < 0)
return NULL;
Key_Type.ob_type = &PyType_Type;
KeyBlock_Type.ob_type = &PyType_Type;
//KeyBlock_Type.ob_type = &PyType_Type;
PyType_Ready( &KeyBlock_Type );
submodule =
Py_InitModule3( "Blender.Key", M_Key_methods, "Key module" );
@@ -426,3 +629,20 @@ PyObject *Key_Init( void )
*/
return submodule;
}
static PyObject *Key_getChannelIpo(PyObject *self, PyObject *args){
short index;
IpoCurve *curve;
Key *key = (( BPy_KeyBlock * ) self)->key;
C_IpoCurve *output;
if( !PyArg_ParseTuple( args, "i", &index ) ) {
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
"expected one integer as an arguments" ) );
}
curve = verify_ipocurve(&key->id,ID_KE,NULL,NULL,index);
output = ( C_IpoCurve * ) PyObject_NEW( C_IpoCurve, &IpoCurve_Type );
output->ipocurve = curve;
return ( ( PyObject * ) output );
}

View File

@@ -261,6 +261,25 @@ class IpoCurve:
Important Notes for Rotation Curves:\n
For the rotation IpoCurves, the y values for points are in units of 10 degrees. For example, 45.0 degrees is stored as 4.50 degrees. These are the same numbers you see in the Transform Properties pupmenu ( NKey ) in the IPO Curve Editor window. Positive rotations are in a counter-clockwise direction, just like in math class.
@ivar driver: Status of Driver
1: on
0: off
@type driver: int
@ivar driverObject: Object Used to Drive the IpoCurve
@type driverObject: Object
@ivar driverChannel: Object Channel Used to Drive the IpoCurve
Use module constants
IpoCurve.LOC_X
IpoCurve.LOC_Y
IpoCurve.LOC_Z
IpoCurve.ROT_X
IpoCurve.ROT_Y
IpoCurve.ROT_Z
IpoCurve.SIZE_X
IpoCurve.SIZE_Y
IpoCurve.SIZE_Z
@type driverChannel: int
@ivar name: The Curve Data name.
@ivar bezierPoints : The list of the Bezier points.
"""

View File

@@ -35,17 +35,17 @@ class Key:
An object with keyframes (L{Lattice.Lattice}, L{NMesh.NMesh} or
L{Curve.Curve}) will contain a Key object representing the
keyframe data.
@ivar value: The Value of the Key - Read Only
@type value: float
@ivar type: An integer from the L{Types} dictionary
representing the Key type.
@type type: int
@cvar blocks: A list of KeyBlocks.
@cvar ipo: The L{Ipo.Ipo} object associated with this key.
@cvar type: An integer from the L{Types} dictionary
representing the Key type.
"""
def getType():
"""
Get the type of this Key object. It will be one of the
integers defined in the L{Types} dictionary.
"""
def getIpo():
"""
Get the L{Ipo.Ipo} object associated with this key.
@@ -55,44 +55,51 @@ class Key:
Get a list of L{KeyBlock}s, containing the keyframes defined for
this Key.
"""
def setDriverChannel(index):
"""
Get the IpoCurve object associated with the shape key referenced
by the index of that key in getBlocks
@type index: int
@param index: the keyblock index to retrieve an IPO for.
@rtype: Blender IpoCurve
@return: Ipo Data Object:
"""
class KeyBlock:
"""
The KeyBlock object
===================
Each Key object has a list of KeyBlocks attached, each KeyBlock
representing a keyframe.
@ivar name: The Name of the Keyblock
Truncated to 32 Characters
@type name: string
@ivar pos: The position of the keyframe
@type pos: float
@ivar slidermin: The minimum value for the action slider
@type slidermin: float
@ivar slidermax: The maximum value for the action slider
@type slidermax: float
@ivar vgroup: The assigned VGroup for the Key Block
@type vgroup: string
@cvar data: The data of the KeyBlock (see L{getData}). This
attribute is read-only.
"""
def getData():
"""
The KeyBlock object
===================
Each Key object has a list of KeyBlocks attached, each KeyBlock
representing a keyframe.
Get the data of a KeyBlock, as a list of data items. Each item
will have a different data type depending on the type of this
Key.
Mesh keys have a list of L{NMesh.NMVert} objects in the data
block.
@cvar data: The data of the KeyBlock (see L{getData}). This
attribute is read-only.
@cvar pos: The position of the keyframe (see L{getPos}). This
attribute is read-only.
@cvar name: The name of the KeyBlock. This attribute is read-only.
Lattice keys have a list of BPoints in the data block. These
don't have corresponding Python objects yet, so each BPoint is
represented using a list of four floating-point numbers.
Curve keys have a list of L{Ipo.BezTriple} objects in the data
block.
"""
def getData():
"""
Get the data of a KeyBlock, as a list of data items. Each item
will have a different data type depending on the type of this
Key.
Mesh keys have a list of L{NMesh.NMVert} objects in the data
block.
Lattice keys have a list of BPoints in the data block. These
don't have corresponding Python objects yet, so each BPoint is
represented using a list of four floating-point numbers.
Curve keys have a list of L{Ipo.BezTriple} objects in the data
block.
"""
def getPos():
"""
Get the position of the keyframe represented by this KeyBlock,
normally between 0.0 and 1.0. The time point when the Speed
Ipo intersects the KeyBlock position is the actual time of the
keyframe.
"""
def getName():
"""Get the name of the keyframe represented by this KeyBlock."""