Repository navigation
Expand file tree
/
Copy pathAnimationNormalizerWindow.cs
More file actions
67 lines (59 loc) · 2.67 KB
/
Copy pathAnimationNormalizerWindow.cs
File metadata and controls
67 lines (59 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#if UNITY_EDITOR
using System;
using UnityEditor;
using UnityEngine;
/// <summary>Small editor window in front of <see cref="AnimationNormalizer"/>.</summary>
public class AnimationNormalizerWindow : EditorWindow
{
[SerializeField] private GameObject sourceModel;
[SerializeField] private GameObject normalizedModel;
[SerializeField] private AnimationClip clip;
[SerializeField] private float sampleRate;
[SerializeField] private bool enforceTPose = true;
[SerializeField] private bool keepOtherCurves = true;
[MenuItem("Tools/Animation Normalizer")]
private static void Open()
{
GetWindow<AnimationNormalizerWindow>("Animation Normalizer");
}
private void OnGUI()
{
EditorGUILayout.HelpBox(
"Converts the non-humanoid bone animation (ears, tails, hair...) of an original avatar " +
"so it plays correctly on its normalized (zero rest rotation) copy.",
MessageType.Info);
sourceModel = (GameObject)EditorGUILayout.ObjectField("Original Model", sourceModel, typeof(GameObject), true);
normalizedModel = (GameObject)EditorGUILayout.ObjectField("Normalized Model", normalizedModel, typeof(GameObject), true);
clip = (AnimationClip)EditorGUILayout.ObjectField("Animation", clip, typeof(AnimationClip), false);
EditorGUILayout.Space();
sampleRate = Mathf.Max(0f, EditorGUILayout.FloatField(new GUIContent("Sample Rate", "0 = use the clip's frame rate"), sampleRate));
enforceTPose = EditorGUILayout.Toggle(new GUIContent("Enforce T-Pose", "Read rest values with both rigs in the humanoid T-pose"), enforceTPose);
keepOtherCurves = EditorGUILayout.Toggle(new GUIContent("Keep Other Curves", "Copy muscle, blendshape and event data into the new clip"), keepOtherCurves);
EditorGUILayout.Space();
using (new EditorGUI.DisabledScope(sourceModel == null || normalizedModel == null || clip == null))
{
if (GUILayout.Button("Create Normalized Animation", GUILayout.Height(32)))
Run();
}
}
private void Run()
{
try
{
AnimationClip result = AnimationNormalizer.Bake(sourceModel, normalizedModel, clip, new AnimationNormalizer.Options
{
sampleRate = sampleRate,
enforceTPose = enforceTPose,
keepOtherCurves = keepOtherCurves,
});
Selection.activeObject = result;
EditorGUIUtility.PingObject(result);
}
catch (Exception e)
{
Debug.LogException(e);
EditorUtility.DisplayDialog("Animation Normalizer", e.Message, "OK");
}
}
}
#endif