3rd attempt to commit, metaball fixes and small vector optimization
authorCampbell Barton <ideasman42@gmail.com>
Sat, 30 Sep 2006 14:14:49 +0000 (14:14 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 30 Sep 2006 14:14:49 +0000 (14:14 +0000)
source/blender/python/api2_2x/BGL.c
source/blender/python/api2_2x/Bone.c
source/blender/python/api2_2x/Draw.c
source/blender/python/api2_2x/Lattice.c
source/blender/python/api2_2x/Metaball.c
source/blender/python/api2_2x/Metaball.h
source/blender/python/api2_2x/Object.c
source/blender/python/api2_2x/euler.c
source/blender/python/api2_2x/logic.c
source/blender/python/api2_2x/quat.c
source/blender/python/api2_2x/vector.c

index 03d282151a7bb71800ce96dcbf9b25339a5a1c17..1a287528d589503fbec07eaab0ca7bfe3769c413 100644 (file)
@@ -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 {
index bed859a5a78dc7a0ef8e16a06c46bf783b07a132..0d6594e2aef319015df8e30e128e53ccd01b1f7d 100644 (file)
@@ -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)
index d2a1331d4eb286a55d32d2c651aa684e5363d34f..9728d8ec5b0bc0953b802a9f32c25ace1229e4c9 100644 (file)
@@ -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;
index a85a69c4be276507f37be4179ceaa879cc57bdb7..cceb536efd7e27c3561132200f977dc87e0d9d3d 100644 (file)
@@ -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 ) {
index d8eae80aa7a016c2360bf46e74bb9d37a6896af8..ca4f61e887822bc02da6da3a60ff67fa036fde68 100644 (file)
@@ -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;
 }
 
index a01111cc6f784c6d08300fd6854ecd63ade0fd7f..e2d37ed7706543db3b18d67dbfafc70b953e1c9d 100644 (file)
@@ -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 );
 
index 6aeff4b320c41623dd4be22bdead23d6ab9ba65d..c1ac3ef1c33752ff7626c2d0dfab8839bb96ddec 100644 (file)
@@ -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;
index 6956bf42ffea2aa3d20edbe75c11d07509fd0ca2..4d2402256d0489a677e9a57f242b483958fd56a7 100644 (file)
@@ -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[]-------------------------
index 50163af41fc5e6928f395972fbee65db8cc1b6e3..5af991e9f203295efe27f6cf5e4a8ff1b0287069 100644 (file)
@@ -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;
 }
index 43aa7422101e2ab4f03e225bd79e019329d5ce53..f94ad11e241b925a83c0435af37384fbe626aed7 100644 (file)
@@ -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[]-------------------------
index d7497a88cbdeb5d35d44740abdcee91d4e96bbcb..af85331011e9814c58794179fef975e4fb6d5d1a 100644 (file)
@@ -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[]-------------------------