[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21254] branches/blender2.5/blender/source : Python API

Campbell Barton ideasman42 at gmail.com
Tue Jun 30 02:42:17 CEST 2009


Revision: 21254
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21254
Author:   campbellbarton
Date:     2009-06-30 02:42:17 +0200 (Tue, 30 Jun 2009)

Log Message:
-----------
Python API
Mathutils support for subclassing Vector, Quat, Euler and Matrix types.

Removed C docstrings, prefer to make sure our epydocs are well maintained rather then duplicate, vague doc strings.
Will convert scripts to detect missing docs from the BGE.

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/python/generic/Geometry.c
    branches/blender2.5/blender/source/blender/python/generic/Mathutils.c
    branches/blender2.5/blender/source/blender/python/generic/euler.c
    branches/blender2.5/blender/source/blender/python/generic/euler.h
    branches/blender2.5/blender/source/blender/python/generic/matrix.c
    branches/blender2.5/blender/source/blender/python/generic/matrix.h
    branches/blender2.5/blender/source/blender/python/generic/quat.c
    branches/blender2.5/blender/source/blender/python/generic/quat.h
    branches/blender2.5/blender/source/blender/python/generic/vector.c
    branches/blender2.5/blender/source/blender/python/generic/vector.h
    branches/blender2.5/blender/source/gameengine/Expressions/PyObjectPlus.cpp
    branches/blender2.5/blender/source/gameengine/Ketsji/KX_PyMath.cpp

Modified: branches/blender2.5/blender/source/blender/python/generic/Geometry.c
===================================================================
--- branches/blender2.5/blender/source/blender/python/generic/Geometry.c	2009-06-29 23:59:57 UTC (rev 21253)
+++ branches/blender2.5/blender/source/blender/python/generic/Geometry.c	2009-06-30 00:42:17 UTC (rev 21254)
@@ -273,7 +273,7 @@
 			/*X of vert, Y of hoz. no calculation needed */
 			newvec[0]= a1x;
 			newvec[1]= b1y;
-			return newVectorObject(newvec, 2, Py_NEW);
+			return newVectorObject(newvec, 2, Py_NEW, NULL);
 		}
 		
 		yi = (float)(((b1y / fabs(b1x - b2x)) * fabs(b2x - a1x)) + ((b2y / fabs(b1x - b2x)) * fabs(b1x - a1x)));
@@ -285,7 +285,7 @@
 		}
 		newvec[0]= a1x;
 		newvec[1]= yi;
-		return newVectorObject(newvec, 2, Py_NEW);
+		return newVectorObject(newvec, 2, Py_NEW, NULL);
 	} else if (fabs(a2y-a1y) < eul) {  /* hoz line1 */
 		if (fabs(b2y-b1y) < eul) { /*hoz line2*/
 			Py_RETURN_NONE; /*2 hoz lines dont intersect*/
@@ -300,7 +300,7 @@
 		}
 		newvec[0]= xi;
 		newvec[1]= a1y;
-		return newVectorObject(newvec, 2, Py_NEW);
+		return newVectorObject(newvec, 2, Py_NEW, NULL);
 	}
 	
 	b1 = (a2y-a1y)/(a2x-a1x);
@@ -317,7 +317,7 @@
 	if ((a1x-xi)*(xi-a2x) >= 0 && (b1x-xi)*(xi-b2x) >= 0 && (a1y-yi)*(yi-a2y) >= 0 && (b1y-yi)*(yi-b2y)>=0) {
 		newvec[0]= xi;
 		newvec[1]= yi;
-		return newVectorObject(newvec, 2, Py_NEW);
+		return newVectorObject(newvec, 2, Py_NEW, NULL);
 	}
 	Py_RETURN_NONE;
 }
@@ -355,7 +355,7 @@
 	lambda = lambda_cp_line_ex(pt_in, l1, l2, pt_out);
 	
 	ret = PyTuple_New(2);
