From 039a8c95f3a9536b7e919fc5a55ddf864dd78d1c Mon Sep 17 00:00:00 2001 From: Willian Padovani Germano Date: Fri, 9 Sep 2005 01:31:10 +0000 Subject: BPython: - Pontus Lidman contributed a new module: Blender.Key + access to key objects from NMesh, Lattice and Curve + docs (thanks and sorry for taking so long to check/commit the patch!) - Allowing EVENT spacehandlers to call the file selector (scriptlinks in general are not allowed, but this special case should be able to). Requested by Paolo Colombo (thanks!) - tiny doc update (Ken Hughes pointed an error in the space handlers example) I didn't have time to update the Key module to follow the current bpython design, will do that later and also test it better than I did. --- source/blender/python/api2_2x/Blender.c | 4 +- source/blender/python/api2_2x/Curve.c | 48 ++- source/blender/python/api2_2x/Key.c | 418 +++++++++++++++++++++++ source/blender/python/api2_2x/Key.h | 68 ++++ source/blender/python/api2_2x/Lattice.c | 37 +- source/blender/python/api2_2x/NMesh.c | 26 +- source/blender/python/api2_2x/doc/API_related.py | 2 +- source/blender/python/api2_2x/doc/Curve.py | 9 + source/blender/python/api2_2x/doc/Key.py | 94 +++++ source/blender/python/api2_2x/doc/Lattice.py | 8 + source/blender/python/api2_2x/doc/NMesh.py | 8 + 11 files changed, 694 insertions(+), 28 deletions(-) create mode 100644 source/blender/python/api2_2x/Key.c create mode 100644 source/blender/python/api2_2x/Key.h create mode 100644 source/blender/python/api2_2x/doc/Key.py (limited to 'source/blender/python/api2_2x') diff --git a/source/blender/python/api2_2x/Blender.c b/source/blender/python/api2_2x/Blender.c index 7dc0c5f537a..6e3df9394a1 100644 --- a/source/blender/python/api2_2x/Blender.c +++ b/source/blender/python/api2_2x/Blender.c @@ -67,6 +67,7 @@ struct ID; /*keep me up here */ #include "Effect.h" #include "Ipo.h" #include "Ipocurve.h" +#include "Key.h" #include "Lamp.h" #include "Lattice.h" #include "Mathutils.h" @@ -799,6 +800,7 @@ void M_Blender_Init(void) PyDict_SetItemString(dict, "Ipo", Ipo_Init()); PyDict_SetItemString(dict, "IpoCurve", IpoCurve_Init()); PyDict_SetItemString(dict, "Image", Image_Init()); + PyDict_SetItemString(dict, "Key", Key_Init()); PyDict_SetItemString(dict, "Lamp", Lamp_Init()); PyDict_SetItemString(dict, "Lattice", Lattice_Init()); PyDict_SetItemString(dict, "Library", Library_Init()); @@ -809,9 +811,9 @@ void M_Blender_Init(void) PyDict_SetItemString(dict, "Noise", Noise_Init()); PyDict_SetItemString(dict, "Object", Object_Init()); PyDict_SetItemString(dict, "Registry", Registry_Init()); - PyDict_SetItemString(dict, "sys", sys_Init()); PyDict_SetItemString(dict, "Scene", Scene_Init()); PyDict_SetItemString(dict, "Sound", Sound_Init()); + PyDict_SetItemString(dict, "sys", sys_Init()); PyDict_SetItemString(dict, "Types", Types_Init()); PyDict_SetItemString(dict, "Text", Text_Init()); PyDict_SetItemString(dict, "Text3d", Text3d_Init()); diff --git a/source/blender/python/api2_2x/Curve.c b/source/blender/python/api2_2x/Curve.c index e457a2c6b2e..2cd89b9db4e 100644 --- a/source/blender/python/api2_2x/Curve.c +++ b/source/blender/python/api2_2x/Curve.c @@ -40,6 +40,7 @@ #include "CurNurb.h" #include "Material.h" #include "Object.h" +#include "Key.h" #include "gen_utils.h" @@ -100,6 +101,7 @@ static PyObject *Curve_setRot( BPy_Curve * self, PyObject * args ); static PyObject *Curve_getSize( BPy_Curve * self ); static PyObject *Curve_setSize( BPy_Curve * self, PyObject * args ); static PyObject *Curve_getNumCurves( BPy_Curve * self ); +static PyObject *Curve_getKey( BPy_Curve * self ); static PyObject *Curve_isNurb( BPy_Curve * self, PyObject * args ); static PyObject *Curve_isCyclic( BPy_Curve * self, PyObject * args); static PyObject *Curve_getNumPoints( BPy_Curve * self, PyObject * args ); @@ -199,6 +201,8 @@ Sets a control point "}, METH_VARARGS, "(3-tuple) - Sets curve size"}, {"getNumCurves", ( PyCFunction ) Curve_getNumCurves, METH_NOARGS, "() - Gets number of curves in Curve"}, + {"getKey", ( PyCFunction ) Curve_getKey, + METH_NOARGS, "() - Gets curve key"}, {"isNurb", ( PyCFunction ) Curve_isNurb, METH_VARARGS, "(nothing or integer) - returns 1 if curve is type Nurb, O otherwise."}, @@ -995,6 +999,20 @@ static PyObject *Curve_getNumCurves( BPy_Curve * self ) "couldn't get number of curves" ) ); } +/* + * get the key object linked to this curve + */ + +static PyObject *Curve_getKey( BPy_Curve * self ) +{ + PyObject *keyObj; + + if (self->curve->key) + keyObj = Key_CreatePyObject(self->curve->key); + else keyObj = EXPP_incr_ret(Py_None); + + return keyObj; +} /* * count the number of points in a given spline @@ -1443,34 +1461,36 @@ static PyObject *CurveGetAttr( BPy_Curve * self, char *name ) if( strcmp( name, "name" ) == 0 ) attr = PyString_FromString( self->curve->id.name + 2 ); - if( strcmp( name, "pathlen" ) == 0 ) + else if( strcmp( name, "pathlen" ) == 0 ) attr = PyInt_FromLong( self->curve->pathlen ); - if( strcmp( name, "totcol" ) == 0 ) + else if( strcmp( name, "totcol" ) == 0 ) attr = PyInt_FromLong( self->curve->totcol ); - if( strcmp( name, "flag" ) == 0 ) + else if( strcmp( name, "flag" ) == 0 ) attr = PyInt_FromLong( self->curve->flag ); - if( strcmp( name, "bevresol" ) == 0 ) + else if( strcmp( name, "bevresol" ) == 0 ) attr = PyInt_FromLong( self->curve->bevresol ); - if( strcmp( name, "resolu" ) == 0 ) + else if( strcmp( name, "resolu" ) == 0 ) attr = PyInt_FromLong( self->curve->resolu ); - if( strcmp( name, "resolv" ) == 0 ) + else if( strcmp( name, "resolv" ) == 0 ) attr = PyInt_FromLong( self->curve->resolv ); - if( strcmp( name, "width" ) == 0 ) + else if( strcmp( name, "width" ) == 0 ) attr = PyFloat_FromDouble( self->curve->width ); - if( strcmp( name, "ext1" ) == 0 ) + else if( strcmp( name, "ext1" ) == 0 ) attr = PyFloat_FromDouble( self->curve->ext1 ); - if( strcmp( name, "ext2" ) == 0 ) + else if( strcmp( name, "ext2" ) == 0 ) attr = PyFloat_FromDouble( self->curve->ext2 ); - if( strcmp( name, "loc" ) == 0 ) + else if( strcmp( name, "loc" ) == 0 ) return Curve_getLoc( self ); - if( strcmp( name, "rot" ) == 0 ) + else if( strcmp( name, "rot" ) == 0 ) return Curve_getRot( self ); - if( strcmp( name, "size" ) == 0 ) + else if( strcmp( name, "size" ) == 0 ) return Curve_getSize( self ); - if( strcmp( name, "bevob" ) == 0 ) + else if( strcmp( name, "bevob" ) == 0 ) return Curve_getBevOb( self ); + else if( strcmp( name, "key" ) == 0 ) + return Curve_getKey( self ); #if 0 - if( strcmp( name, "numpts" ) == 0 ) + else if( strcmp( name, "numpts" ) == 0 ) return Curve_getNumPoints( self ); #endif diff --git a/source/blender/python/api2_2x/Key.c b/source/blender/python/api2_2x/Key.c new file mode 100644 index 00000000000..997d4e36400 --- /dev/null +++ b/source/blender/python/api2_2x/Key.c @@ -0,0 +1,418 @@ +/* + * $Id$ + * + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * 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. + * + * This is a new part of Blender. + * + * Contributor(s): Pontus Lidman + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + */ + +#include +#include +#include + +#include "Key.h" +#include "NMesh.h" /* we create NMesh.NMVert objects */ +#include "Ipo.h" +#include "BezTriple.h" + +#include "constant.h" +#include "gen_utils.h" + +#define KEY_TYPE_MESH 0 +#define KEY_TYPE_CURVE 1 +#define KEY_TYPE_LATTICE 2 + +/* macro from blenkernel/intern/key.c:98 */ +#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 ); + +PyTypeObject Key_Type = { + PyObject_HEAD_INIT( NULL ) 0, /*ob_size */ + "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, +}; + +PyTypeObject KeyBlock_Type = { + PyObject_HEAD_INIT( NULL ) 0, /*ob_size */ + "Blender KeyBlock", /*tp_name */ + sizeof( BPy_KeyBlock ), /*tp_basicsize */ + 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, +}; + +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 struct PyMethodDef KeyBlock_methods[] = { + { "getPos", (PyCFunction) KeyBlock_getPos, METH_NOARGS, + "Get keyblock position"}, + { "getData", (PyCFunction) KeyBlock_getData, METH_NOARGS, + "Get keyblock data" }, + { 0, 0, 0, 0 } +}; + +static void Key_dealloc( PyObject * self ) +{ + PyObject_DEL( self ); +} + +static PyObject *new_Key(Key * oldkey) +{ + BPy_Key *k = PyObject_NEW( BPy_Key, &Key_Type ); + + if( !oldkey ) { + k->key = 0; + } else { + k->key = oldkey; + } + return ( PyObject * ) k; +} + +PyObject *Key_CreatePyObject( Key * k ) +{ + BPy_Key *key = ( BPy_Key * ) new_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; + BPy_Ipo *new_ipo; + + if (k->key->ipo) { + new_ipo = ( BPy_Ipo * ) PyObject_NEW( BPy_Ipo, &Ipo_Type ); + new_ipo->ipo = k->key->ipo; + return (PyObject *) new_ipo; + } else { + return EXPP_incr_ret( Py_None ); + } +} + +static PyObject *Key_getType( PyObject * self ) +{ + BPy_Key *k = ( BPy_Key * ) self; + int idcode; + int type = -1; + + idcode = GS( k->key->from->name ); + + switch( idcode ) { + case ID_ME: + type = KEY_TYPE_MESH; + break; + case ID_CU: + type = KEY_TYPE_CURVE; + break; + case ID_LT: + type = KEY_TYPE_LATTICE; + break; + } + + return PyInt_FromLong( type ); +} + +static PyObject *Key_getBlocks( PyObject * self ) +{ + BPy_Key *k = ( BPy_Key * ) self; + Key *key = k->key; + KeyBlock *kb; + PyObject *keyblock_object; + PyObject *l = PyList_New( 0 ); + + for (kb = key->block.first; kb; kb = kb->next) { + + keyblock_object = KeyBlock_CreatePyObject( kb, key ); + PyList_Append( l, keyblock_object ); + } + + return l; +} + +static void KeyBlock_dealloc( PyObject * self ) +{ + PyObject_DEL( self ); +} + +static PyObject *new_KeyBlock( KeyBlock * oldkeyBlock, Key *parentKey) +{ + BPy_KeyBlock *kb = PyObject_NEW( BPy_KeyBlock, &KeyBlock_Type ); + + kb->key = parentKey; + + if( !oldkeyBlock ) { + kb->keyblock = 0; + } else { + kb->keyblock = oldkeyBlock; + } + return ( PyObject * ) kb; +} + +PyObject *KeyBlock_CreatePyObject( KeyBlock * kb, Key *parentKey ) +{ + BPy_KeyBlock *keyBlock = ( BPy_KeyBlock * ) new_KeyBlock( kb, 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, "pos" ) == 0 ) { + return KeyBlock_getPos(self); + } + return Py_FindMethod( KeyBlock_methods, ( PyObject * ) self, name ); +} + +static PyObject *KeyBlock_getPos( PyObject * self ) +{ + BPy_KeyBlock *kb = ( BPy_KeyBlock * ) self; + return PyFloat_FromDouble( kb->keyblock->pos ); +} + +static PyObject *KeyBlock_getData( PyObject * self ) +{ + /* If this is a mesh key, data is an array of MVert. + If lattice, data is an array of BPoint + If curve, data is an array of BezTriple */ + + BPy_KeyBlock *kb = ( BPy_KeyBlock * ) self; + Key *key = kb->key; + char *datap; + int datasize; + int idcode; + int i; + + PyObject *l = PyList_New( kb->keyblock->totelem ); + + idcode = GS( key->from->name ); + + if (!kb->keyblock->data) { + return EXPP_incr_ret( Py_None ); + } + + switch(idcode) { + case ID_ME: + + datasize = sizeof(MVert); + + for (i=0, datap = kb->keyblock->data; ikeyblock->totelem; i++) { + + BPy_NMVert *mv = PyObject_NEW( BPy_NMVert, &NMVert_Type ); + MVert *vert = (MVert *) datap; + + mv->co[0]=vert->co[0]; + mv->co[1]=vert->co[1]; + mv->co[2]=vert->co[2]; + mv->no[0] = vert->no[0] / 32767.0; + mv->no[1] = vert->no[1] / 32767.0; + mv->no[2] = vert->no[2] / 32767.0; + + mv->uvco[0] = mv->uvco[1] = mv->uvco[2] = 0.0; + mv->index = i; + mv->flag = 0; + + PyList_SetItem(l, i, ( PyObject * ) mv); + + datap += datasize; + } + break; + + case ID_CU: + + datasize = sizeof(BezTriple); + + for (i=0, datap = kb->keyblock->data; ikeyblock->totelem; i++) { + + BezTriple *bt = (BezTriple *) datap; + PyObject *pybt = BezTriple_CreatePyObject( bt ); + + PyList_SetItem( l, i, pybt ); + + datap += datasize; + } + break; + + case ID_LT: + + datasize = sizeof(BPoint); + + for (i=0, datap = kb->keyblock->data; ikeyblock->totelem; i++) { + /* Lacking a python class for BPoint, use a list of four floats */ + BPoint *bp = (BPoint *) datap; + PyObject *bpoint = PyList_New( 4 ); + + PyList_SetItem( bpoint, 0, PyFloat_FromDouble( bp->vec[0] ) ); + PyList_SetItem( bpoint, 1, PyFloat_FromDouble( bp->vec[1] ) ); + PyList_SetItem( bpoint, 2, PyFloat_FromDouble( bp->vec[2] ) ); + PyList_SetItem( bpoint, 3, PyFloat_FromDouble( bp->vec[3] ) ); + + PyList_SetItem( l, i, bpoint ); + + datap += datasize; + } + break; + } + + return l; +} + +static PyObject *M_Key_Get( PyObject * self, PyObject * args ) +{ + char *name = NULL; + Key *key_iter; + char error_msg[64]; + int i; + + if( !PyArg_ParseTuple( args, "|s", &name ) ) + return ( EXPP_ReturnPyObjError( PyExc_TypeError, + "expected string argument (or nothing)" ) ); + + if ( name ) { + for (key_iter = G.main->key.first; key_iter; key_iter=key_iter->id.next) { + if (strcmp ( key_iter->id.name + 2, name ) == 0 ) { + return Key_CreatePyObject( key_iter ); + } + } + + PyOS_snprintf( error_msg, sizeof( error_msg ), + "Key \"%s\" not found", name ); + return ( EXPP_ReturnPyObjError ( PyExc_NameError, error_msg ) ); + + } + + else { + + PyObject *keylist; + + keylist = PyList_New( BLI_countlist( &( G.main->key ) ) ); + + for ( i=0, key_iter = G.main->key.first; key_iter; key_iter=key_iter->id.next, i++ ) { + PyList_SetItem(keylist, i, Key_CreatePyObject(key_iter)); + } + return keylist; + } +} + + +struct PyMethodDef M_Key_methods[] = { + {"Get", M_Key_Get, METH_VARARGS, "Get a key or all key names"}, + {NULL, NULL, 0, NULL} +}; + +PyObject *Key_Init( void ) +{ + PyObject *submodule, *KeyTypes; + + Key_Type.ob_type = &PyType_Type; + KeyBlock_Type.ob_type = &PyType_Type; + + submodule = + Py_InitModule3( "Blender.Key", M_Key_methods, "Key module" ); + + KeyTypes = PyConstant_New( ); + + PyConstant_Insert(( BPy_constant * ) KeyTypes, "MESH", PyInt_FromLong(KEY_TYPE_MESH)); + PyConstant_Insert(( BPy_constant * ) KeyTypes, "CURVE", PyInt_FromLong(KEY_TYPE_CURVE)); + PyConstant_Insert(( BPy_constant * ) KeyTypes, "LATTICE", PyInt_FromLong(KEY_TYPE_LATTICE)); + + PyModule_AddObject( submodule, "Types", KeyTypes); + + /* + PyModule_AddIntConstant( submodule, "TYPE_MESH", KEY_TYPE_MESH ); + PyModule_AddIntConstant( submodule, "TYPE_CURVE", KEY_TYPE_CURVE ); + PyModule_AddIntConstant( submodule, "TYPE_LATTICE", KEY_TYPE_LATTICE ); + */ + return submodule; +} diff --git a/source/blender/python/api2_2x/Key.h b/source/blender/python/api2_2x/Key.h new file mode 100644 index 00000000000..2dc5498900d --- /dev/null +++ b/source/blender/python/api2_2x/Key.h @@ -0,0 +1,68 @@ +/* + * $Id$ + * + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * 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. + * + * This is a new part of Blender. + * + * Contributor(s): Pontus Lidman + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + */ + +#ifndef EXPP_KEY_H +#define EXPP_KEY_H + +#include "Python.h" + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include + +extern PyTypeObject Key_Type; +extern PyTypeObject KeyBlock_Type; + +typedef struct { + PyObject_HEAD /* required python macro */ + Key * key; + // Object *object; /* for vertex grouping info, since it's stored on the object */ + //PyObject *keyBlock; + PyObject *ipo; +} BPy_Key; + +typedef struct { + PyObject_HEAD /* required python macro */ + Key *key; + KeyBlock * keyblock; + // Object *object; /* for vertex grouping info, since it's stored on the object */ +} BPy_KeyBlock; + +PyObject *Key_CreatePyObject( Key * k ); +PyObject *KeyBlock_CreatePyObject( KeyBlock * k, Key *parentKey ); + +PyObject *Key_Init( void ); + +#endif /* EXPP_KEY_H */ diff --git a/source/blender/python/api2_2x/Lattice.c b/source/blender/python/api2_2x/Lattice.c index 7110944fd31..1c177cc67db 100644 --- a/source/blender/python/api2_2x/Lattice.c +++ b/source/blender/python/api2_2x/Lattice.c @@ -49,6 +49,7 @@ #include "blendef.h" #include "gen_utils.h" +#include "Key.h" /*****************************************************************************/ /* Python API function prototypes for the Lattice module. */ @@ -87,11 +88,12 @@ struct PyMethodDef M_Lattice_methods[] = { static PyObject *Lattice_getName( BPy_Lattice * self ); static PyObject *Lattice_setName( BPy_Lattice * self, PyObject * args ); static PyObject *Lattice_setPartitions( BPy_Lattice * self, PyObject * args ); -static PyObject *Lattice_getPartitions( BPy_Lattice * self, PyObject * args ); +static PyObject *Lattice_getPartitions( BPy_Lattice * self ); +static PyObject *Lattice_getKey( BPy_Lattice * self ); static PyObject *Lattice_setKeyTypes( BPy_Lattice * self, PyObject * args ); -static PyObject *Lattice_getKeyTypes( BPy_Lattice * self, PyObject * args ); +static PyObject *Lattice_getKeyTypes( BPy_Lattice * self ); static PyObject *Lattice_setMode( BPy_Lattice * self, PyObject * args ); -static PyObject *Lattice_getMode( BPy_Lattice * self, PyObject * args ); +static PyObject *Lattice_getMode( BPy_Lattice * self ); static PyObject *Lattice_setPoint( BPy_Lattice * self, PyObject * args ); static PyObject *Lattice_getPoint( BPy_Lattice * self, PyObject * args ); static PyObject *Lattice_applyDeform( BPy_Lattice * self, PyObject *args ); @@ -113,6 +115,9 @@ static char Lattice_setPartitions_doc[] = static char Lattice_getPartitions_doc[] = "(str) - Get the number of Partitions in x,y,z"; +static char Lattice_getKey_doc[] = + "() - Get the Key object attached to this Lattice"; + static char Lattice_setKeyTypes_doc[] = "(str) - Set the key types for x,y,z dimensions"; @@ -153,6 +158,8 @@ static PyMethodDef BPy_Lattice_methods[] = { Lattice_setPartitions_doc}, {"getPartitions", ( PyCFunction ) Lattice_getPartitions, METH_NOARGS, Lattice_getPartitions_doc}, + {"getKey", ( PyCFunction ) Lattice_getKey, METH_NOARGS, + Lattice_getKey_doc}, {"setKeyTypes", ( PyCFunction ) Lattice_setKeyTypes, METH_VARARGS, Lattice_setKeyTypes_doc}, {"getKeyTypes", ( PyCFunction ) Lattice_getKeyTypes, METH_NOARGS, @@ -429,7 +436,7 @@ static PyObject *Lattice_setPartitions( BPy_Lattice * self, PyObject * args ) return Py_None; } -static PyObject *Lattice_getPartitions( BPy_Lattice * self, PyObject * args ) +static PyObject *Lattice_getPartitions( BPy_Lattice * self ) { Lattice *bl_Lattice; bl_Lattice = self->Lattice; @@ -439,7 +446,18 @@ static PyObject *Lattice_getPartitions( BPy_Lattice * self, PyObject * args ) ( int ) bl_Lattice->pntsw ); } -static PyObject *Lattice_getKeyTypes( BPy_Lattice * self, PyObject * args ) +static PyObject *Lattice_getKey( BPy_Lattice * self ) +{ + Key *key = self->Lattice->key; + + if (key) + return Key_CreatePyObject(key); + else { + return EXPP_incr_ret(Py_None); + } +} + +static PyObject *Lattice_getKeyTypes( BPy_Lattice * self ) { Lattice *bl_Lattice; char *linear = "linear"; @@ -553,7 +571,7 @@ static PyObject *Lattice_setMode( BPy_Lattice * self, PyObject * args ) return Py_None; } -static PyObject *Lattice_getMode( BPy_Lattice * self, PyObject * args ) +static PyObject *Lattice_getMode( BPy_Lattice * self ) { char type[24]; Lattice *bl_Lattice; @@ -825,12 +843,13 @@ static PyObject *Lattice_getAttr( BPy_Lattice * self, char *name ) self->Lattice->pntsw ); } else if( strcmp( name, "users" ) == 0 ) { attr = PyInt_FromLong( self->Lattice->id.us ); - + } else if( strcmp( name, "key" ) == 0 ) { + return Lattice_getKey(self); } else if( strcmp( name, "__members__" ) == 0 ) - attr = Py_BuildValue( "[s,s,s,s,s,s,s,s,s]", "name", "width", + attr = Py_BuildValue( "[s,s,s,s,s,s,s,s,s,s]", "name", "width", "height", "depth", "widthType", "heightType", "depthType", "mode", - "latSize", "users" ); + "latSize", "users", "key" ); if( !attr ) return ( EXPP_ReturnPyObjError( PyExc_MemoryError, diff --git a/source/blender/python/api2_2x/NMesh.c b/source/blender/python/api2_2x/NMesh.c index 024933e33a1..b073bb949da 100644 --- a/source/blender/python/api2_2x/NMesh.c +++ b/source/blender/python/api2_2x/NMesh.c @@ -26,7 +26,8 @@ * This is a new part of Blender, but it borrows all the old NMesh code. * * Contributor(s): Willian P. Germano, Jordi Rovira i Bonet, Joseph Gilbert, - * Bala Gi, Alexander Szakaly, Stephane Soppera, Campbell Barton, Ken Hughes + * Bala Gi, Alexander Szakaly, Stephane Soppera, Campbell Barton, Ken Hughes, + * Daniel Dunbar. * * ***** END GPL/BL DUAL LICENSE BLOCK ***** */ @@ -68,6 +69,7 @@ #include "blendef.h" #include "mydevice.h" #include "Object.h" +#include "Key.h" #include "Mathutils.h" #include "constant.h" #include "gen_utils.h" @@ -108,6 +110,9 @@ static PyObject *NMesh_transform (PyObject *self, PyObject *args); static char NMesh_printDebug_doc[] = "print debug info about the mesh."; +static char NMesh_getKey_doc[] = + "get the Key object linked to this mesh"; + static char NMesh_addEdge_doc[] = "create an edge between two vertices.\n\ If an edge already exists between those vertices, it is returned.\n\ @@ -1113,6 +1118,18 @@ static PyObject *NMesh_addMaterial( PyObject * self, PyObject * args ) return EXPP_incr_ret( Py_None ); } +static PyObject *NMesh_getKey( BPy_NMesh * self ) +{ + PyObject *keyobj; + + if( self->mesh->key ) + keyobj = Key_CreatePyObject(self->mesh->key); + else + keyobj = EXPP_incr_ret(Py_None); + + return keyobj; +} + static PyObject *NMesh_removeAllKeys( PyObject * self, PyObject * args ) { BPy_NMesh *nm = ( BPy_NMesh * ) self; @@ -1602,6 +1619,7 @@ static struct PyMethodDef NMesh_methods[] = { MethodDef( printDebug ), MethodDef( getVertGroupNames ), MethodDef( getActiveFace ), + MethodDef( getKey ), MethodDef( getMode ), MethodDef( getMaxSmoothAngle ), MethodDef( getSubDivLevels ), @@ -1648,6 +1666,8 @@ static PyObject *NMesh_getattr( PyObject * self, char *name ) return Py_BuildValue( "i", 0 ); } } + else if (strcmp( name, "key") == 0) + return NMesh_getKey((BPy_NMesh*)self); else if( strcmp( name, "faces" ) == 0 ) return EXPP_incr_ret( me->faces ); @@ -1691,10 +1711,10 @@ static PyObject *NMesh_getattr( PyObject * self, char *name ) return EXPP_incr_ret(Py_None); } else if( strcmp( name, "__members__" ) == 0 ) - return Py_BuildValue( "[s,s,s,s,s,s,s,s,s,s]", + return Py_BuildValue( "[s,s,s,s,s,s,s,s,s,s,s]", "name", "materials", "verts", "users", "faces", "maxSmoothAngle", - "subdivLevels", "edges", "oopsLoc", "oopsSel" ); + "subdivLevels", "edges", "oopsLoc", "oopsSel", "key" ); return Py_FindMethod( NMesh_methods, ( PyObject * ) self, name ); } diff --git a/source/blender/python/api2_2x/doc/API_related.py b/source/blender/python/api2_2x/doc/API_related.py index d3cdb4fb45e..ee575463543 100644 --- a/source/blender/python/api2_2x/doc/API_related.py +++ b/source/blender/python/api2_2x/doc/API_related.py @@ -224,7 +224,7 @@ Introduction: # SPACEHANDLER.VIEW3D.EVENT import Blender - from Blender import DRAW + from Blender import Draw evt = Blender.event return_it = False diff --git a/source/blender/python/api2_2x/doc/Curve.py b/source/blender/python/api2_2x/doc/Curve.py index 9a345df5f5a..a7a66bf08ad 100644 --- a/source/blender/python/api2_2x/doc/Curve.py +++ b/source/blender/python/api2_2x/doc/Curve.py @@ -74,6 +74,7 @@ class Curve: @ivar rot: The Curve Data rotation(from the center). @ivar size: The Curve Data size(from the center). @ivar bevob: The Curve Bevel Object + @cvar key: The L{Key.Key} object associated with this Curve, if any. """ def getName(): @@ -382,6 +383,14 @@ class Curve: @rtype: integer """ + def getKey(): + """ + Return the L{Key.Key} object containing the keyframes for this + curve, if any. + @rtype: L{Key.Key} object or None + """ + + class CurNurb: """ The CurNurb Object diff --git a/source/blender/python/api2_2x/doc/Key.py b/source/blender/python/api2_2x/doc/Key.py new file mode 100644 index 00000000000..f091b32c29e --- /dev/null +++ b/source/blender/python/api2_2x/doc/Key.py @@ -0,0 +1,94 @@ +# Blender.Key module and the Key and KeyBlock PyType objects + +""" +The Blender.Key submodule. + +This module provides access to B{Key} objects in Blender. + +@type Types: readonly dictionary +@var Types: The type of a key, indicating the type of data in the +data blocks. + - MESH - the key is a Mesh key; data blocks contain + L{NMesh.NMVert} vertices. + - CURVE - the key is a Curve key; data blocks contain + L{Ipo.BezTriple} points. + - LATTICE - the key is a Lattice key; data blocks contain + BPoints, each point represented as a list of 4 floating point numbers. + +""" + +def Get(name = None): + """ + Get the named Key object from Blender. If the name is omitted, it + will retrieve a list of all keys in Blender. + @type name: string + @param name: the name of the requested key + @return: If name was given, return that Key object (or None if not + found). If a name was not given, return a list of every Key object + in Blender. + """ + +class Key: + """ + The Key object + ============== + An object with keyframes (L{Lattice.Lattice}, L{NMesh.NMesh} or + L{Curve.Curve}) will contain a Key object representing the + keyframe data. + @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. + """ + def getBlocks(): + """ + Get a list of L{KeyBlock}s, containing the keyframes defined for + this Key. + """ + +class KeyBlock: + """ + The KeyBlock object + =================== + Each Key object has a list of KeyBlocks attached, each KeyBlock + representing a keyframe. + + @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. + """ + 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. + """ diff --git a/source/blender/python/api2_2x/doc/Lattice.py b/source/blender/python/api2_2x/doc/Lattice.py index 3723e290491..97cee2faaa9 100644 --- a/source/blender/python/api2_2x/doc/Lattice.py +++ b/source/blender/python/api2_2x/doc/Lattice.py @@ -76,6 +76,7 @@ class Lattice: @ivar depthType: The z dimension key type. @ivar mode: The current mode of the Lattice. @ivar latSize: The number of points in this Lattice. + @cvar key: The L{Key.Key} object associated with this Lattice. """ def getName(): @@ -189,6 +190,13 @@ class Lattice: much probably an undesired effect. """ + def getKey(): + """ + Returns the L{Key.Key} object associated with this Lattice. + @rtype: L{Key.Key} + @return: A key object representing the keyframes of the lattice or None. + """ + def insertKey(frame): """ Inserts the current state of the Lattice as a new absolute keyframe diff --git a/source/blender/python/api2_2x/doc/NMesh.py b/source/blender/python/api2_2x/doc/NMesh.py index 2fa2de747af..6f6666b24f7 100644 --- a/source/blender/python/api2_2x/doc/NMesh.py +++ b/source/blender/python/api2_2x/doc/NMesh.py @@ -357,6 +357,7 @@ class NMesh: @ivar mode: The mode flags for this mesh. See L{setMode}. @ivar subDivLevels: The [display, rendering] subdivision levels in [1, 6]. @ivar maxSmoothAngle: The max angle for auto smoothing. See L{setMode}. + @cvar key: The L{Key.Key} object attached to this mesh, if any. """ def addEdge(v1, v2): @@ -532,6 +533,13 @@ class NMesh: and its weight is a float value. """ + def getKey(): + """ + Get the Key object representing the Vertex Keys (absolute or + relative) assigned to this mesh. + @rtype: L{Key.Key} object or None + """ + def insertKey(frame = None, type = 'relative'): """ Insert a mesh key at the given frame. Remember to L{update} the nmesh -- cgit v1.2.3