From 32b1e2383bf50ebe30c26618496ec966620d1d23 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 30 Sep 2006 14:14:49 +0000 Subject: [PATCH] 3rd attempt to commit, metaball fixes and small vector optimization --- source/blender/python/api2_2x/BGL.c | 2 +- source/blender/python/api2_2x/Bone.c | 2 +- source/blender/python/api2_2x/Draw.c | 8 +++--- source/blender/python/api2_2x/Lattice.c | 32 ++++++++++++------------ source/blender/python/api2_2x/Metaball.c | 19 ++++++++++++++ source/blender/python/api2_2x/Metaball.h | 2 +- source/blender/python/api2_2x/Object.c | 3 +++ source/blender/python/api2_2x/euler.c | 2 +- source/blender/python/api2_2x/logic.c | 10 ++++---- source/blender/python/api2_2x/quat.c | 3 +-- source/blender/python/api2_2x/vector.c | 2 +- 11 files changed, 53 insertions(+), 32 deletions(-) diff --git a/source/blender/python/api2_2x/BGL.c b/source/blender/python/api2_2x/BGL.c index 03d282151a7..1a287528d58 100644 --- a/source/blender/python/api2_2x/BGL.c +++ b/source/blender/python/api2_2x/BGL.c @@ -246,7 +246,7 @@ static PyObject *Buffer_item(PyObject *self, int i) case GL_BYTE: return Py_BuildValue("b", buf->buf.asbyte[i]); case GL_SHORT: return Py_BuildValue("h", buf->buf.asshort[i]); case GL_INT: return Py_BuildValue("i", buf->buf.asint[i]); - case GL_FLOAT: return Py_BuildValue("f", buf->buf.asfloat[i]); + case GL_FLOAT: return PyFloat_FromDouble(buf->buf.asfloat[i]); case GL_DOUBLE: return Py_BuildValue("d", buf->buf.asdouble[i]); } } else { diff --git a/source/blender/python/api2_2x/Bone.c b/source/blender/python/api2_2x/Bone.c index bed859a5a78..0d6594e2aef 100644 --- a/source/blender/python/api2_2x/Bone.c +++ b/source/blender/python/api2_2x/Bone.c @@ -1122,7 +1122,7 @@ static int Bone_setMatrix(BPy_Bone *self, PyObject *value, void *closure) //------------------------Bone.length (get) static PyObject *Bone_getLength(BPy_Bone *self, void *closure) { - return Py_BuildValue("f", self->bone->length); + return PyFloat_FromDouble(self->bone->length); } //------------------------Bone.length (set) static int Bone_setLength(BPy_Bone *self, PyObject *value, void *closure) diff --git a/source/blender/python/api2_2x/Draw.c b/source/blender/python/api2_2x/Draw.c index d2a1331d4eb..9728d8ec5b0 100644 --- a/source/blender/python/api2_2x/Draw.c +++ b/source/blender/python/api2_2x/Draw.c @@ -384,11 +384,11 @@ static PyObject *Button_getattr( PyObject * self, char *name ) if( strcmp( name, "val" ) == 0 ) { if( but->type == BINT_TYPE ) - return Py_BuildValue( "i", but->val.asint ); + return PyInt_FromLong( but->val.asint ); else if( but->type == BFLOAT_TYPE ) - return Py_BuildValue( "f", but->val.asfloat ); + return PyFloat_FromDouble( but->val.asfloat ); else if( but->type == BSTRING_TYPE ) - return Py_BuildValue( "s", but->val.asstr ); + return PyString_FromString( but->val.asstr ); else if( but->type == BVECTOR_TYPE ) return Py_BuildValue( "fff", but->val.asvec[0], but->val.asvec[1], but->val.asvec[2] ); } @@ -1391,7 +1391,7 @@ static PyObject *Method_PupStrInput( PyObject * self, PyObject * args ) return Py_None; } - ret = Py_BuildValue( "s", tmp ); + ret = PyString_FromString( tmp ); if( ret ) return ret; diff --git a/source/blender/python/api2_2x/Lattice.c b/source/blender/python/api2_2x/Lattice.c index a85a69c4be2..cceb536efd7 100644 --- a/source/blender/python/api2_2x/Lattice.c +++ b/source/blender/python/api2_2x/Lattice.c @@ -592,7 +592,7 @@ static PyObject *Lattice_getMode( BPy_Lattice * self ) return EXPP_ReturnPyObjError( PyExc_TypeError, "bad mode type..." ); - return Py_BuildValue( "s", type ); + return PyString_FromString( type ); } static PyObject *Lattice_setPoint( BPy_Lattice * self, PyObject * args ) @@ -822,51 +822,51 @@ static PyObject *Lattice_getAttr( BPy_Lattice * self, char *name ) if( strcmp( name, "name" ) == 0 ) attr = PyString_FromString( self->Lattice->id.name + 2 ); else if( strcmp( name, "width" ) == 0 ) - attr = Py_BuildValue( "i", self->Lattice->pntsu ); + attr = PyInt_FromLong( self->Lattice->pntsu ); else if( strcmp( name, "height" ) == 0 ) - attr = Py_BuildValue( "i", self->Lattice->pntsv ); + attr = PyInt_FromLong( self->Lattice->pntsv ); else if( strcmp( name, "depth" ) == 0 ) - attr = Py_BuildValue( "i", self->Lattice->pntsw ); + attr = PyInt_FromLong( self->Lattice->pntsw ); else if( strcmp( name, "widthType" ) == 0 ) { if( self->Lattice->typeu == 0 ) - attr = Py_BuildValue( "s", "Linear" ); + attr = PyString_FromString( "Linear" ); else if( self->Lattice->typeu == 1 ) - attr = Py_BuildValue( "s", "Cardinal" ); + attr = PyString_FromString( "Cardinal" ); else if( self->Lattice->typeu == 2 ) - attr = Py_BuildValue( "s", "Bspline" ); + attr = PyString_FromString( "Bspline" ); else return EXPP_ReturnPyObjError( PyExc_ValueError, "bad widthType..." ); } else if( strcmp( name, "heightType" ) == 0 ) { if( self->Lattice->typev == 0 ) - attr = Py_BuildValue( "s", "Linear" ); + attr = PyString_FromString( "Linear" ); else if( self->Lattice->typev == 1 ) - attr = Py_BuildValue( "s", "Cardinal" ); + attr = PyString_FromString( "Cardinal" ); else if( self->Lattice->typev == 2 ) - attr = Py_BuildValue( "s", "Bspline" ); + attr = PyString_FromString( "Bspline" ); else return EXPP_ReturnPyObjError( PyExc_ValueError, "bad widthType..." ); } else if( strcmp( name, "depthType" ) == 0 ) { if( self->Lattice->typew == 0 ) - attr = Py_BuildValue( "s", "Linear" ); + attr = PyString_FromString( "Linear" ); else if( self->Lattice->typew == 1 ) - attr = Py_BuildValue( "s", "Cardinal" ); + attr = PyString_FromString( "Cardinal" ); else if( self->Lattice->typew == 2 ) - attr = Py_BuildValue( "s", "Bspline" ); + attr = PyString_FromString( "Bspline" ); else return EXPP_ReturnPyObjError( PyExc_ValueError, "bad widthType..." ); } else if( strcmp( name, "mode" ) == 0 ) { if( self->Lattice->flag == 1 ) - attr = Py_BuildValue( "s", "Grid" ); + attr = PyString_FromString( "Grid" ); else if( self->Lattice->flag == 3 ) - attr = Py_BuildValue( "s", "Outside" ); + attr = PyString_FromString( "Outside" ); else return EXPP_ReturnPyObjError( PyExc_ValueError, "bad mode..." ); } else if( strcmp( name, "latSize" ) == 0 ) { - attr = Py_BuildValue( "i", self->Lattice->pntsu * + attr = PyInt_FromLong( self->Lattice->pntsu * self->Lattice->pntsv * self->Lattice->pntsw ); } else if( strcmp( name, "users" ) == 0 ) { diff --git a/source/blender/python/api2_2x/Metaball.c b/source/blender/python/api2_2x/Metaball.c index d8eae80aa7a..ca4f61e8878 100644 --- a/source/blender/python/api2_2x/Metaball.c +++ b/source/blender/python/api2_2x/Metaball.c @@ -37,6 +37,7 @@ #include "BKE_mball.h" #include "BKE_library.h" #include "BLI_blenlib.h" +#include "BLI_arithb.h" /* for quat normal */ #include "DNA_object_types.h" #include "Mathutils.h" #include "Material.h" @@ -727,6 +728,21 @@ static PyObject *Metaball_copy( BPy_Metaball * self ) } +/* These are needed by Object.c */ +PyObject *Metaball_CreatePyObject( MetaBall * mball) +{ + BPy_Metaball *py_mball= PyObject_NEW( BPy_Metaball, &Metaball_Type ); + + if( !py_mball ) + return EXPP_ReturnPyObjError( PyExc_MemoryError, + "couldn't create BPy_Metaball object" ); + + py_mball->metaball= mball; + + return ( PyObject * ) py_mball; +} + + static PyObject *MetaElemSeq_CreatePyObject(BPy_Metaball *self, MetaElem *iter) { BPy_MetaElemSeq *seq = PyObject_NEW( BPy_MetaElemSeq, &MetaElemSeq_Type); @@ -877,6 +893,9 @@ static int Metaelem_setQuat( BPy_Metaelem * self, QuaternionObject * value ) for (i = 0; i < 4; i++) self->metaelem->quat[i]= value->quat[i]; + /* need to normalize or metaball drawing can go into an infinate loop */ + NormalQuat(self->metaelem->quat); + return 0; } diff --git a/source/blender/python/api2_2x/Metaball.h b/source/blender/python/api2_2x/Metaball.h index a01111cc6f7..e2d37ed7706 100644 --- a/source/blender/python/api2_2x/Metaball.h +++ b/source/blender/python/api2_2x/Metaball.h @@ -75,7 +75,7 @@ typedef struct { */ PyObject *Metaball_Init( void ); -PyObject *Metaball_CreatePyObject( MetaBall * metaball ); +PyObject *Metaball_CreatePyObject( MetaBall * mball ); MetaBall *Metaball_FromPyObject( PyObject * py_obj ); int Metaball_CheckPyObject( PyObject * py_obj ); diff --git a/source/blender/python/api2_2x/Object.c b/source/blender/python/api2_2x/Object.c index 6aeff4b320c..c1ac3ef1c33 100644 --- a/source/blender/python/api2_2x/Object.c +++ b/source/blender/python/api2_2x/Object.c @@ -4409,6 +4409,9 @@ static PyObject *get_obj_data( BPy_Object *self, int mesh ) else /* else get as Mesh */ data_object = Mesh_CreatePyObject( object->data, object ); break; + case OB_MBALL: + data_object = Metaball_CreatePyObject( object->data ); + break; case ID_OB: data_object = Object_CreatePyObject( object->data ); break; diff --git a/source/blender/python/api2_2x/euler.c b/source/blender/python/api2_2x/euler.c index 6956bf42ffe..4d2402256d0 100644 --- a/source/blender/python/api2_2x/euler.c +++ b/source/blender/python/api2_2x/euler.c @@ -315,7 +315,7 @@ static PyObject *Euler_item(EulerObject * self, int i) return EXPP_ReturnPyObjError(PyExc_IndexError, "euler[attribute]: array index out of range\n"); - return Py_BuildValue("f", self->eul[i]); + return PyFloat_FromDouble(self->eul[i]); } //----------------------------object[]------------------------- diff --git a/source/blender/python/api2_2x/logic.c b/source/blender/python/api2_2x/logic.c index 50163af41fc..5af991e9f20 100644 --- a/source/blender/python/api2_2x/logic.c +++ b/source/blender/python/api2_2x/logic.c @@ -542,15 +542,15 @@ static PyObject *Property_getType( BPy_Property * self ) type = self->type; if( type == PROP_BOOL ) - attr = Py_BuildValue( "s", "BOOL" ); + attr = PyString_FromString( "BOOL" ); else if( type == PROP_INT ) - attr = Py_BuildValue( "s", "INT" ); + attr = PyString_FromString( "INT" ); else if( type == PROP_FLOAT ) - attr = Py_BuildValue( "s", "FLOAT" ); + attr = PyString_FromString( "FLOAT" ); else if( type == PROP_STRING ) - attr = Py_BuildValue( "s", "STRING" ); + attr = PyString_FromString( "STRING" ); else if( type == PROP_TIME ) - attr = Py_BuildValue( "s", "TIME" ); + attr = PyString_FromString( "TIME" ); return attr; } diff --git a/source/blender/python/api2_2x/quat.c b/source/blender/python/api2_2x/quat.c index 43aa7422101..f94ad11e241 100644 --- a/source/blender/python/api2_2x/quat.c +++ b/source/blender/python/api2_2x/quat.c @@ -318,8 +318,7 @@ static PyObject *Quaternion_item(QuaternionObject * self, int i) if(i < 0 || i >= 4) return EXPP_ReturnPyObjError(PyExc_IndexError, "quaternion[attribute]: array index out of range\n"); - - return Py_BuildValue("f", self->quat[i]); + return PyFloat_FromDouble(self->quat[i]); } //----------------------------object[]------------------------- diff --git a/source/blender/python/api2_2x/vector.c b/source/blender/python/api2_2x/vector.c index d7497a88cbd..af85331011e 100644 --- a/source/blender/python/api2_2x/vector.c +++ b/source/blender/python/api2_2x/vector.c @@ -418,7 +418,7 @@ static PyObject *Vector_item(VectorObject * self, int i) return EXPP_ReturnPyObjError(PyExc_IndexError, "vector[index]: out of range\n"); - return Py_BuildValue("f", self->vec[i]); + return PyFloat_FromDouble(self->vec[i]); } /*----------------------------object[]-------------------------