-	PyTuple_SET_ITEM( ret, 0, newVectorObject(pt_out, 3, Py_NEW) );
+	PyTuple_SET_ITEM( ret, 0, newVectorObject(pt_out, 3, Py_NEW, NULL) );
 	PyTuple_SET_ITEM( ret, 1, PyFloat_FromDouble(lambda) );
 	return ret;
 }
@@ -535,7 +535,7 @@
 	list= PyList_New(resolu);
 	fp= coord_array;
 	for(i=0; i<resolu; i++, fp= fp+dims) {
-		PyList_SET_ITEM(list, i, newVectorObject(fp, dims, Py_NEW));
+		PyList_SET_ITEM(list, i, newVectorObject(fp, dims, Py_NEW, NULL));
 	}
 	MEM_freeN(coord_array);
 	return list;

Modified: branches/blender2.5/blender/source/blender/python/generic/Mathutils.c
===================================================================
--- branches/blender2.5/blender/source/blender/python/generic/Mathutils.c	2009-06-29 23:59:57 UTC (rev 21253)
+++ branches/blender2.5/blender/source/blender/python/generic/Mathutils.c	2009-06-30 00:42:17 UTC (rev 21254)
@@ -176,7 +176,7 @@
 				quat->quat[3]*quat->quat[3]*vec->vec[2] - 2*quat->quat[0]*quat->quat[2]*vec->vec[0] - 
 				quat->quat[2]*quat->quat[2]*vec->vec[2] + 2*quat->quat[0]*quat->quat[1]*vec->vec[1] - 
 				quat->quat[1]*quat->quat[1]*vec->vec[2] + quat->quat[0]*quat->quat[0]*vec->vec[2];
-			return newVectorObject(rot, 3, Py_NEW);
+			return newVectorObject(rot, 3, Py_NEW, NULL);
 		}
 	}else if(VectorObject_Check(arg1)){
 		vec = (VectorObject*)arg1;
@@ -201,7 +201,7 @@
 				quat->quat[3]*quat->quat[3]*vec->vec[2] - 2*quat->quat[0]*quat->quat[2]*vec->vec[0] - 
 				quat->quat[2]*quat->quat[2]*vec->vec[2] + 2*quat->quat[0]*quat->quat[1]*vec->vec[1] - 
 				quat->quat[1]*quat->quat[1]*vec->vec[2] + quat->quat[0]*quat->quat[0]*vec->vec[2];
-			return newVectorObject(rot, 3, Py_NEW);
+			return newVectorObject(rot, 3, Py_NEW, NULL);
 		}
 	}
 
@@ -311,7 +311,7 @@
 	for(x = 0; x < vec1->size; x++) {
 		vec[x] = 0.5f * (vec1->vec[x] + vec2->vec[x]);
 	}
-	return newVectorObject(vec, vec1->size, Py_NEW);
+	return newVectorObject(vec, vec1->size, Py_NEW, NULL);
 }
 //----------------------------------Mathutils.ProjectVecs() -------------
 //projects vector 1 onto vector 2
@@ -348,7 +348,7 @@
 	for(x = 0; x < size; x++) {
 		vec[x] = (float)(dot * vec2->vec[x]);
 	}
-	return newVectorObject(vec, size, Py_NEW);
+	return newVectorObject(vec, size, Py_NEW, NULL);
 }
 //----------------------------------MATRIX FUNCTIONS--------------------
 //----------------------------------Mathutils.RotationMatrix() ----------
@@ -493,7 +493,7 @@
 		mat[3] = 0.0f;
 	}
 	//pass to matrix creation
-	return newMatrixObject(mat, matSize, matSize, Py_NEW);
+	return newMatrixObject(mat, matSize, matSize, Py_NEW, NULL);
 }
 //----------------------------------Mathutils.TranslationMatrix() -------
 //creates a translation matrix
@@ -520,7 +520,7 @@
 	mat[13] = vec->vec[1];
 	mat[14] = vec->vec[2];
 
