mirror of
https://github.com/maxartz15/VertexAnimation.git
synced 2024-11-14 16:25:32 +01:00
33 lines
773 B
C#
33 lines
773 B
C#
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();
|
|
lodMeshes[lm] = lodMeshes[lm].Simplify(quality[lm]);
|
|
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);
|
|
}
|
|
}
|
|
} |