diff --git a/source/blender/python/api2_2x/Key.c b/source/blender/python/api2_2x/Key.c index 6f35f35f0f3..f72f01b2eb1 100644 --- a/source/blender/python/api2_2x/Key.c +++ b/source/blender/python/api2_2x/Key.c @@ -519,23 +519,12 @@ static PyObject *KeyBlock_getData( PyObject * self ) case ID_ME: for (i=0, datap = kb->keyblock->data; ikeyblock->totelem; i++) { + PyObject *vec = newVectorObject((float*)datap, 3, Py_WRAP); + + if (!vec) return EXPP_ReturnPyObjError( PyExc_MemoryError, + "could not allocate memory for Blender.Mathutils.Vector wrapper!" ); - 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] = 0.0; - mv->no[1] = 0.0; - mv->no[2] = 0.0; - - mv->uvco[0] = mv->uvco[1] = mv->uvco[2] = 0.0; - mv->index = i; - mv->flag = 0; - - PyList_SetItem(l, i, ( PyObject * ) mv); - + PyList_SetItem(l, i, vec); datap += kb->key->elemsize; } break; @@ -552,44 +541,63 @@ static PyObject *KeyBlock_getData( PyObject * self ) Py_DECREF (l); l = PyList_New( datasize ); for( i = 0, datap = kb->keyblock->data; i < datasize; - i++, datap += sizeof(float)*12 ) { - /* - * since the key only stores the control point and not the - * other BezTriple attributes, build a Py_NEW BezTriple - */ - PyObject *pybt = newBezTriple( (float *)datap ); - PyList_SetItem( l, i, pybt ); + i++, datap += sizeof(float)*3*4) { + PyObject *tuple = PyTuple_New(4), *vec; + float *vecs = (float*)datap; + + if (!tuple) return EXPP_ReturnPyObjError( PyExc_MemoryError, + "PyTuple_New() failed!" ); + + vec = newVectorObject(vecs, 3, Py_WRAP); + if (!vec) return EXPP_ReturnPyObjError( PyExc_MemoryError, + "Could not allocate memory for Blender.Mathutils.Vector wrapper!" ); + + PyTuple_SET_ITEM( tuple, 0, vec); + + vecs += 3; + vec = newVectorObject(vecs, 3, Py_WRAP); + if (!vec) return EXPP_ReturnPyObjError( PyExc_MemoryError, + "Could not allocate memory for Blender.Mathutils.Vector wrapper!" ); + + PyTuple_SET_ITEM( tuple, 1, vec); + + vecs += 3; + vec = newVectorObject(vecs, 3, Py_WRAP); + if (!vec) return EXPP_ReturnPyObjError( PyExc_MemoryError, + "Could not allocate memory for Blender.Mathutils.Vector wrapper!" ); + + PyTuple_SET_ITEM( tuple, 2, vec); + + /*tilts*/ + vecs += 3; + vec = newVectorObject(vecs, 3, Py_WRAP); + if (!vec) return EXPP_ReturnPyObjError( PyExc_MemoryError, + "Could not allocate memory for Blender.Mathutils.Vector wrapper!" ); + + PyTuple_SET_ITEM( tuple, 3, vec); + + PyList_SetItem( l, i, tuple ); } } else { for( i = 0, datap = kb->keyblock->data; i < datasize; i++, datap += kb->key->elemsize ) { - PyObject *pybt; - float *fp = (float *)datap; - pybt = Py_BuildValue( "[f,f,f]", fp[0],fp[1],fp[2]); - if( !pybt ) { - Py_DECREF( l ); - return EXPP_ReturnPyObjError( PyExc_MemoryError, - "Py_BuildValue() failed" ); - } - PyList_SetItem( l, i, pybt ); + PyObject *vec = newVectorObject((float*)datap, 4, Py_WRAP); + if (!vec) return EXPP_ReturnPyObjError( PyExc_MemoryError, + "could not allocate memory for Blender.Mathutils.Vector wrapper!" ); + + PyList_SetItem( l, i, vec ); } } break; case ID_LT: - for( i = 0, datap = kb->keyblock->data; i < kb->keyblock->totelem; i++, datap += kb->key->elemsize ) { - /* Lacking a python class for BPoint, use a list of three floats */ - PyObject *pybt; - float *fp = (float *)datap; - pybt = Py_BuildValue( "[f,f,f]", fp[0],fp[1],fp[2]); - if( !pybt ) { - Py_DECREF( l ); - return EXPP_ReturnPyObjError( PyExc_MemoryError, - "Py_BuildValue() failed" ); - } - PyList_SetItem( l, i, pybt ); + PyObject *vec = newVectorObject((float*)datap, 3, Py_WRAP); + if (!vec) return EXPP_ReturnPyObjError( PyExc_MemoryError, + "Could not allocate memory for Blender.Mathutils.Vector wrapper!" ); + + PyList_SetItem( l, i, vec ); } break; } diff --git a/source/blender/python/api2_2x/doc/Key.py b/source/blender/python/api2_2x/doc/Key.py index 584a7f066b1..98a279e68e7 100644 --- a/source/blender/python/api2_2x/doc/Key.py +++ b/source/blender/python/api2_2x/doc/Key.py @@ -89,16 +89,33 @@ class KeyBlock: 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 + will have a different data format depending on the type of this Key. - - Mesh keys have a list of L{NMVert} objects in the data + + Note that prior to 2.45 the behaviour of this function + was different (and very wrong). Old scripts might need to be + updated. + + - Mesh keys have a list of L{Vectors} 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 three floating-point numbers (the - coordinate for each lattice vertex). - - Curve keys return either a list of L{BezTriple} - objects in the data if the curve is a Bezier curve, otherwise it - returns lists of three floats for each NURB or poly coordinate. + - Lattice keys have a list of L{Vectors} objects in the data + block. + - Curve keys return either a list of tuples, eacn containing + four L{Vectors} (if the curve is a Bezier curve), + or otherwise just a list of L{Vectors}. + + For bezier keys, the first three vectors in the tuple are the Bezier + triple vectors, while the fourth vector's first element is the curve tilt + (the other two elements are reserved and are currently unused). + + For non-Bezier keys, the first three elements of the returned vector is + the curve handle point, while the fourth element is the tilt. + + + A word on relative shape keys; relative shape keys are not actually + stored as offsets to the base shape key (like you'd expect). Instead, + the additive relative offset is calculated on the fly by comparing a + shape key with its base key, which is always the very first shapekey + in the keyblock list. """