Open
Description
I really didn't want to manually go through all my animations and process them one-by-one and then hook them up to new files. So I made an AssetPreprocessor
that will do this on import.
The way it works is you add an Asset Label of CloseCCJaw
to any models that you want to fix the jaw on. Then reimport them.
Here's the code if you would like to clean it up and include it in the package.
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
public class JawCloserImporter : AssetPostprocessor {
void OnPostprocessAnimation(GameObject root, AnimationClip clip) {
if (AssetDatabase.GetLabels(assetImporter).Contains("CloseCCJaw")) {
FixJaw(clip);
}
}
public uint GetVersion() {
return 2;
}
const string jawClose = "Jaw Close";
static void FixJaw(AnimationClip inputClip) {
var found = false;
var curveBindings = AnimationUtility.GetCurveBindings(inputClip);
var targetBinding = new EditorCurveBinding();
var jawCurve = new AnimationCurve();
Keyframe[] jawKeys;
foreach (var binding in curveBindings) {
if (binding.propertyName.Equals(jawClose)) {
targetBinding = binding;
found = true;
}
}
if (found) {
jawCurve = AnimationUtility.GetEditorCurve(inputClip, targetBinding);
}
else {
targetBinding = new EditorCurveBinding() { propertyName = jawClose, type = typeof(Animator) };
jawKeys = new Keyframe[] {
new Keyframe( 0f, 0f ),
new Keyframe( inputClip.length, 0f )
};
jawCurve.keys = jawKeys;
}
jawKeys = jawCurve.keys;
for (int i = 0; i < jawKeys.Length; i++) {
jawKeys[i].value = 1;
}
jawCurve.keys = jawKeys;
AnimationUtility.SetEditorCurve(inputClip, targetBinding, jawCurve);
}
}
Metadata
Assignees
Labels
No labels
Activity