
void OnPostprocessModel(GameObject g) {
List<AnimationClip> animationClipList = new List<AnimationClip>(AnimationUtility.GetAnimationClips(g));
if (animationClipList.Count == 0) {
AnimationClip[] objectList = UnityEngine.Object.FindObjectsOfType (typeof(AnimationClip)) as AnimationClip[];
animationClipList.AddRange(objectList);
}
foreach (AnimationClip theAnimation in animationClipList)
{
try
{
//去除scale曲线
foreach (EditorCurveBinding theCurveBinding in AnimationUtility.GetCurveBindings(theAnimation))
{
string name = theCurveBinding.propertyName.ToLower();
if (name.Contains("scale"))
{
AnimationUtility.SetEditorCurve(theAnimation, theCurveBinding, null);
}
}
//浮点数精度压缩到f3
AnimationClipCurveData[] curves = null;
curves = AnimationUtility.GetAllCurves(theAnimation);
Keyframe key;
Keyframe[] keyFrames;
for (int ii = 0; ii < curves.Length; ++ii)
{
AnimationClipCurveData curveDate = curves[ii];
if (curveDate.curve == null || curveDate.curve.keys == null)
{
continue;
}
keyFrames = curveDate.curve.keys;
for (int i = 0; i < keyFrames.Length; i++)
{
key = keyFrames[i];
key.value = float.Parse(key.value.ToString("f3"));
key.inTangent = float.Parse(key.inTangent.ToString("f3"));
key.outTangent = float.Parse(key.outTangent.ToString("f3"));
keyFrames[i] = key;
}
curveDate.curve.keys = keyFrames;
theAnimation.SetCurve(curveDate.path, curveDate.type, curveDate.propertyName, curveDate.curve);
}
}
catch (System.Exception e)
{
Debug.LogError(string.Format("CompressAnimationClip Failed !!! animationPath : {0} error: {1}", assetPath, e));
}
}
}unity动画无论不压缩,重不重采样都会和ddc软件在表现上有所差异
| 操作 | 描述 |
|---|---|
| Off | 不压缩,质量最高,内存消耗最大 |
| Keyframe Reduction | 减少冗余关键帧,减小动画文件大小和内存大小 |
| Optimal | 仅适用于Generic和Humanoid动画类型,Unity自动决定如何进行压缩(紧缩式和流式数据压缩) |
导入用户自定义属性,一般对应DCC工具中的extraUserProperties字段中定义的数据
| 数据项 | 信息 |
|---|---|
| Curves Pos | 位置曲线 |
| Quaternion | 四元数曲线 Resample Curves开启会有 |
| Euler | 欧拉曲线 |
| Scale | 缩放曲线 |
| Muscles | 肌肉曲线 Humanoid类型下会有 |
| Generic | 一般属性的动画曲线,如颜色,材质等 |
| PPtr | 精灵动画曲线,一般2D系统下会有 |
| Curves Total | 曲线总数,数量越大性能越差 |
| Constant | 优化为常数的曲线,error设置越大常数曲线越多,常数曲线一般不参与采样,越大说明优化程度越大 |
| Dense | 使用了密集数据存储 (线性插值后的离散值) |
| Stream | 使用了流式数据存储(插值的时间和切线数据) |