Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Eagar <joeedh@gmail.com>2007-09-08 04:04:32 +0400
committerJoseph Eagar <joeedh@gmail.com>2007-09-08 04:04:32 +0400
commit8aa152df93c5bfd41115def264b9fa608e986e4e (patch)
tree64f6eed70824e00524e145f06cd5083b9cbc33a4 /source/blender/python/api2_2x/Key.c
parent40c0b37a2a7504b312f844d73f6f9955753bab36 (diff)
=Python Bugfix=
The python wrapper code for shape keys was really bad; whoever wrote it (mis)read the wrong section of blender's codebase and got the totally wrong idea. The code was definitely broken to the point where either it had to be fixed for 2.45, or else the entire keyblock wrapper would have to be removed from the stable branch. The fact that it didn't crash is just sheer luck; the code assume mesh keys were MVerts, when in fact mesh keys are just arrays of three-float vectors. So shapekey data can now be editing directly, and is exposed as Mathutils.Vectors. Also I updated the epydocs to explain how it all works now.
Diffstat (limited to 'source/blender/python/api2_2x/Key.c')
-rw-r--r--source/blender/python/api2_2x/Key.c94
1 files changed, 51 insertions, 43 deletions
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; i<kb->keyblock->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;
}