[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [12302] trunk/blender/source/blender/ python/api2_2x: made setting the pose_bone.poseMatrix possible, this does not set the matrix directly, only the pose

Campbell Barton cbarton at metavr.com
Sat Oct 20 13:28:59 CEST 2007


Revision: 12302
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=12302
Author:   campbellbarton
Date:     2007-10-20 13:28:58 +0200 (Sat, 20 Oct 2007)

Log Message:
-----------
made setting the pose_bone.poseMatrix possible, this does not set the matrix directly, only the pose 
bones loc/size/rot, when dealing with an armature without constraints this works as expected. it uses 
the same code as Copy Visual Loc/Size/Rot.

Modified Paths:
--------------
    trunk/blender/source/blender/python/api2_2x/Pose.c
    trunk/blender/source/blender/python/api2_2x/doc/Pose.py

Modified: trunk/blender/source/blender/python/api2_2x/Pose.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Pose.c	2007-10-19 17:31:57 UTC (rev 12301)
+++ trunk/blender/source/blender/python/api2_2x/Pose.c	2007-10-20 11:28:58 UTC (rev 12302)
@@ -723,14 +723,41 @@
 //Gets the pose_mat
 static PyObject *PoseBone_getPoseMatrix(BPy_PoseBone *self, void *closure)
 {
+	printmatrix4("posemat GET", self->posechannel->pose_mat );
     return newMatrixObject((float*)self->posechannel->pose_mat, 4, 4, Py_WRAP);
 }
 //------------------------PoseBone.poseMatrix (setter)
 //Sets the pose_mat
-static int PoseBone_setPoseMatrix(BPy_PoseBone *self, PyObject *value, void *closure)
+static int PoseBone_setPoseMatrix(BPy_PoseBone *self, MatrixObject *value, void *closure)
 {
-	return EXPP_intError(PyExc_AttributeError, "%s%s%s",
-		sPoseBoneError, ".poseMatrix: ", "not able to set this property");
+	float loc_mat[4][4];
+	float delta_mat[4][4], quat[4]; /* rotation */
+	float size[4]; /* size only */
+	
+	if( !MatrixObject_Check( value ) )
+		return EXPP_ReturnIntError( PyExc_TypeError,
+									"expected matrix object as argument" );
+	
+	if( value->colSize != 4 || value->rowSize != 4 )
+		return EXPP_ReturnPyObjError( PyExc_AttributeError,
+			"matrix must be a 4x4 transformation matrix\n"
+			"for example as returned by object.matrixWorld" );
+
+	/* get bone-space cursor matrix and extract location */
+	armature_mat_pose_to_bone(self->posechannel, (float (*)[4]) *value->matrix, delta_mat);
+	
+	/* Visual Location */
+	VECCOPY(self->posechannel->loc, delta_mat[3]);
+
+	/* Visual Size */
+	Mat4ToSize(delta_mat, size);
+	VECCOPY(self->posechannel->size, size);
+	
+	/* Visual Rotation */
+	Mat4ToQuat(delta_mat, quat);
+	QUATCOPY(self->posechannel->quat, quat);
+	
+	return 0;
 }
 //------------------------PoseBone.constraints (getter)
 //Gets the constraints sequence

Modified: trunk/blender/source/blender/python/api2_2x/doc/Pose.py
===================================================================
--- trunk/blender/source/blender/python/api2_2x/doc/Pose.py	2007-10-19 17:31:57 UTC (rev 12301)
+++ trunk/blender/source/blender/python/api2_2x/doc/Pose.py	2007-10-20 11:28:58 UTC (rev 12302)
@@ -175,12 +175,14 @@
 	@type localMatrix: Matrix object
 	@ivar poseMatrix: The total transformation of this PoseBone including constraints.
 
-	(not settable).
-
 	This matrix is in armature space, for the current worldspace location of this pose bone, multiply
-	it with its objects worldspace matrix
+	it with its objects worldspace matrix.
 
 	eg. pose_bone.poseMatrix * object.matrixWorld
+	
+	Setting the poseMatrix only sets the loc/size/rot, before constraints are applied (similar to actions).
+	After setting pose matrix, run pose.update() to re-evaluate the pose and see the changes in the 3d view.
+	
 	@type poseMatrix: Matrix object
 	@type constraints: BPy_ConstraintSeq
 	@ivar constraints: a sequence of constraints for the object





More information about the Bf-blender-cvs mailing list