-	return newMatrixObject(mat, 4, 4, Py_NEW);
+	return newMatrixObject(mat, 4, 4, Py_NEW, NULL);
 }
 //----------------------------------Mathutils.ScaleMatrix() -------------
 //mat is a 1D array of floats - row[0][0],row[0][1], row[1][0], etc.
@@ -598,7 +598,7 @@
 		mat[3] = 0.0f;
 	}
 	//pass to matrix creation
-	return newMatrixObject(mat, matSize, matSize, Py_NEW);
+	return newMatrixObject(mat, matSize, matSize, Py_NEW, NULL);
 }
 //----------------------------------Mathutils.OrthoProjectionMatrix() ---
 //mat is a 1D array of floats - row[0][0],row[0][1], row[1][0], etc.
@@ -701,7 +701,7 @@
 		mat[3] = 0.0f;
 	}
 	//pass to matrix creation
-	return newMatrixObject(mat, matSize, matSize, Py_NEW);
+	return newMatrixObject(mat, matSize, matSize, Py_NEW, NULL);
 }
 //----------------------------------Mathutils.ShearMatrix() -------------
 //creates a shear matrix
@@ -768,7 +768,7 @@
 		mat[3] = 0.0f;
 	}
 	//pass to matrix creation
-	return newMatrixObject(mat, matSize, matSize, Py_NEW);
+	return newMatrixObject(mat, matSize, matSize, Py_NEW, NULL);
 }
 //----------------------------------QUATERNION FUNCTIONS-----------------
 
@@ -801,7 +801,7 @@
 		tempQuat[x] /= (float)(dot * dot);
 	}
 	QuatMul(quat, tempQuat, quatV->quat);
-	return newQuaternionObject(quat, Py_NEW);
+	return newQuaternionObject(quat, Py_NEW, NULL);
 }
 //----------------------------------Mathutils.Slerp() ------------------
 //attemps to interpolate 2 quaternions and return the result
@@ -862,7 +862,7 @@
 	quat[2] = (float)(quat_u[2] * x + quat_v[2] * y);
 	quat[3] = (float)(quat_u[3] * x + quat_v[3] * y);
 
-	return newQuaternionObject(quat, Py_NEW);
+	return newQuaternionObject(quat, Py_NEW, NULL);
 }
 //----------------------------------EULER FUNCTIONS----------------------
 //---------------------------------INTERSECTION FUNCTIONS--------------------
@@ -936,7 +936,7 @@
 	VecMulf(dir, t);
 	VecAddf(pvec, orig, dir);
 
-	return newVectorObject(pvec, 3, Py_NEW);
+	return newVectorObject(pvec, 3, Py_NEW, NULL);
 }
 //----------------------------------Mathutils.LineIntersect() -------------------
 /* Line-Line intersection using algorithm from mathworld.wolfram.com */
@@ -993,8 +993,8 @@
 		}
 		else {
 			tuple = PyTuple_New( 2 );
-			PyTuple_SetItem( tuple, 0, newVectorObject(i1, vec1->size, Py_NEW) );
-			PyTuple_SetItem( tuple, 1, newVectorObject(i2, vec1->size, Py_NEW) );
+			PyTuple_SetItem( tuple, 0, newVectorObject(i1, vec1->size, Py_NEW, NULL) );
+			PyTuple_SetItem( tuple, 1, newVectorObject(i2, vec1->size, Py_NEW, NULL) );
 			return tuple;
 		}
 	}
@@ -1055,7 +1055,7 @@
 	VecAddf(n1, n2, n1);
 	Normalize(n1);
 
-	return newVectorObject(n1, 3, Py_NEW);
+	return newVectorObject(n1, 3, Py_NEW, NULL);
 }
 
 //----------------------------Mathutils.TriangleNormal() -------------------
@@ -1091,7 +1091,7 @@
 	Crossf(n, e2, e1);
 	Normalize(n);
 
-	return newVectorObject(n, 3, Py_NEW);
+	return newVectorObject(n, 3, Py_NEW, NULL);
 }
 
 //--------------------------------- AREA FUNCTIONS--------------------
