[Bf-python] getMatrix('worldspace') patch for bf-blender

Gilbert, Joseph jgilbert at tigr.org
Fri Jun 25 15:56:14 CEST 2004


Hi, :)
  Looks good but I don't think it's necessary to have an internal
function because the getMatrix() will be backwards compatible anyway
(when no arg is used). The extra stringcompare functions in getattr will
never get called. Everything minus the internal function is perfect :)
Oh, I was thinking that this also needs to be done on the bone module
for rot/loc/size I think. Not sure where else this is applicable.

static PyObject *Object_getMatrix (BPy_Object *self, PyObject *args);
....
{"getMatrix", (PyCFunction)Object_getMatrix, METH_VARARGS,"Returns the
object matrix"},
.....
static PyObject *Object_getMatrix (BPy_Object *self, PyObject *args)
{
    PyObject  *matrix;
    char *space = "localespace";	 /* default to locale */
	
    if (!PyArg_ParseTuple(args, "|s", &space))
    {
        return (EXPP_ReturnPyObjError (PyExc_AttributeError,
          "expected a string or nothing"));
    }
	
    matrix = newMatrixObject(NULL, 4, 4);
	
    if (BLI_streq(space, "worldspace"))		/* Worldspace matrix */
    {
        where_is_object(self->object);
        Mat4CpyMat4(*((MatrixObject*)matrix)->matrix,
self->object->obmat);
    } else if (BLI_streq(space, "localespace")) { /* Localespace matrix
*/
        object_to_mat4(self->object, *((MatrixObject*)matrix)->matrix);
    } else {
        return (EXPP_ReturnPyObjError (PyExc_RuntimeError, "correct
spaces 
          are 'worldspace' and 'localespace', none defaults to 
          localespace"));
    }
    return matrix;
}
 ....
if (StringEqual (name, "mat"))
    return (Object_getMatrix (obj));
if (StringEqual (name, "matrix"))
    return (Object_getMatrix (obj));
....




More information about the Bf-python mailing list