/// <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(); }
/// <summary> /// Map a Unity property name to the corresponding FBX property and /// channel names. /// </summary> public static bool TryGetValue(string unityPropertyName, out FbxPropertyChannelPair prop) { System.StringComparison ct = System.StringComparison.CurrentCulture; if (unityPropertyName.StartsWith("m_LocalPosition.x", ct) || unityPropertyName.EndsWith("T.x", ct)) { prop = new FbxPropertyChannelPair("Lcl Translation", Globals.FBXSDK_CURVENODE_COMPONENT_X); return(true); } if (unityPropertyName.StartsWith("m_LocalPosition.y", ct) || unityPropertyName.EndsWith("T.y", ct)) { prop = new FbxPropertyChannelPair("Lcl Translation", Globals.FBXSDK_CURVENODE_COMPONENT_Y); return(true); } if (unityPropertyName.StartsWith("m_LocalPosition.z", ct) || unityPropertyName.EndsWith("T.z", ct)) { prop = new FbxPropertyChannelPair("Lcl Translation", Globals.FBXSDK_CURVENODE_COMPONENT_Z); return(true); } prop = new FbxPropertyChannelPair(); return(false); }