public CanonicalRepresentation.HAnimBones[] GetExportBones(CanonicalRepresentation.MASK_MODE maskMode, AvatarMask exportMask, AnimationClip clip) { CanonicalRepresentation.HAnimBones[] skeletonBones = this.ExportPose().parts; CanonicalRepresentation.HAnimBones[] animatedBones; if (ikDrivingAnimator == null && clip != null) { animatedBones = GetAnimatedCanonicalBones(clip); } else { animatedBones = ExportPose().parts; } if (maskMode == CanonicalRepresentation.MASK_MODE.ALL) { return(skeletonBones); } else if (maskMode == CanonicalRepresentation.MASK_MODE.ALL_ANIMATED) { return(animatedBones); // TODO: if we are IK rig, this should return all bones on this rig. } else if ((maskMode == CanonicalRepresentation.MASK_MODE.MASK_MAPPED_ALL || maskMode == CanonicalRepresentation.MASK_MODE.MASK_MAPPED_ANIMATED) && exportMask != null) { List <CanonicalRepresentation.HAnimBones> _boneUnion = new List <CanonicalRepresentation.HAnimBones>(); for (int i = 0; i < exportMask.transformCount; i++) { if (!exportMask.GetTransformActive(i)) { continue; } string boneName = exportMask.GetTransformPath(i).Split(new char[] { '/' }).Last(); if (CanonicalRepresentation.HAnimBoneNames.Contains(boneName)) { CanonicalRepresentation.HAnimBones canonicalBone = (CanonicalRepresentation.HAnimBones)System.Enum.Parse(typeof(CanonicalRepresentation.HAnimBones), boneName, false); if (maskMode == CanonicalRepresentation.MASK_MODE.MASK_MAPPED_ALL && skeletonBones.Contains(canonicalBone)) { _boneUnion.Add(canonicalBone); } if (maskMode == CanonicalRepresentation.MASK_MODE.MASK_MAPPED_ANIMATED && animatedBones.Contains(canonicalBone)) { _boneUnion.Add(canonicalBone); } } } return(_boneUnion.ToArray()); } return(skeletonBones); }
void OnGUI() { GUIStyle popStyle = new GUIStyle(EditorStyles.popup); popStyle.margin = new RectOffset(5, 5, 5, 5); GUILayout.Label("Output Paths", EditorStyles.boldLabel); if (GUILayout.Button("Set Human Root Path")) { asapHumanRootPath = EditorUtility.OpenFolderPanel("ASAP Humans Root Folder", asapHumanRootPath, ""); //sampleBMLPath = System.IO.Path.Combine(asapHumanRootPath, ""); gestureFilesPath = System.IO.Path.Combine(asapHumanRootPath, "procanimation"); restposeFilesPath = System.IO.Path.Combine(asapHumanRootPath, "restposes"); keyframeFilesPath = System.IO.Path.Combine(asapHumanRootPath, "keyframe"); } GUILayout.Label(ShortPath(asapHumanRootPath)); fileSuffix = EditorGUILayout.TextField("File Suffix: ", fileSuffix); EditorGUILayout.BeginHorizontal(); EditorGUILayout.BeginVertical(); GUILayout.Label("Pose/Animiation Source", EditorStyles.boldLabel); MotionExportSkeleton[] rigs = FindObjectsOfType <MotionExportSkeleton>(); string[] rigNames = rigs.Select(rig => rig.transform.name).ToArray(); if (rigNames.Length > 0) { if (selectedRig >= rigNames.Length) { selectedRig = rigNames.Length - 1; } if (selectedRig < 0) { selectedRig = 0; } int _selectedRig = EditorGUILayout.Popup(selectedRig, rigNames, popStyle); if (_selectedRig != selectedRig) { selectedRig = _selectedRig; selectedClip = 0; } currentRig = rigs[selectedRig]; } else { currentRig = null; } if (currentRig == null) { return; } Animator animator = currentRig.GetAnimator(); if (animator == null) { return; } //UnityEditor.Selection.objects = new UnityEngine.Object[] { currentRig }; EditorGUILayout.EndVertical(); EditorGUILayout.BeginVertical(); GUILayout.Label("Pose/Clip", EditorStyles.boldLabel); string assetPath = AssetDatabase.GetAssetPath(animator.runtimeAnimatorController); UnityEditor.Animations.AnimatorController controller = AssetDatabase.LoadAssetAtPath <UnityEditor.Animations.AnimatorController>(assetPath); if (controller == null) { return; } AnimationClip[] _c = controller.animationClips; List <string> clipNames = _c.Select(clip => clip.name).ToList(); clipNames.Insert(0, "Current Pose"); if (selectedClip >= clipNames.Count) { selectedClip = clipNames.Count - 1; } if (selectedClip < 0) { selectedClip = 0; } int _selectedClip = EditorGUILayout.Popup(selectedClip, clipNames.ToArray(), popStyle); selectedClip = _selectedClip; EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); if (selectedClip > 0) { GUILayout.Label("Length: " + _c[_selectedClip - 1].length); } GUILayout.Label("Avatar Mask", EditorStyles.boldLabel); EditorGUILayout.BeginHorizontal(); EditorGUILayout.BeginVertical(); currentAvatarMask = (AvatarMask)EditorGUILayout.ObjectField(currentAvatarMask, typeof(AvatarMask), true); maskMode = (CanonicalRepresentation.MASK_MODE)EditorGUILayout.EnumPopup("Mask Mode: ", maskMode); ignoreRootTranslation = EditorGUILayout.Toggle("Ignore Root Translation", ignoreRootTranslation); EditorGUILayout.EndVertical(); AnimationClip ac = null; if (selectedClip > 0) { ac = _c[selectedClip - 1]; } EditorGUILayout.EndHorizontal(); GUILayout.Label("Export:", EditorStyles.boldLabel); EditorGUILayout.BeginHorizontal(); EditorGUILayout.BeginVertical(); batchKeyframe = EditorGUILayout.Toggle("All Keyframe", batchKeyframe); batchProc = EditorGUILayout.Toggle("All ProcAnim", batchProc); EditorGUILayout.EndVertical(); EditorGUILayout.BeginVertical(); bool _batch = GUILayout.Button("Batch Export"); EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); if (_batch) { foreach (AnimationClip _ac in _c) { HandleExport(_ac, true); } } else { HandleExport(ac, false); } }