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).
This commit is contained in:
2006-07-09 13:04:42 +00:00
parent 1ce6c22f27
commit c8a37212da
2 changed files with 33 additions and 14 deletions

View File

@@ -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" ) ) {
/* old behavior, prior to 2.34, check this method's doc string: */
} else {
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
"wrong parameter, expected nothing or either 'worldspace' (default),\n\
'localspace' or '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 {
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
"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);
}

View File

@@ -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.