void Register() { if (bmlRequests == null) { bmlRequests = FindObjectOfType <BMLRequests>(); } rigs = FindObjectsOfType <ManualAnimationRig>(); List <string> names = new List <string>(); for (int r = 0; r < rigs.Length; r++) { names.Add(rigs[r].name); } if (rigs.Length >= selectedRig) { selectedRig = 0; } labels = names.ToArray(); if (rigs.Length > 0) { if (animationRig == null) { animationRig = rigs[selectedRig]; } Populate(); } }
// Export animation... current clip? public static string ExportAnimation(ManualAnimationRig animationRig, AnimationClip clip, float frameRate, ManualAnimationRig.ExportMode mode) { if (animationRig == null) { return(null); } Dictionary <string, bool> animatedBones = new Dictionary <string, bool>(); Dictionary <string, float> syncPoints = new Dictionary <string, float>(); foreach (EditorCurveBinding binding in AnimationUtility.GetCurveBindings(clip)) { //AnimationCurve curve = AnimationUtility.GetEditorCurve (clip, binding); string[] pathElems = binding.path.Split('/'); string hAnimName = pathElems[pathElems.Length - 1]; if (binding.propertyName.StartsWith("m_LocalRotation")) { if (!animatedBones.ContainsKey(hAnimName)) { animatedBones.Add(hAnimName, false); } } if (binding.propertyName.StartsWith("m_LocalPosition")) { if (!animatedBones.ContainsKey(hAnimName)) { animatedBones.Add(hAnimName, true); } else { animatedBones[hAnimName] = true; } } } foreach (AnimationEvent ae in AnimationUtility.GetAnimationEvents(clip)) { if (ae.functionName.StartsWith("Sync_")) { string syncType = ae.functionName.Substring(5); if (syncType == "custom") { syncType = ae.stringParameter; } syncPoints.Add(syncType, ae.time / clip.length); Debug.Log(ae.functionName + " " + syncType + " " + ae.time); } } string parts = ""; List <Transform> partReferences = new List <Transform>(); // Get a nice ordered list of the bones: foreach (BoneSpec boneSpec in animationRig.controlledAgent.agentSpec.bones) { foreach (KeyValuePair <string, bool> animatedBone in animatedBones) { if (animatedBone.Key == boneSpec.hAnimName) { parts += boneSpec.hAnimName + " "; Transform boneObject = animationRig.FindDeepChild(animationRig.vjointRoot.parent, boneSpec.hAnimName); partReferences.Add(boneObject); break; } } } parts = parts.Trim(); string encoding = "R"; string rotationEncoding = "quaternions"; // if root has translation: we use T1R if (animatedBones.ContainsKey("HumanoidRoot") && animatedBones["HumanoidRoot"]) { encoding = "T1R"; // Could also use "TR" if there is a non-root bone with translation... // but we don't support those non-root translations in animations atm anyway... } List <float> times = new List <float>(); List <float[]> frames = new List <float[]>(); float delta = 1 / frameRate; for (int frame = 0; frame < Math.Max(1, clip.length * frameRate); frame++) { float t = delta * frame; clip.SampleAnimation(animationRig.vjointRoot.parent.gameObject, t); //yield return new WaitForSeconds(delta); times.Add(t); List <float> elems = new List <float>(); foreach (Transform partReference in partReferences) { if (encoding == "TR" || (encoding == "T1R" && partReference.name == "HumanoidRoot")) { elems.AddRange(ExtractAsapVectorPosition(partReference)); elems.AddRange(ExtractAsapQuaternionRotation(partReference)); } else if (encoding == "R" || encoding == "T1R") { elems.AddRange(ExtractAsapQuaternionRotation(partReference)); } } frames.Add(elems.ToArray()); } Debug.Log("Exporting gesture " + clip.name + ". Duration: " + clip.length + " (" + frames.Count + " frames total)"); return(WriteXML(animationRig.controlledAgent.id, clip, parts, rotationEncoding, encoding, times, frames, syncPoints, mode)); }