文章目录
将 .fbx 放到 Assets
- 将 .fbx 放到 Assets
- 网格信息
- face
- body
- hair
- weapon
- skin
- 压缩选
- Animation->Anim.Compression : Optimal
- 打包 AB 大小
- Model->Mesh.Compression : Optimal
- 打包 AB 大小
- AnimationClip 精度压缩
- AnimationClip 丢弃不必要的变化曲线
- CSharp 脚本 - ModelPreprocessor.cs
- 打包 AB 大小
- 三次优化
- 测试打包 AB 资源的 CSharp 脚本 : BuildFbxToABEditor.cs
- 另,附送一个坑点
- References
375 顶点,638 面
body6529 顶点,9381 面
hair2234 顶点,3162 面
weapon176 顶点,132 面
skin1053 顶顶啊,1518 面
压缩选- fbx 的 Animation->Anim.Compression : Off
- fbx 的 Model->Mesh Compression : Off
- fbx AnimationClip 的 keyframe 精度
将 Anim.Compression 由 Off 调整为:Optimal Rotation/Position/Scale Error 的各个容差都使用默认值:0.5
打包 AB 大小单单一个:Anim.Compression : Off 到 Optimal, Errors : 0.5 然后压缩大小从:6.54 mb -> 1.64 mb
Model->Mesh.Compression : Optimal将 Mesh.Compression 由 Off 调整为:High
打包 AB 大小单单一个:Mesh Compression : Off 到 High 然后压缩大小从:1.64 mb -> 1.42 mb
AnimationClip 精度压缩其实只保留了 2~3 位精度,原来的精度有:7位小数,我们将其压缩到 f2 : 2两个精度
可以看到调整变换:0.7071068 -> 071
AnimationClip 丢弃不必要的变化曲线一般我们的动画中都是 位移、旋转比较多,缩放比较少,所以一般情况下,确定没使用到缩放的,可以直接删掉
public static void CompressAnimationClip(AnimationClip clip)
{
var editorCurves = AnimationUtility.GetCurveBindings(clip);
if (editorCurves != null)
{
foreach (EditorCurveBinding editorCurve in editorCurves)
{
string name = editorCurve.propertyName.ToLower();
if (name.Contains("scale"))
{
AnimationUtility.SetEditorCurve(clip, editorCurve, null);
}
}
}
...
}
CSharp 脚本 - ModelPreprocessor.cs
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public class ModelPreprocessor : AssetPostprocessor
{
public void OnPreprocessModel()
{
//Debug.Log("ModelPreprocessor.OnPreprocessModel");
ModelImporter modelImporter = (ModelImporter)assetImporter;
modelImporter.animationCompression = ModelImporterAnimationCompression.Optimal;
modelImporter.meshCompression = ModelImporterMeshCompression.High;
}
public void OnPostprocessAnimation(GameObject go, AnimationClip clip)
{
try
{
CompressAnimationClip(clip);
}
catch (System.Exception e)
{
Debug.LogError("CompressAnimationClip Failed !!! animationPath :" + assetPath + "error: " + e);
}
}
public static void CompressAnimationClip(AnimationClip clip)
{
var editorCurves = AnimationUtility.GetCurveBindings(clip);
if (editorCurves != null)
{
foreach (EditorCurveBinding editorCurve in editorCurves)
{
string name = editorCurve.propertyName.ToLower();
if (name.Contains("scale"))
{
AnimationUtility.SetEditorCurve(clip, editorCurve, null);
}
}
}
string format = "f4";
AnimationClipCurveData[] curves = AnimationUtility.GetAllCurves(clip);
for (int ii = 0; ii 1.64 mb-> 1.42 mb -> 1.10 mb
测试打包 AB 资源的 CSharp 脚本 : BuildFbxToABEditor.cs
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEngine;
public static class BuildFbxToABEditor
{
[MenuItem("Tools/BuildSelectionToAB")]
private static void BuildSelectionToAB()
{
Debug.Log("BuildSelectionToAB START.");
var objs = Selection.objects;
if (objs == null || objs.Length == 0)
{
Debug.Log($"Selection.objects.Length : {objs.Length}, u have no selections.");
return;
}
var ab_build_infos = new AssetBundleBuild[objs.Length];
for (int i = 0; i
关注
打赏
热门博文
- 3D Assets (Textures & Model & Animations) & Game Design Ideas & DCC Tutorials & TA
- LearnGL - 学习笔记目录
- Unity - Timeline 知识汇总
- Unity Graphics - 知识点目录 - 停止翻译,因为发现官方有中文文档了
- Graphic资料
- Unity Lightmap&LightProbe局部动态加载(亲测2020以及以上版本官方修复了)
- Unity - 踩坑日志 - 低版本线性颜色空间渲染异常的 “BUG”
- Unity Shader - PBR 渲染 SP 导出的素材
- 什么是 3A 游戏?
- Photosohp - 实现 2D MetaBall、MetaFont