2021-01-17 04:27:57 +01:00
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
namespace TAO.VertexAnimation
|
|
|
|
{
|
|
|
|
public static class MeshLodGenerator
|
|
|
|
{
|
|
|
|
public static Mesh[] GenerateLOD(this Mesh mesh, int lods, float[] quality)
|
|
|
|
{
|
|
|
|
Mesh[] lodMeshes = new Mesh[lods];
|
|
|
|
|
|
|
|
for (int lm = 0; lm < lodMeshes.Length; lm++)
|
|
|
|
{
|
|
|
|
lodMeshes[lm] = mesh.Copy();
|
2021-02-18 17:35:05 +01:00
|
|
|
|
|
|
|
// Only simplify when needed.
|
|
|
|
if (quality[lm] < 1.0f)
|
|
|
|
{
|
|
|
|
lodMeshes[lm] = lodMeshes[lm].Simplify(quality[lm]);
|
|
|
|
}
|
|
|
|
|
2021-01-17 04:27:57 +01:00
|
|
|
lodMeshes[lm].name = string.Format("{0}_LOD{1}", lodMeshes[lm].name, lm);
|
|
|
|
}
|
|
|
|
|
|
|
|
return lodMeshes;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Mesh[] GenerateLOD(this Mesh mesh, int lods, AnimationCurve qualityCurve)
|
|
|
|
{
|
|
|
|
float[] quality = new float[lods];
|
|
|
|
|
|
|
|
for (int q = 0; q < quality.Length; q++)
|
|
|
|
{
|
|
|
|
quality[q] = qualityCurve.Evaluate(1f / quality.Length * q);
|
|
|
|
}
|
|
|
|
|
|
|
|
return GenerateLOD(mesh, lods, quality);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|