Extract bone local rotation issue

Hello, I have an issue with local rotation and scripting which I have not been able to solve.

I'm trying to extract the local position and rotation of all the bones of a figure after posing it, using a script.

Here I have posed the Genesis 8 Female, by only rotating the arm to the front by 90 degrees.

image

 

With this script I try to read the local rotation and rotation order, in order to compute the euler values:

 

var oNode = Scene.getPrimarySelection();

var oSkeleton = oNode.getSkeleton();

var bones = oSkeleton.getAllBones();

var n = bones.length;

for ( var i = 0; i < n; i++ )

{

     bone = bones[i];

     if ( bone.name == 'lShldrBend' )

     {

          var rot = bone.getLocalRot();

          debug ( rot );

          var rotOrder = bone.getRotationOrder();

          var rotEuler = rot.getValue(rotOrder.firstAxis, rotOrder.secondAxis, rotOrder.thirdAxis);

          var rotEulerD = rotEuler.multiply( DzVec3 (57.3248407643, 57.3248407643, 57.3248407643 ) );

          debug( rotEulerD );

     }

}

 

This is the script output:

Executing Script...

[0.530114,0.467706,0.0151514,0.707107]

[-90.0098,-42.6703,40.1898]

Result: 

Script executed in 0 secs 4 msecs.

 

The angles I'm expecting are [-90, 0, 0], but I get [-90.0098,-42.6703,40.1898]. Is there something that I'm missing?

genesis8_posed.png
404K

Comments

  • MikeDMikeD Posts: 299

    Hey Return0,

     

    The problem with the above script is what DS consider to be "Local" rotations....

     

    Modify a little the above script like the one I am posting....

     

    (function (){	//-------------------------------------------------------------	//function for returning the Radial angle	function radialAngle (){		var pi = Math.PI;		return 180/pi;	};		//--------------------------------------------------------------	//Main	var oNode = Scene.getPrimarySelection();	var oSkeleton = oNode.getSkeleton();		var bones = oSkeleton.getAllBones();		var n = bones.length;		//take the radial angle	var nAngle = radialAngle();		for ( var i = 0; i &lt; n; i++ )		{		     bone = bones[i];		     if ( bone.name == 'lShldrBend' )		     {		          var rot = bone.getLocalRot();		          //debug ( rot );		          var rotOrder = bone.getRotationOrder();		          var rotEuler = rot.getValue(rotOrder.firstAxis, rotOrder.secondAxis, rotOrder.thirdAxis);	          	          //get the world rotations	          var oWorldNodeRotations = bone.getWSRot();	          	          //make them Euler vector	          var oWorldRotationEuler = oWorldNodeRotations.getValue(rotOrder.firstAxis, rotOrder.secondAxis, rotOrder.thirdAxis);	          	          debug("oWorldRotationEuler", oWorldRotationEuler.multiply( DzVec3 (nAngle, nAngle, nAngle ) ));			  			  	          var rotEulerD = rotEuler.multiply( DzVec3 (nAngle, nAngle, nAngle ) );		          debug( "rotEulerD" , rotEulerD );		     }		}	})();

     

    You will notice that the "oWorldRotationEuler" and the local "rotEuler" values are the same [-89.9642,-42.6487,40.1694] ..... wink

    Also notice that there are values in the y and z axis, which means that they aren't  0.

     

    It seems that it is not right at a first glance....

     

    Now select the Genesis figure and make a group, with the figure parented to thit group. Change the Y rotation of the group by 90 degrees.

     

    Select again the Figure in the group (or the script will throw an error) and execute it again.... the world rotations are changed but the local rotations remain the same ....

     

    It seems that the "bone.getLocalRot()" method takes the "local' rotation values compared to the figure rotation values, and not the values in the properties as they are apeared to be in the Parameters tab  ....

    At the first execution of the script the figure has no rotations so the Local and World rotations are the same.

    At the second execution the World rotations are changed as we rotated the group but the Local rotations are still the same as the arm is rotating with the figure and the relative rotations have not changed. Nevertheless if you want to take the 0,90,0 (X, Y, Z) try to take the properties values from the arm with the "node.getXRotControl ()" (the coresponding for Y and Z) and then use the getValue () method.:

     

    var nLocalX = bone.getXRotControl().getValue();var nLocalY = bone.getYRotControl().getValue();var nLocalZ = bone.getZRotControl().getValue();	          debug(nLocalX, nLocalY, nLocalZ);

     

  • Hello Mike, thank you very much for the detailed reply. Indeed the control values were the ones I was looking for, so that finally fixed it for me!

Sign In or Register to comment.