[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11957] branches/2-44-stable/blender: 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.

Campbell Barton cbarton at metavr.com
Fri Sep 7 09:45:08 CEST 2007


Revision: 11957
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11957
Author:   campbellbarton
Date:     2007-09-07 09:45:07 +0200 (Fri, 07 Sep 2007)

Log Message:
-----------
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)

Modified Paths:
--------------
    branches/2-44-stable/blender/release/scripts/export_fbx.py
    branches/2-44-stable/blender/source/blender/python/api2_2x/Object.c
    branches/2-44-stable/blender/source/blender/python/api2_2x/matrix.c

Modified: branches/2-44-stable/blender/release/scripts/export_fbx.py
===================================================================
--- branches/2-44-stable/blender/release/scripts/export_fbx.py	2007-09-07 06:57:02 UTC (rev 11956)
+++ branches/2-44-stable/blender/release/scripts/export_fbx.py	2007-09-07 07:45:07 UTC (rev 11957)
@@ -257,28 +257,9 @@
 		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:
 		if os == None:	BATCH_OWN_DIR = False
@@ -561,16 +542,10 @@
 				
 			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
 			matrix_rot = matrix
@@ -578,37 +553,26 @@
 			#	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,17 +2539,11 @@
 						# ----------------
 						# ----------------
 						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
 							
 							for i in xrange(3):

Modified: branches/2-44-stable/blender/source/blender/python/api2_2x/Object.c
===================================================================
--- branches/2-44-stable/blender/source/blender/python/api2_2x/Object.c	2007-09-07 06:57:02 UTC (rev 11956)
+++ branches/2-44-stable/blender/source/blender/python/api2_2x/Object.c	2007-09-07 07:45:07 UTC (rev 11957)
@@ -1383,14 +1383,23 @@
 					"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",

Modified: branches/2-44-stable/blender/source/blender/python/api2_2x/matrix.c
===================================================================
--- branches/2-44-stable/blender/source/blender/python/api2_2x/matrix.c	2007-09-07 06:57:02 UTC (rev 11956)
+++ branches/2-44-stable/blender/source/blender/python/api2_2x/matrix.c	2007-09-07 07:45:07 UTC (rev 11957)
@@ -202,16 +202,27 @@
 /*---------------------------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() ---------------------*/





More information about the Bf-blender-cvs mailing list