===Python API===
Allow object.setMatrix() to accept 3x3 matrices by extending to a 4x4 internally. Also check the dimensions of the new matrix and throw an exception if not a 3x3 or 4x4.
This commit is contained in:
@@ -2197,11 +2197,26 @@ static PyObject *Object_setMatrix( BPy_Object * self, PyObject * args )
|
|||||||
( PyExc_TypeError,
|
( PyExc_TypeError,
|
||||||
"expected matrix object as argument" );
|
"expected matrix object as argument" );
|
||||||
|
|
||||||
for( x = 0; x < 4; x++ ) {
|
if( mat->rowSize == 4 && mat->colSize == 4 ) {
|
||||||
for( y = 0; y < 4; y++ ) {
|
for( x = 0; x < 4; x++ ) {
|
||||||
self->object->obmat[x][y] = mat->matrix[x][y];
|
for( y = 0; y < 4; y++ ) {
|
||||||
|
self->object->obmat[x][y] = mat->matrix[x][y];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
} else if( mat->rowSize == 3 && mat->colSize == 3 ) {
|
||||||
|
for( x = 0; x < 3; x++ ) {
|
||||||
|
for( y = 0; y < 3; y++ ) {
|
||||||
|
self->object->obmat[x][y] = mat->matrix[x][y];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* if a 3x3 matrix, clear the fourth row/column */
|
||||||
|
for( x = 0; x < 3; x++ )
|
||||||
|
self->object->obmat[x][3] = self->object->obmat[3][x] = 0.0;
|
||||||
|
self->object->obmat[3][3] = 1.0;
|
||||||
|
} else
|
||||||
|
return EXPP_ReturnPyObjError ( PyExc_ValueError,
|
||||||
|
"expected 3x3 or 4x4 matrix" );
|
||||||
|
|
||||||
apply_obmat( self->object );
|
apply_obmat( self->object );
|
||||||
|
|
||||||
/* since we have messed with object, we need to flag for DAG recalc */
|
/* since we have messed with object, we need to flag for DAG recalc */
|
||||||
|
|||||||
@@ -696,9 +696,10 @@ class Object:
|
|||||||
|
|
||||||
def setMatrix(matrix):
|
def setMatrix(matrix):
|
||||||
"""
|
"""
|
||||||
Sets the object's matrix and updates it's transformation.
|
Sets the object's matrix and updates its transformation.
|
||||||
@type matrix: Py_Matrix 4x4
|
@type matrix: Py_Matrix 3x3 or 4x4
|
||||||
@param matrix: a python matrix 4x4.
|
@param matrix: a 3x3 or 4x4 Python matrix. If a 3x3 matrix is given,
|
||||||
|
it is extended to a 4x4 matrix.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def setName(name):
|
def setName(name):
|
||||||
|
|||||||
Reference in New Issue
Block a user