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 Gilbert <ascotan@gmail.com>2004-06-26 18:38:56 +0400
committerJoseph Gilbert <ascotan@gmail.com>2004-06-26 18:38:56 +0400
commit2a6c8a2797ab3f629d6ab7c36e5e33cc3f7af9d3 (patch)
treef4dbcd7a1827953d13d64874aa4bd505a1e090bc /source/blender/python/api2_2x/Object.c
parent4c53f38756976704bab11a3dd8c33c71d926e6b8 (diff)
- added support for getting worlspace and localspace matrices from objects through python. Add cvars matrixWorld/matrixLocal.
- credits to Campbell Barton
Diffstat (limited to 'source/blender/python/api2_2x/Object.c')
-rw-r--r--source/blender/python/api2_2x/Object.c38
1 files changed, 27 insertions, 11 deletions
diff --git a/source/blender/python/api2_2x/Object.c b/source/blender/python/api2_2x/Object.c
index 94f3e3ef194..508bc47a0a4 100644
--- a/source/blender/python/api2_2x/Object.c
+++ b/source/blender/python/api2_2x/Object.c
@@ -28,7 +28,7 @@
*
*
* Contributor(s): Michel Selten, Willian Germano, Jacques Guignot,
- * Joseph Gilbert, Stephen Swaney, Bala Gi
+ * Joseph Gilbert, Stephen Swaney, Bala Gi, Campbell Barton
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
@@ -108,7 +108,7 @@ static PyObject *Object_getInverseMatrix (BPy_Object *self);
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,8 +176,8 @@ hierarchy (faster)"},
"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,
- "Returns the object matrix"},
+ {"getMatrix", (PyCFunction)Object_getMatrix, METH_VARARGS,
+ "Returns the object matrix - worlspace or localspace (default)"},
{"getName", (PyCFunction)Object_getName, METH_NOARGS,
"Returns the name of the object"},
{"getParent", (PyCFunction)Object_getParent, METH_NOARGS,
@@ -871,13 +871,27 @@ static PyObject *Object_getMaterials (BPy_Object *self)
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 localespace"));
+ }
return matrix;
}
@@ -2048,10 +2062,12 @@ static PyObject* Object_getAttr (BPy_Object *obj, char *name)
}
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"))