AnimationClip压缩-动画文件压缩
动画压缩方法
一、常用方法
1. Rig->Animation Type:改为Generic
2. Animations->Anim.Compression:Optimal
二、高级方法
1. 去掉AnimationClip中的无效曲线:例如ScaleCurve
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
public class RemoveCurve : AssetPostprocessor
{
void OnPostprocessModel(GameObject g)
{
Apply(g);
}
void Apply(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)
{
foreach (EditorCurveBinding theCurveBinding in AnimationUtility.GetCurveBindings(theAnimation))
{
string name = theCurveBinding.propertyName.ToLower();
if (name.Contains("scale"))
{
AnimationUtility.SetEditorCurve(theAnimation, theCurveBinding, null);
}
}
}
}
}
2. 压缩AnimationClip文件float的精度
public static bool CompressAnimationClip(Object o)
{
string animationPath = AssetDatabase.GetAssetPath(o);
try
{
//AnimationClip clip = GameObject.Instantiate(o) as AnimationClip;
AnimationClip clip = o as AnimationClip;
AnimationClipCurveData[] curves = null;
curves = AnimationUtility.GetAllCurves(clip);
Keyframe key;
Keyframe[] keyFrames;
for (int ii = 0; ii < curves.Length; ++ii)
{
AnimationClipCurveData curveDate = curves[ii];
if (curveDate.curve == null || curveDate.curve.keys == null)
{
//Debug.LogWarning(string.Format("AnimationClipCurveData {0} don't have curve; Animation name {1} ", curveDate, animationPath));
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;
clip.SetCurve(curveDate.path, curveDate.type, curveDate.propertyName, curveDate.curve);
}
//AssetDatabase.CreateAsset(clip, animationPath);
Debug.Log(string.Format(" CompressAnimationClip {0} Success !!!", animationPath));
return true;
}
catch(Exception e)
{
Debug.LogError(string.Format("CompressAnimationClip Failed !!! animationPath : {0} error: {1}", animationPath, e));
return false;
}
}
3. 简化骨骼名字
unity的动画数据存储的时候按每个骨骼节点的轨道拆分存储的,每个骨骼存储的是从根节点到这个骨骼节点的hierarchy路径,字符串的,骨骼多了之后这部分字符串不少。如果把所有骨骼名字都简化,这里可以省不少内存
————————————————
版权声明:本文为CSDN博主「石圣」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/alexander_xfl/article/details/66975570
最新文章
- 自定义圆饼(利用贝塞尔曲线和CGContext类完成)
- 使用OCR来帮助LR实现认证码识别
- JDBC 基本操作
- thinkphp分页搜索条件带中文参数
- 12 个 Web 设计师必备的 Bootstrap 工具
- ios取证
- ecshop添加商品选择品牌时如何按拼音排序
- 转:Linux网络IO并行化技术概览
- SHOI2008小约翰的游戏John
- 多个UITableView横向切换的简单实现(有点类似网易新闻)
- centos 下mysql操作
- 监控父元素里面子元素内容变化 DOMSubtreeModified
- 利用百度地图API和群蚁算法,对TSP问题进行模拟与求解
- Java中用正则表达式找出数字
- Angular记录(5)
- git中如何撤销部分修改?
- Android获取通讯录并上传(包含通讯录加密)
- 【BZOJ4919】[Lydsy六月月赛]大根堆
- Gym 101149L Right Build
- Redis 安装配制
热门文章
- metrics-server 安装问题解决
- HDU 1253 胜利大逃亡 题解
- 在windows下安装Superset
- 微信小程序中的事件
- 达信:深度解读COSO新版企业风险管理框架(ERM)
- token的验证过程
- tomcat Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986
- Android Studio 之 GridView
- 可能是全网最好的MySQL重要知识点 | 面试必备
- Windows彻底卸载VMWare虚拟机详细步骤