LODSettings

This commit is contained in:
max 2021-01-18 13:01:47 +01:00
parent 73d25ac453
commit 3ae24f5926
2 changed files with 121 additions and 78 deletions

View File

@ -46,12 +46,7 @@ namespace TAO.VertexAnimation.Editor
{ {
EditorGUI.indentLevel++; EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(serializedObject.FindProperty("generateAnimationBook")); EditorGUILayout.PropertyField(serializedObject.FindProperty("generateAnimationBook"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("lodSettings"));
using (new EditorGUILayout.HorizontalScope())
{
EditorGUILayout.PropertyField(serializedObject.FindProperty("generateLODS"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("lodCurve"), new GUIContent(""));
}
using (new EditorGUILayout.HorizontalScope()) using (new EditorGUILayout.HorizontalScope())
{ {

View File

@ -15,10 +15,7 @@ namespace TAO.VertexAnimation.Editor
public int fps = 24; public int fps = 24;
public int textureWidth = 512; public int textureWidth = 512;
public bool generateLODS = true; public LODSettings lodSettings = new LODSettings();
// TODO: Improve curve/lod settings. LOD-Mesh Quality pair.
//public Vector2[] lodLevels = new Vector2[4] { new Vector2(32, 100), new Vector2(32, 65), new Vector2(32, 30), new Vector2(3, 0) };
public AnimationCurve lodCurve = new AnimationCurve(new Keyframe(0, 1), new Keyframe(1, 0.01f));
public bool saveBakedDataToAsset = true; public bool saveBakedDataToAsset = true;
public bool generateAnimationBook = true; public bool generateAnimationBook = true;
public bool generatePrefab = true; public bool generatePrefab = true;
@ -33,6 +30,57 @@ namespace TAO.VertexAnimation.Editor
[SerializeField] [SerializeField]
private AnimationBaker.BakedData bakedData; private AnimationBaker.BakedData bakedData;
[System.Serializable]
public class LODSettings
{
public bool generate = true;
public LODSetting[] lodSettings = new LODSetting[3] { new LODSetting(1, .4f), new LODSetting(.6f, .15f), new LODSetting(.3f, .01f) };
public float[] GetQualitySettings()
{
float[] q = new float[lodSettings.Length];
for (int i = 0; i < lodSettings.Length; i++)
{
q[i] = lodSettings[i].quality;
}
return q;
}
public float[] GetTransitionSettings()
{
float[] t = new float[lodSettings.Length];
for (int i = 0; i < lodSettings.Length; i++)
{
t[i] = lodSettings[i].screenRelativeTransitionHeight;
}
return t;
}
public int LODCount()
{
return lodSettings.Length;
}
}
[System.Serializable]
public struct LODSetting
{
[Range(1.0f, 0.0f)]
public float quality;
[Range(1.0f, 0.0f)]
public float screenRelativeTransitionHeight;
public LODSetting(float q, float t)
{
quality = q;
screenRelativeTransitionHeight = t;
}
}
public void Bake() public void Bake()
{ {
var target = Instantiate(model); var target = Instantiate(model);
@ -41,9 +89,9 @@ namespace TAO.VertexAnimation.Editor
target.ConbineAndConvertGameObject(); target.ConbineAndConvertGameObject();
bakedData = target.Bake(animationClips, fps, textureWidth); bakedData = target.Bake(animationClips, fps, textureWidth);
if (generateLODS) if (lodSettings.generate)
{ {
meshes = bakedData.mesh.GenerateLOD(3, lodCurve); meshes = bakedData.mesh.GenerateLOD(lodSettings.LODCount(), lodSettings.GetQualitySettings());
} }
else else
{ {
@ -129,7 +177,7 @@ namespace TAO.VertexAnimation.Editor
} }
// Generate Prefab // Generate Prefab
prefab = AnimationPrefab.Create(path, name, meshes, material, lodCurve); prefab = AnimationPrefab.Create(path, name, meshes, material, lodSettings.GetTransitionSettings());
} }
public void GenerateBook() public void GenerateBook()