/// <summary>
/// Export an AnimationCurve.
/// NOTE: This is not used for rotations, because we need to convert from
/// quaternion to euler and various other stuff.
/// </summary>
protected void ExportAnimCurve(UnityEngine.Object unityObj,
AnimationCurve unityAnimCurve,
string unityPropertyName,
FbxScene fbxScene,
FbxAnimLayer fbxAnimLayer)
{
FbxPropertyChannelPair fbxPropertyChannelPair;
if (!FbxPropertyChannelPair.TryGetValue(unityPropertyName, out fbxPropertyChannelPair))
{
Debug.LogWarning(string.Format("no mapping from Unity '{0}' to fbx property", unityPropertyName));
return;
}
GameObject unityGo = GetGameObject(unityObj);
if (unityGo == null)
{
Debug.LogError(string.Format("cannot find gameobject for {0}", unityObj.ToString()));
return;
}
FbxNode fbxNode;
if (!MapUnityObjectToFbxNode.TryGetValue(unityGo, out fbxNode))
{
Debug.LogError(string.Format("no fbx node for {0}", unityGo.ToString()));
return;
}
// map unity property name to fbx property
var fbxProperty = fbxNode.FindProperty(fbxPropertyChannelPair.Property, false);
if (!fbxProperty.IsValid())
{
Debug.LogError(string.Format("no fbx property {0} found on {1} ", fbxPropertyChannelPair.Property, fbxNode.GetName()));
return;
}
if (Verbose)
{
Debug.Log("Exporting animation for " + unityObj.ToString() + " (" + unityPropertyName + ")");
}
// Create the AnimCurve on the channel
FbxAnimCurve fbxAnimCurve = fbxProperty.GetCurve(fbxAnimLayer, fbxPropertyChannelPair.Channel, true);
// copy Unity AnimCurve to FBX AnimCurve.
fbxAnimCurve.KeyModifyBegin();
for (int keyIndex = 0, n = unityAnimCurve.length; keyIndex < n; ++keyIndex)
{
var key = unityAnimCurve [keyIndex];
var fbxTime = FbxTime.FromSecondDouble(key.time);
fbxAnimCurve.KeyAdd(fbxTime);
fbxAnimCurve.KeySet(keyIndex, fbxTime, key.value);
}
fbxAnimCurve.KeyModifyEnd();
}