@@ -1254,6 +1254,6 @@
 		PyMem_Free(self->data);
 
 	Py_XDECREF(self->cb_user);
-	PyObject_DEL(self);
+	Py_TYPE(self)->tp_free(self); // PyObject_DEL(self); // breaks subtypes
 }
 

Modified: branches/blender2.5/blender/source/blender/python/generic/euler.c
===================================================================
--- branches/blender2.5/blender/source/blender/python/generic/euler.c	2009-06-29 23:59:57 UTC (rev 21253)
+++ branches/blender2.5/blender/source/blender/python/generic/euler.c	2009-06-30 00:42:17 UTC (rev 21254)
@@ -34,13 +34,6 @@
 
 
 //-------------------------DOC STRINGS ---------------------------
-static char Euler_Zero_doc[] = "() - set all values in the euler to 0";
-static char Euler_Unique_doc[] ="() - sets the euler rotation a unique shortest arc rotation - tests for gimbal lock";
-static char Euler_ToMatrix_doc[] =	"() - returns a rotation matrix representing the euler rotation";
-static char Euler_ToQuat_doc[] = "() - returns a quaternion representing the euler rotation";
-static char Euler_Rotate_doc[] = "() - rotate a euler by certain amount around an axis of rotation";
-static char Euler_copy_doc[] = "() - returns a copy of the euler.";
-static char Euler_MakeCompatible_doc[] = "(euler) - Make this user compatible with another (no axis flipping).";
 
 static PyObject *Euler_Zero( EulerObject * self );
 static PyObject *Euler_Unique( EulerObject * self );
@@ -52,22 +45,21 @@
 
 //-----------------------METHOD DEFINITIONS ----------------------
 static struct PyMethodDef Euler_methods[] = {
-	{"zero", (PyCFunction) Euler_Zero, METH_NOARGS, Euler_Zero_doc},
-	{"unique", (PyCFunction) Euler_Unique, METH_NOARGS, Euler_Unique_doc},
-	{"toMatrix", (PyCFunction) Euler_ToMatrix, METH_NOARGS, Euler_ToMatrix_doc},
-	{"toQuat", (PyCFunction) Euler_ToQuat, METH_NOARGS, Euler_ToQuat_doc},
-	{"rotate", (PyCFunction) Euler_Rotate, METH_VARARGS, Euler_Rotate_doc},
-	{"makeCompatible", (PyCFunction) Euler_MakeCompatible, METH_O, Euler_MakeCompatible_doc},
-	{"__copy__", (PyCFunction) Euler_copy, METH_VARARGS, Euler_copy_doc},
-	{"copy", (PyCFunction) Euler_copy, METH_VARARGS, Euler_copy_doc},
+	{"zero", (PyCFunction) Euler_Zero, METH_NOARGS, NULL},
+	{"unique", (PyCFunction) Euler_Unique, METH_NOARGS, NULL},
+	{"toMatrix", (PyCFunction) Euler_ToMatrix, METH_NOARGS, NULL},
+	{"toQuat", (PyCFunction) Euler_ToQuat, METH_NOARGS, NULL},
+	{"rotate", (PyCFunction) Euler_Rotate, METH_VARARGS, NULL},
+	{"makeCompatible", (PyCFunction) Euler_MakeCompatible, METH_O, NULL},
+	{"__copy__", (PyCFunction) Euler_copy, METH_VARARGS, NULL},
+	{"copy", (PyCFunction) Euler_copy, METH_VARARGS, NULL},
 	{NULL, NULL, 0, NULL}
 };
 
 //----------------------------------Mathutils.Euler() -------------------
 //makes a new euler for you to play with
-static PyObject *Euler_new(PyObject * self, PyObject * args, PyObject * kwargs)
+static PyObject *Euler_new(PyTypeObject * type, PyObject * args, PyObject * kwargs)
 {
-
 	PyObject *listObject = NULL;
 	int size, i;
 	float eul[3];
@@ -84,7 +76,7 @@
 		}
 	} else if (size == 0) {
 		//returns a new empty 3d euler

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list