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:
authorCampbell Barton <ideasman42@gmail.com>2007-09-07 11:45:07 +0400
committerCampbell Barton <ideasman42@gmail.com>2007-09-07 11:45:07 +0400
commit6731f7e01a95b4cc1cfaa0085915a2ad0e586b17 (patch)
treef56c3c50a732a5bc7457fac2b427de4627a723ea
parent16fc98de33e4250dd4d8a3473575c5bcfe7aa52a (diff)
matrix.scalePart() was never returning negative values, even tho its impossible to get correct negative scale/rotation values from a matrix, blender gets these values in apply_obmat (editobject.c) in a way that keeps the transformation the same at least.
copied the code from apply_obmat to be used by matrix.scalePart() ob.getSize('worldspace'), this makes the hack I committed to FBX before not needed (rolled back in this commit)
-rw-r--r--release/scripts/export_fbx.py58
-rw-r--r--source/blender/python/api2_2x/Object.c19
-rw-r--r--source/blender/python/api2_2x/matrix.c19
3 files changed, 37 insertions, 59 deletions
diff --git a/release/scripts/export_fbx.py b/release/scripts/export_fbx.py
index cd47dc81969..581f913a7fb 100644
--- a/release/scripts/export_fbx.py
+++ b/release/scripts/export_fbx.py
@@ -257,27 +257,8 @@ def write(filename, batch_objects = None, \
BATCH_OWN_DIR = False
):
- # Extreamly evil hack, only keep here for now until the python API's improved.
- # to solve this we should add a function like matrix.toLocScaleRot() that copies code from
- # editobject.c's apply_obmat function.
- # for now this will do.
- DUMMY_OB = Blender.Object.New('Empty') # dont add to a scene, will be removed later...
- def matrix_to_LocScaRot(matrix):
- RAD2DEG = 0.017453292519943295
- DUMMY_OB.setMatrix(matrix)
- return (\
- (DUMMY_OB.LocX, DUMMY_OB.LocY, DUMMY_OB.LocZ),\
- (DUMMY_OB.SizeX, DUMMY_OB.SizeY, DUMMY_OB.SizeZ),\
- (DUMMY_OB.RotX/RAD2DEG, DUMMY_OB.RotY/RAD2DEG, DUMMY_OB.RotZ/RAD2DEG)\
- )
-
- def matrix_translationPart(matrix):
- return matrix_to_LocScaRot(matrix)[0]
- def matrix_scalePart(matrix):
- return matrix_to_LocScaRot(matrix)[1]
- def matrix_toEuler(matrix):
- return matrix_to_LocScaRot(matrix)[2]
- # end evil hack
+
+
# ----------------- Batch support!
if BATCH_ENABLE:
@@ -561,15 +542,9 @@ def write(filename, batch_objects = None, \
matrix_rot = matrix.rotationPart()
- ''' # use hack instead
loc = tuple(matrix.translationPart())
scale = tuple(matrix.scalePart())
rot = tuple(matrix_rot.toEuler())
- '''
-
- loc = tuple(matrix_translationPart(matrix))
- scale = tuple(matrix_scalePart(matrix))
- rot = tuple(matrix_toEuler(matrix_rot))
else:
if ob and not matrix: matrix = ob.matrixWorld * GLOBAL_MATRIX
@@ -578,37 +553,26 @@ def write(filename, batch_objects = None, \
# matrix = matrix_scale * matrix
if matrix:
- ''' # use hack instead
- loc = tuple(matrix.translationPart())
+ loc = tuple(matrix.translationPart())
scale = tuple(matrix.scalePart())
- '''
- loc = tuple(matrix_translationPart(matrix))
- scale = tuple(matrix_scalePart(matrix))
-
matrix_rot = matrix.rotationPart()
# Lamps need to be rotated
if ob and ob.type =='Lamp':
matrix_rot = mtx_x90 * matrix_rot
- # use hack instead
- #rot = tuple(matrix_rot.toEuler())
- rot = tuple(matrix_toEuler(matrix_rot))
+ rot = tuple(matrix_rot.toEuler())
elif ob and ob.type =='Camera':
y = Vector(0,1,0) * matrix_rot
matrix_rot = matrix_rot * RotationMatrix(90, 3, 'r', y)
- # use hack instead
- #rot = tuple(matrix_rot.toEuler())
- rot = tuple(matrix_toEuler(matrix_rot))
+ rot = tuple(matrix_rot.toEuler())
else:
- # use hack instead
- # rot = tuple(matrix_rot.toEuler())
- rot = tuple(matrix_toEuler(matrix_rot))
+ rot = tuple(matrix_rot.toEuler())
else:
if not loc:
loc = 0,0,0
scale = 1,1,1
rot = 0,0,0
-
+
return loc, rot, scale, matrix, matrix_rot
def write_object_tx(ob, loc, matrix, matrix_mod= None):
@@ -2575,16 +2539,10 @@ Takes: {''')
# ----------------
# ----------------
for TX_LAYER, TX_CHAN in enumerate('TRS'): # transform, rotate, scale
- ''' # use hack instead
+
if TX_CHAN=='T': context_bone_anim_vecs = [mtx[0].translationPart() for mtx in context_bone_anim_mats]
elif TX_CHAN=='R': context_bone_anim_vecs = [mtx[1].toEuler() for mtx in context_bone_anim_mats]
else: context_bone_anim_vecs = [mtx[0].scalePart() for mtx in context_bone_anim_mats]
- '''
-
- if TX_CHAN=='T': context_bone_anim_vecs = [matrix_translationPart(mtx[0]) for mtx in context_bone_anim_mats]
- elif TX_CHAN=='R': context_bone_anim_vecs = [matrix_toEuler(mtx[1]) for mtx in context_bone_anim_mats]
- else: context_bone_anim_vecs = [matrix_scalePart(mtx[0]) for mtx in context_bone_anim_mats]
-
file.write('\n\t\t\t\tChannel: "%s" {' % TX_CHAN) # translation
diff --git a/source/blender/python/api2_2x/Object.c b/source/blender/python/api2_2x/Object.c
index c829c33ec3e..4b34a416195 100644
--- a/source/blender/python/api2_2x/Object.c
+++ b/source/blender/python/api2_2x/Object.c
@@ -1383,14 +1383,23 @@ static PyObject *Object_getSize( BPy_Object * self, PyObject * args )
"expected a string or nothing" );
if( BLI_streq( space, "worldspace" ) ) { /* Worldspace matrix */
- float scale[3];
+ float rot[3];
+ float mat[3][3], imat[3][3], tmat[3][3];
disable_where_script( 1 );
where_is_object( self->object );
- Mat4ToSize(self->object->obmat, scale);
+
+ Mat3CpyMat4(mat, self->object->obmat);
+
+ /* functionality copied from editobject.c apply_obmat */
+ Mat3ToEul(mat, rot);
+ EulToMat3(rot, tmat);
+ Mat3Inv(imat, tmat);
+ Mat3MulMat3(tmat, imat, mat);
+
attr = Py_BuildValue( "fff",
- self->object->size[0],
- self->object->size[1],
- self->object->size[2] );
+ tmat[0][0],
+ tmat[1][1],
+ tmat[2][2] );
disable_where_script( 0 );
} else if( BLI_streq( space, "localspace" ) ) { /* Localspace matrix */
attr = Py_BuildValue( "fff",
diff --git a/source/blender/python/api2_2x/matrix.c b/source/blender/python/api2_2x/matrix.c
index a09d3142479..45858ef71e6 100644
--- a/source/blender/python/api2_2x/matrix.c
+++ b/source/blender/python/api2_2x/matrix.c
@@ -202,16 +202,27 @@ PyObject *Matrix_RotationPart(MatrixObject * self)
/*---------------------------Matrix.scalePart() --------------------*/
PyObject *Matrix_scalePart(MatrixObject * self)
{
- float scale[3];
-
+ float scale[3], rot[3];
+ float mat[3][3], imat[3][3], tmat[3][3];
+
/*must be 3-4 cols, 3-4 rows, square matrix*/
if(self->colSize == 4 && self->rowSize == 4)
- Mat4ToSize((float (*)[4])*self->matrix, scale);
+ Mat3CpyMat4(mat, (float (*)[4])*self->matrix);
else if(self->colSize == 3 && self->rowSize == 3)
- Mat3ToSize((float (*)[3])*self->matrix, scale);
+ Mat3CpyMat3(mat, (float (*)[3])*self->matrix);
else
return EXPP_ReturnPyObjError(PyExc_AttributeError,
"Matrix.scalePart(): inappropriate matrix size - expects 3x3 or 4x4 matrix\n");
+
+ /* functionality copied from editobject.c apply_obmat */
+ Mat3ToEul(mat, rot);
+ EulToMat3(rot, tmat);
+ Mat3Inv(imat, tmat);
+ Mat3MulMat3(tmat, imat, mat);
+
+ scale[0]= tmat[0][0];
+ scale[1]= tmat[1][1];
+ scale[2]= tmat[2][2];
return newVectorObject(scale, 3, Py_NEW);
}
/*---------------------------Matrix.invert() ---------------------*/