mirror of
https://github.com/maxartz15/VertexAnimation.git
synced 2025-04-11 19:55:54 +02:00
LODSettings
This commit is contained in:
parent
73d25ac453
commit
3ae24f5926
@ -5,87 +5,82 @@ using System.Linq;
|
|||||||
|
|
||||||
namespace TAO.VertexAnimation.Editor
|
namespace TAO.VertexAnimation.Editor
|
||||||
{
|
{
|
||||||
[CustomEditor(typeof(VA_ModelBaker))]
|
[CustomEditor(typeof(VA_ModelBaker))]
|
||||||
public class VA_ModelBakerEditor : UnityEditor.Editor
|
public class VA_ModelBakerEditor : UnityEditor.Editor
|
||||||
{
|
{
|
||||||
private VA_ModelBaker modelBaker = null;
|
private VA_ModelBaker modelBaker = null;
|
||||||
|
|
||||||
void OnEnable()
|
void OnEnable()
|
||||||
{
|
{
|
||||||
modelBaker = target as VA_ModelBaker;
|
modelBaker = target as VA_ModelBaker;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnInspectorGUI()
|
public override void OnInspectorGUI()
|
||||||
{
|
{
|
||||||
serializedObject.Update();
|
serializedObject.Update();
|
||||||
|
|
||||||
InputGUI();
|
InputGUI();
|
||||||
EditorGUILayoutUtils.HorizontalLine(color: Color.gray);
|
EditorGUILayoutUtils.HorizontalLine(color: Color.gray);
|
||||||
BakeGUI();
|
BakeGUI();
|
||||||
|
|
||||||
serializedObject.ApplyModifiedProperties();
|
serializedObject.ApplyModifiedProperties();
|
||||||
|
|
||||||
EditorGUILayoutUtils.HorizontalLine(color: Color.gray);
|
EditorGUILayoutUtils.HorizontalLine(color: Color.gray);
|
||||||
OutputGUI();
|
OutputGUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InputGUI()
|
private void InputGUI()
|
||||||
{
|
{
|
||||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("model"));
|
EditorGUILayout.PropertyField(serializedObject.FindProperty("model"));
|
||||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("animationClips"));
|
EditorGUILayout.PropertyField(serializedObject.FindProperty("animationClips"));
|
||||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("fps"));
|
EditorGUILayout.PropertyField(serializedObject.FindProperty("fps"));
|
||||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("textureWidth"));
|
EditorGUILayout.PropertyField(serializedObject.FindProperty("textureWidth"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void BakeGUI()
|
private void BakeGUI()
|
||||||
{
|
{
|
||||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("saveBakedDataToAsset"));
|
EditorGUILayout.PropertyField(serializedObject.FindProperty("saveBakedDataToAsset"));
|
||||||
|
|
||||||
int il = EditorGUI.indentLevel;
|
int il = EditorGUI.indentLevel;
|
||||||
if (modelBaker.saveBakedDataToAsset)
|
if (modelBaker.saveBakedDataToAsset)
|
||||||
{
|
{
|
||||||
EditorGUI.indentLevel++;
|
EditorGUI.indentLevel++;
|
||||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("generateAnimationBook"));
|
EditorGUILayout.PropertyField(serializedObject.FindProperty("generateAnimationBook"));
|
||||||
|
EditorGUILayout.PropertyField(serializedObject.FindProperty("lodSettings"));
|
||||||
|
|
||||||
using (new EditorGUILayout.HorizontalScope())
|
using (new EditorGUILayout.HorizontalScope())
|
||||||
{
|
{
|
||||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("generateLODS"));
|
EditorGUILayout.PropertyField(serializedObject.FindProperty("generatePrefab"));
|
||||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("lodCurve"), new GUIContent(""));
|
EditorGUILayout.PropertyField(serializedObject.FindProperty("materialShader"), new GUIContent(""));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
EditorGUI.indentLevel = il;
|
||||||
|
|
||||||
using (new EditorGUILayout.HorizontalScope())
|
if (GUILayout.Button("Bake", GUILayout.Height(32)))
|
||||||
{
|
{
|
||||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("generatePrefab"));
|
modelBaker.Bake();
|
||||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("materialShader"), new GUIContent(""));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
EditorGUI.indentLevel = il;
|
|
||||||
|
|
||||||
if (GUILayout.Button("Bake", GUILayout.Height(32)))
|
if (modelBaker.saveBakedDataToAsset)
|
||||||
{
|
{
|
||||||
modelBaker.Bake();
|
modelBaker.SaveAssets();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (modelBaker.saveBakedDataToAsset)
|
if (GUILayout.Button("Delete", EditorStyles.miniButtonRight))
|
||||||
{
|
{
|
||||||
modelBaker.SaveAssets();
|
if (EditorUtility.DisplayDialog("Delete Assets", "Deleting assets will loose references within the project.", "Ok", "Cancel"))
|
||||||
}
|
{
|
||||||
}
|
modelBaker.DeleteSavedAssets();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (GUILayout.Button("Delete", EditorStyles.miniButtonRight))
|
private void OutputGUI()
|
||||||
{
|
{
|
||||||
if (EditorUtility.DisplayDialog("Delete Assets", "Deleting assets will loose references within the project.", "Ok", "Cancel"))
|
using (new EditorGUI.DisabledGroupScope(true))
|
||||||
{
|
{
|
||||||
modelBaker.DeleteSavedAssets();
|
EditorGUILayout.PropertyField(serializedObject.FindProperty("bakedData"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OutputGUI()
|
|
||||||
{
|
|
||||||
using (new EditorGUI.DisabledGroupScope(true))
|
|
||||||
{
|
|
||||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("bakedData"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -14,11 +14,8 @@ namespace TAO.VertexAnimation.Editor
|
|||||||
[Range(1, 60)]
|
[Range(1, 60)]
|
||||||
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()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user