使用 Unity Mesh Simplifier 在 Unity 编辑器内降低模型面数
不需要使用 Max 或者 Blender Decimate 3D 软件
减面之后,再使用 FBX Exporter 导出减面的 FBX 就可以了
写了个编辑器脚本调用 mesh simplier api 方便使用
using UnityEditor;
using UnityEngine;
using UnityMeshSimplifier;
public class MeshSimplifyTool
{
[MenuItem ("GameObject/Simplify Mesh", false, 30)]
static void OnContextItem (MenuCommand command)
{
if (Selection.objects.Length <= 0)
{
DisplayNoSelectionDialog ();
return;
}
SimplifyMesh ();
}
private static void SimplifyMesh()
{
var selectedGOs = Selection.GetFiltered<GameObject> (SelectionMode.TopLevel);
if (selectedGOs.Length > 0)
{
var go = selectedGOs[0];
var mf = go.GetComponent<MeshFilter>();
if (mf == null)
{
DisplayNoMeshDialog();
return;
}
var mesh = mf.sharedMesh;
var ms = new MeshSimplifier();
ms.Initialize(mesh);
ms.SimplifyMesh(0.5f);
var destMesh = ms.ToMesh();
mf.sharedMesh = destMesh;
}
else
{
DisplayNoSelectionDialog();
}
}
private static void DisplayNoSelectionDialog()
{
EditorUtility.DisplayDialog (
"Mesh Simplify Warning",
"No GameObjects selected.",
"Ok");
}
private static void DisplayNoMeshDialog()
{
EditorUtility.DisplayDialog (
"Mesh Simplify Warning",
"GameObject has no mesh attach.",
"Ok");
}
}
使用步骤
- 在 Hierarchy 选中 GameObject 右键点击 Simplify Mesh
- 每次减面 50%,可反复点击
- 右键选中 使用 FBX Exporter 导出
–EOF–