Search Unity

Question AnimationUtility.GetEditorCurve()

Discussion in 'Animation' started by QuebecDev, Dec 29, 2021.

  1. QuebecDev

    QuebecDev

    Joined:
    May 9, 2020
    Posts:
    37
    Hi,

    When I open my character prefab and apply manually all those rotations (see screenshot below) my character takes the desired pose.

    But, when I read the rotation from AnimationUtility.GetCurveBindings(clip) (see the code below) and convert the "quaternion.eulerAngles" and debug.log the result...

    Root: Rotation = (10.8, 17.4, 2.4) :)
    Hips: Roation = (0.0, 270.0, 278.6) :(
    Spine: Rotation = (355.4, 178.7, 207.0) :(
    etc

    Why my root is the only one with the perfect euler? What am I doing wrong?

    upload_2021-12-29_15-10-58.png


    Code (CSharp):
    1.             var bindings = AnimationUtility.GetCurveBindings(clip);
    2.  
    3.             for (int b = 0; b < bindings.Length; b++)
    4.             {
    5.                 var binding = bindings[b];
    6.  
    7.                 var keys = AnimationUtility.GetEditorCurve(clip, binding).keys;
    8.                 var property = GetPropetyValue(binding.propertyName);
    9.  
    10.                 // Keys
    11.                 for (int k = 0; k < keys.Length; k++)
    12.                 {
    13.                     Keyframe keyFrame = keys[k];
    14.  
    15.                     // Create key | MyKeys
    16.                     AnimationKey key = new AnimationKey();
    17.  
    18.                     // Set key propety
    19.                     if (property.type == 0) key.position = property.value.xyz * keyFrame.value;
    20.                     else if (property.type == 1) key.rotation = property.value * keyFrame.value;
    21.                     else if (property.type == 2) key.scale = property.value.xyz * keyFrame.value;
    22.                     else continue;
    23.                 }
    24.             }
     
  2. Silvere69

    Silvere69

    Joined:
    Jul 12, 2016
    Posts:
    39
    i found the perfect discussion but no solution :( nobody?

    (property and getpropetyvalue is a custom script right?)
     
    Last edited: Oct 27, 2022