diff options
author | Willian Padovani Germano <wpgermano@gmail.com> | 2006-07-09 17:04:42 +0400 |
---|---|---|
committer | Willian Padovani Germano <wpgermano@gmail.com> | 2006-07-09 17:04:42 +0400 |
commit | c8a37212daffb992be301222144be0559e976e79 (patch) | |
tree | 168516dc89e5e9320c8173fb153bac58b48df0d0 /source/blender | |
parent | 1ce6c22f2700b2473f5ad8e0c79ff5802fb65a62 (diff) |
BPython API:
-fixing object.getMatrix("localspace") and object.matrixLocal to return
the local matrix (returns global space matrix if the object doesn't
have a parent).
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/python/api2_2x/Object.c | 38 | ||||
-rw-r--r-- | source/blender/python/api2_2x/doc/Object.py | 5 |
2 files changed, 31 insertions, 12 deletions
diff --git a/source/blender/python/api2_2x/Object.c b/source/blender/python/api2_2x/Object.c index d12dfa4d16e..0d41b6c9b76 100644 --- a/source/blender/python/api2_2x/Object.c +++ b/source/blender/python/api2_2x/Object.c @@ -1429,8 +1429,7 @@ static PyObject *Object_getMaterials( BPy_Object * self, PyObject * args ) static PyObject *Object_getMatrix( BPy_Object * self, PyObject * args ) { - float matrix[16] = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}; + Object *ob = self->object; char *space = "worldspace"; /* default to world */ if( !PyArg_ParseTuple( args, "|s", &space ) ) { @@ -1438,20 +1437,39 @@ static PyObject *Object_getMatrix( BPy_Object * self, PyObject * args ) "expected a string or nothing" ) ); } - if( BLI_streq( space, "worldspace" ) ) { /* Worldspace matrix */ + if( BLI_streq( space, "worldspace" ) ) { /* world space matrix */ disable_where_script( 1 ); where_is_object( self->object ); disable_where_script( 0 ); - } else if( BLI_streq( space, "localspace" ) ) { /* Localspace matrix */ - object_to_mat4( self->object, (float (*)[4])matrix ); - return newMatrixObject(matrix,4,4,Py_NEW); - } else if( BLI_streq( space, "old_worldspace" ) ) { + } + + else if( BLI_streq( space, "localspace" )) {/* return local space matrix */ + if (ob->parent) { + float matrix[4][4]; /* for the result */ + float invmat[4][4]; /* for inverse of parent's matrix */ + + Mat4Invert(invmat, self->object->parent->obmat ); + Mat4MulMat4(matrix, invmat, self->object->obmat); + return newMatrixObject((float*)matrix,4,4,Py_NEW); + } + else { /* no parent, so return world space matrix */ + disable_where_script( 1 ); + where_is_object( self->object ); + disable_where_script( 0 ); + } + } + + else if( BLI_streq( space, "old_worldspace" ) ) { /* old behavior, prior to 2.34, check this method's doc string: */ - } else { + } + + else { return ( EXPP_ReturnPyObjError( PyExc_RuntimeError, - "wrong parameter, expected nothing or either 'worldspace' (default),\n\ -'localspace' or 'old_worldspace'" ) ); + "wrong parameter, expected nothing or either\n\ + 'worldspace' (default), 'localspace' or 'old_worldspace'" ) ); } + + /* return world space matrix */ return newMatrixObject((float*)self->object->obmat,4,4,Py_WRAP); } diff --git a/source/blender/python/api2_2x/doc/Object.py b/source/blender/python/api2_2x/doc/Object.py index 8fddec11be3..566de1bab38 100644 --- a/source/blender/python/api2_2x/doc/Object.py +++ b/source/blender/python/api2_2x/doc/Object.py @@ -237,7 +237,7 @@ class Object: @ivar ipo: The ipo data associated with the object. (Read-only) @ivar mat: alias for L{matrix<Object.Object.matrix>}: the matrix of the object in world space. (Read-only) @ivar matrix: The matrix of the object in world space, same as L{matrixWorld<Object.Object.matrixWorld>}. (Read-only) - @ivar matrixLocal: The matrix of the object relative to its parent. (Read-only) + @ivar matrixLocal: The matrix of the object relative to its parent (or L{matrixWorld<Object.Object.matrixWorld>} if there is no parent). (Read-only) @ivar matrixWorld: The matrix of the object in world space. (Read-only) @ivar 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 @@ -526,7 +526,8 @@ class Object: @param space: The desired matrix: - worldspace (default): absolute, taking vertex parents, tracking and Ipo's into account; - - localspace: relative to the object's parent; + - localspace: relative to the object's parent (returns worldspace + matrix if the object doesn't have a parent); - old_worldspace: old behavior, prior to Blender 2.34, where eventual changes made by the script itself were not taken into account until a redraw happened, either called by the script or upon its exit. |