[Bf-python] another getMatrix('worldspace') patch for bf-blender hopefully final
Campbell Barton
cbarton at metavr.com
Sun Jun 27 14:00:57 CEST 2004
Hi
This has been applied to bf-blender but not the py docs.
Why does this happen? - Not complaining, its just since I bothered to
write the docs and make the patch, why not include it.?
- Cam
> Heres a patch that
>
> * uses one getMatrix function
> * full python doc's
> * uses local spelling
> * adds matrixLocale and matrixWorld class variables
> * works well :)
>
> It seems rediculous to have 3 class variable names for 1 var.
> mat/matrix/matrixLocale.
>
>
> I was thinking that it would be cool to be able to switch a context bool,
> 0/1 : world/local and then all the funcs act accordingly rather then
> duplicate each function/ class var.
> but this would not be in keeping with the rest of bpython.
>
> - Cam
>
>------------------------------------------------------------------------
>
>Index: source/blender/python/api2_2x/Object.c
>===================================================================
>RCS file: /cvsroot/bf-blender/blender/source/blender/python/api2_2x/Object.c,v
>retrieving revision 1.79
>diff -u -r1.79 Object.c
>--- source/blender/python/api2_2x/Object.c 11 Jun 2004 13:15:50 -0000 1.79
>+++ source/blender/python/api2_2x/Object.c 26 Jun 2004 15:30:56 -0000
>@@ -108,7 +108,7 @@
> static PyObject *Object_getIpo (BPy_Object *self);
> static PyObject *Object_getLocation (BPy_Object *self, PyObject *args);
> static PyObject *Object_getMaterials (BPy_Object *self);
>-static PyObject *Object_getMatrix (BPy_Object *self);
>+static PyObject *Object_getMatrix (BPy_Object *self, PyObject *args);
> static PyObject *Object_getName (BPy_Object *self);
> static PyObject *Object_getParent (BPy_Object *self);
> static PyObject *Object_getSize (BPy_Object *self, PyObject *args);
>@@ -176,7 +176,7 @@
> "Returns the object's location (x, y, z)"},
> {"getMaterials", (PyCFunction)Object_getMaterials, METH_NOARGS,
> "Returns list of materials assigned to the object"},
>- {"getMatrix", (PyCFunction)Object_getMatrix, METH_NOARGS,
>+ {"getMatrix", (PyCFunction)Object_getMatrix, METH_VARARGS,
> "Returns the object matrix"},
> {"getName", (PyCFunction)Object_getName, METH_NOARGS,
> "Returns the name of the object"},
>@@ -871,16 +871,31 @@
> self->object->totcol));
> }
>
>-static PyObject *Object_getMatrix (BPy_Object *self)
>+static PyObject *Object_getMatrix (BPy_Object *self, PyObject *args)
> {
>- PyObject * matrix;
>+ PyObject *matrix;
>+ char *space = "localspace"; /* default to local */
>
>+ if (!PyArg_ParseTuple(args, "|s", &space)){
>+ return (EXPP_ReturnPyObjError (PyExc_AttributeError,
>+ "expected a string or nothing"));
>+ }
>+ //new matrix
> matrix = newMatrixObject(NULL, 4, 4);
>- object_to_mat4(self->object, *((MatrixObject*)matrix)->matrix);
>
>+ if (BLI_streq(space, "worldspace")){ /* Worldspace matrix */
>+ where_is_object(self->object);
>+ Mat4CpyMat4(*((MatrixObject*)matrix)->matrix, self->object->obmat);
>+ } else if (BLI_streq(space, "localspace")) { /* Localspace matrix*/
>+ object_to_mat4(self->object, *((MatrixObject*)matrix)->matrix);
>+ } else {
>+ return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
>+ "correct spaces are 'worldspace' and 'localspace', none defaults to localspace"));
>+ }
> return matrix;
> }
>
>+
> static PyObject *Object_getName (BPy_Object *self)
> {
> PyObject *attr = Py_BuildValue ("s", self->object->id.name+2);
>@@ -1945,7 +1960,7 @@
> {
> struct Object * object;
> struct Ika * ika;
>-
>+
> object = obj->object;
> if (StringEqual (name, "LocX"))
> return (PyFloat_FromDouble(object->loc[0]));
>@@ -2048,10 +2063,12 @@
> }
> return (Ipo_CreatePyObject (object->ipo));
> }
>- if (StringEqual (name, "mat"))
>- return (Object_getMatrix (obj));
>- if (StringEqual (name, "matrix"))
>- return (Object_getMatrix (obj));
>+ if (StringEqual (name, "mat") || StringEqual (name, "matrix"))
>+ return (Object_getMatrix (obj, Py_BuildValue("(s)","localspace")));
>+ if (StringEqual (name, "matrixWorld"))
>+ return (Object_getMatrix (obj, Py_BuildValue("(s)","worldspace")));
>+ if (StringEqual (name, "matrixLocal"))
>+ return (Object_getMatrix (obj, Py_BuildValue("(s)","localspace")));
> if (StringEqual (name, "colbits"))
> return (Py_BuildValue ("h", object->colbits));
> if (StringEqual (name, "drawType"))
>Index: source/blender/python/api2_2x/doc/Object.py
>===================================================================
>RCS file: /cvsroot/bf-blender/blender/source/blender/python/api2_2x/doc/Object.py,v
>retrieving revision 1.18
>diff -u -r1.18 Object.py
>--- source/blender/python/api2_2x/doc/Object.py 8 Jun 2004 04:41:02 -0000 1.18
>+++ source/blender/python/api2_2x/doc/Object.py 26 Jun 2004 15:30:57 -0000
>@@ -140,8 +140,10 @@
> @cvar track: The object tracking this object. (Read-only)
> @cvar data: The data of the object. (Read-only)
> @cvar ipo: The ipo data associated with the object. (Read-only)
>- @cvar mat: The actual matrix of the object. (Read-only)
>- @cvar matrix: The actual matrix of the object. (Read-only)
>+ @cvar mat: The matrix of the object relative to its parent. (Read-only)
>+ @cvar matrix: The matrix of the object relative to its parent. (Read-only)
>+ @cvar matrixLocal: The matrix of the object relative to its parent. (Read-only)
>+ @cvar matrixWorld: The matrix of the object in world space. (Read-only)
> @cvar colbits: The Material usage mask. A set bit #n means: the Material
> #n in the Object's material list is used. Otherwise, the Material #n
> of the Objects Data material list is displayed.
>@@ -277,8 +279,16 @@
> @return: list of Material Objects assigned to the object.
> """
>
>- def getMatrix():
>+ def getMatrix(space = 'localspace'):
> """
>+ Returns the object matrix.
>+ Use getMatrix() or getMatrix('localspace') to get the matrix relative to the objects parent.
>+ Somtimes the absolute matrix of the object is required (taking into account vertex parents, tracking and ipo's)
>+ in this case use getMatrix('worldspace')
>+ @type space: string. Values are:
>+ @param space: possible values are:
>+ - localspace (default)
>+ - worldspace
> Returns the object matrix.
> @rtype: Py_Matrix
> @return: a python matrix 4x4
>
>
--
Campbell J Barton
133 Hope Street
Geelong West, Victoria 3218 Australia
URL: http://www.metavr.com
e-mail: cbarton at metavr.com
phone: AU (03) 5229 0241
More information about the Bf-python
mailing list