FBX 6.1 ASCII export - Formula to Rotate joint before import to unity

Hello,

I have a question about the FBX 6.1 ASCII export of a humanoid model.
I am using blender vers. 2.77 and import the fbx file into unity / unity3D.
I would like to manipulate the exported fbx file afterwards and rotate one single joint - the foot joint (ankle_joint_L) - first by changing the x,y and z values for rotation manually and later by script.

Inside the exported fbx-file there are the following sections:


			One section with the Lcl Translation, Rotation and Scaling:


			...
				Model: "Model::ankle_joint_L", "Limb" {
					Version: 232
					Properties60:  {
						Property: "QuaternionInterpolate", "bool", "",0
						Property: "Visibility", "Visibility", "A+",1
						Property: "Lcl Translation", "Lcl Translation", "A+",0.438361942768097,0.000000032580047,0.000000003539899
						Property: "Lcl Rotation", "Lcl Rotation", "A+",-0.000087242375938,65.026167125041809,-0.000069140807423
						Property: "Lcl Scaling", "Lcl Scaling", "A+",0.999999940395355,1.000000000000000,0.999999940395355
						Property: "RotationOffset", "Vector3D", "",0,0,0
						Property: "RotationPivot", "Vector3D", "",0,0,0
						Property: "ScalingOffset", "Vector3D", "",0,0,0			
			...


			One section with a fbx-matrix with 4x4 values:
			...
				Pose: "Pose::BIND_POSES", "BindPose" {
					Type: "BindPose"
					Version: 100
					Properties60:  {
					}
					NbPoseNodes: 198
					...
					PoseNode:  {
						Node: "Model::ankle_joint_L"
						Matrix: 0.000000134451199,-0.579614102840424,0.814895033836365,0.000000000000000,-1.000000000000000,0.000000030697251,0.000000186832239,0.000000000000000,-0.000000133302478,-0.814891040325165,-0.579617083072662,0.000000000000000,0.112832039594650,0.090652249753475,-0.025477036833763,1.000000000000000
					}
			...	


			And a section with the animation data:


			....
				Take: "test_Take" {
					FileName: "test_Take.tak"
					LocalTime: -1924423249,44261734750
					ReferenceTime: -1924423249,44261734750


					;Models animation
					;----------------------------------------------------


			...				
			Model: "Model::ankle_joint_L" {
						Version: 1.1
						Channel: "Transform" {
							Channel: "T" {
								Channel: "X" {
									Default: 0.438361942768097
									KeyVer: 4005
									KeyCount: 1
									Key: 
										1924423250,0.438361942768097,L
									Color: 1,0,0
								}
								Channel: "Y" {
									Default: 0.000000032580047
									KeyVer: 4005
									KeyCount: 1
									Key: 
										1924423250,0.000000032580047,L
									Color: 0,1,0
								}
								Channel: "Z" {
									Default: 0.000000003539899
									KeyVer: 4005
									KeyCount: 1
									Key: 
										1924423250,0.000000003539899,L
									Color: 0,0,1
								}
								LayerType: 1
							}
							Channel: "R" {
								Channel: "X" {
									Default: -0.000087242323828
									KeyVer: 4005
									KeyCount: 25
									Key: 
										0,-0.000087242323828,L,
										1924423250,-0.353714926505663,L,
										3848846500,-1.422824987255344,L,
										5773269750,-3.213950423143348,L,
										7697693000,-5.720650979432171,L,
										9622116250,-8.914925121680621,L,
										11546539500,-12.737680401067362,L,
										13470962750,-17.091411171435546,L,
										15395386000,-21.839283984274271,L,
										17319809250,-26.813954936050237,L,
										19244232500,-31.835795174234246,L,
										21168655750,-36.735472356470872,L,
										23093079000,-41.373194708564959,L,
										25017502250,-45.649111695040240,L,
										26941925500,-49.503790424833930,L,
										28866348750,-52.911713311206896,L,
										30790772000,-55.871985599377865,L,
										32715195250,-58.399162422468123,L,
										34639618500,-60.516036121737962,L,
										36564041750,-62.248424812250001,L,
										38488465000,-63.622057816607629,L,
										40412888250,-64.660458306312350,L,
										42337311500,-65.383987075279933,L,
										44261734750,-65.809302954896012,L,
										46186158000,-65.948973493233396,L
									Color: 1,0,0
								}
								Channel: "Y" {
									Default: 65.026160294852644
									KeyVer: 4005
									KeyCount: 25
									Key: 
										0,65.026160294852644,L,
										1924423250,65.025777804259121,L,
										3848846500,65.019978973653792,L,
										5773269750,64.994597990698054,L,
										7697693000,64.925975080107037,L,
										9622116250,64.781885409376656,L,
										11546539500,64.523984296506512,L,
										13470962750,64.112007776339453,L,
										15395386000,63.509837808544482,L,
										17319809250,62.692291485651808,L,
										19244232500,61.651076958009050,L,
										21168655750,60.398065094393672,L,
										23093079000,58.964838689527767,L,
										25017502250,57.398806086440324,L,
										26941925500,55.757252081700159,L,
										28866348750,54.100856075893574,L,
										30790772000,52.488029846802441,L,
										32715195250,50.970880907604709,L,
										34639618500,49.592845846327009,L,
										36564041750,48.387911684279281,L,
										38488465000,47.380807121351523,L,
										40412888250,46.588088536091810,L,
										42337311500,46.019369419756927,L,
										44261734750,45.678682999051766,L,
										46186158000,45.565769726787863,L
									Color: 0,1,0
								}
								Channel: "Z" {
									Default: -0.000069140807423
									KeyVer: 4005
									KeyCount: 25
									Key: 
										0,-0.000069140807423,L,
										1924423250,-0.293096570735064,L,
										3848846500,-1.178960660181499,L,
										5773269750,-2.662748821038822,L,
										7697693000,-4.737849937118571,L,
										9622116250,-7.377809831991677,L,
										11546539500,-10.527275798850793,L,
										13470962750,-14.095164276906166,L,
										15395386000,-17.954132365498616,L,
										17319809250,-21.949707652585708,L,
										19244232500,-25.918580315112678,L,
										21168655750,-29.710892587595065,L,
										23093079000,-33.209001291768750,L,
										25017502250,-36.336975214630804,L,
										26941925500,-39.059997466887140,L,
										28866348750,-41.376749822027946,L,
										30790772000,-43.308928375951737,L,
										32715195250,-44.891264640587977,L,
										34639618500,-46.163616184838219,L,
										36564041750,-47.165471747388835,L,
										38488465000,-47.932758123274041,L,
										40412888250,-48.495951616570387,L,
										42337311500,-48.879439417709378,L,
										44261734750,-49.101352263842770,L,
										46186158000,-49.173642986018081,L
									Color: 0,0,1
								}
								LayerType: 2
							}
			.....

The blender exported fbx file imports to other applications and the animation is working well in unity.
In this case the models left foot (ankle_joint_L) was animated and rotated to the left in pose mode with r-key followed by z-key around the globals z-axis.
Coordinate system in blender: global z-up, y forward/backward, x left/right, fbx-export-option presettings -z forward, y up.
The foot bone (ankle_joint_L) is inclined downwards and when selecting the local axes in pose mode it differs from the global axes of course (the joints local y-axis is aligned
with a line pointing from the ankle downwards to the toes).
When rotating the foot in blender in pose mode, the foot becomes rotated around the globals z-axis and not around the joints local axis, so that the foot is always on the ground.
That is what one would expect.

Now i would like to do this global rotation manually.

One key/keyframe looks like this:
Key:
1924423250,-0.353714926505663,L,

The first number is the keyframes time value, these are multiples of the value defined at LocalTime and ReferenceTime (each with start and end time):

LocalTime: -1924423249,44261734750
ReferenceTime: -1924423249,44261734750

The second number is the x,y or z value for translation (Channel: “T” {), rotation (Channel: “R” {) or scale (Channel: “S” { - scale is not shown here).

What i would like to know is:

With which formula can i calculate the x,y and z rotation values when i want to turn the joint through an angle of 30° around the globals z-axis for example.

And how to do the rotation interpolation ? I think, that the y-axis inside the exported fbx file is the z-axis from blender after export with the settings noted above (-z forward, y up). Adding one numerical value to the keyframes y-value only results in a rotation around the joints local axis. But i need a rotation around the globals axis, so all three values (x,y and z) have to be calculated - but how.

I am hoping for an answer like: “Take the values from the Lcl Rotation and multiply it with the sin or cos of your angle…or use the fbx matrix in the PoseNode…”
Also information about the meaning of the fbx matrix and the Lcl Rotation would be helpful for me.

Greetings
testuser2

i am trying making something like you,can you share some code how to manipulate FBX ascii files.