mirror of
https://github.com/maxartz15/VertexAnimation.git
synced 2025-07-03 06:46:05 +02:00
Model Baker
Model Baker ScriptableObject, bakes models and outputs the data. Can also generate prefab and animation books for quick setup. Updated GUI.
This commit is contained in:
20
Editor/Scripts/Editor/EditorGUILayoutUtils.cs
Normal file
20
Editor/Scripts/Editor/EditorGUILayoutUtils.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TAO.VertexAnimation.Editor
|
||||
{
|
||||
public static class EditorGUILayoutUtils
|
||||
{
|
||||
public static readonly Color horizontalLineColor = Color.white;
|
||||
|
||||
public static void HorizontalLine(Color color)
|
||||
{
|
||||
Color prev = GUI.color;
|
||||
GUI.color = color;
|
||||
EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);
|
||||
GUI.color = prev;
|
||||
}
|
||||
|
||||
public static void HorizontalLine() => HorizontalLine(horizontalLineColor);
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3a3231c3c369f0c4ab95f98b979d0530
|
||||
guid: 0a78d6eea6c7f534b8361125e43eacc9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: afa9933157fe17b40be247abddb0b2ee
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5fb7e85d011f3c6419742e766fc11aeb
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,109 +0,0 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace TAO.VertexAnimation.Editor
|
||||
{
|
||||
[CustomEditor(typeof(VA_ModelBaker))]
|
||||
public class VA_ModelBakerEditor : UnityEditor.Editor
|
||||
{
|
||||
private VA_ModelBaker modelBaker = null;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
modelBaker = target as VA_ModelBaker;
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
serializedObject.Update();
|
||||
|
||||
InputGUI();
|
||||
BakeGUI();
|
||||
OutputGUI();
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
|
||||
private void InputGUI()
|
||||
{
|
||||
//public GameObject model;
|
||||
//public AnimationClip[] animationClips;
|
||||
//public int fps = 24;
|
||||
//public int textureWidth = 512;
|
||||
//public bool saveBakedDataToAsset = true;
|
||||
//public bool generateAnimationBook = false;
|
||||
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("model"));
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("animationClips"));
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("fps"));
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("textureWidth"));
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("saveBakedDataToAsset"));
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("generateAnimationBook"));
|
||||
}
|
||||
|
||||
private void BakeGUI()
|
||||
{
|
||||
if (GUILayout.Button("Bake"))
|
||||
{
|
||||
ClearBakedData();
|
||||
|
||||
modelBaker.Bake();
|
||||
|
||||
if (modelBaker.saveBakedDataToAsset)
|
||||
{
|
||||
SaveBakedData();
|
||||
}
|
||||
}
|
||||
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
if (GUILayout.Button("SaveBakedData", EditorStyles.miniButtonLeft))
|
||||
{
|
||||
SaveBakedData();
|
||||
}
|
||||
|
||||
if (GUILayout.Button("ClearBakedData", EditorStyles.miniButtonRight))
|
||||
{
|
||||
ClearBakedData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OutputGUI()
|
||||
{
|
||||
using (new EditorGUI.DisabledGroupScope(true))
|
||||
{
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("bakedData"));
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveBakedData()
|
||||
{
|
||||
AssetDatabase.AddObjectToAsset(modelBaker.BakedData.mesh, modelBaker);
|
||||
|
||||
foreach (var pm in modelBaker.BakedData.positionMaps)
|
||||
{
|
||||
AssetDatabase.AddObjectToAsset(pm, modelBaker);
|
||||
}
|
||||
|
||||
AssetDatabase.SaveAssets();
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
|
||||
private void ClearBakedData()
|
||||
{
|
||||
var assets = AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(modelBaker));
|
||||
|
||||
foreach (var a in assets)
|
||||
{
|
||||
if (a != modelBaker)
|
||||
{
|
||||
AssetDatabase.RemoveObjectFromAsset(a);
|
||||
}
|
||||
}
|
||||
|
||||
AssetDatabase.SaveAssets();
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
}
|
||||
}
|
@ -10,10 +10,6 @@ namespace TAO.VertexAnimation.Editor
|
||||
private Vector2 textureGroupScollPos;
|
||||
private Vector2 animationPagesScollPos;
|
||||
|
||||
//private UnityEditor.Editor previewEditor = null;
|
||||
//private int previewIndex = 0;
|
||||
//private int curviewIndex = 0;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
animationBook = target as VA_AnimationBook;
|
||||
@ -25,11 +21,16 @@ namespace TAO.VertexAnimation.Editor
|
||||
|
||||
// Texture Groups.
|
||||
GeneralGUI();
|
||||
EditorGUILayoutUtils.HorizontalLine(color: Color.gray);
|
||||
TextureGroupsGUI();
|
||||
EditorGUILayoutUtils.HorizontalLine(color: Color.gray);
|
||||
SyncListSize();
|
||||
AnimationPagesGUI();
|
||||
EditorGUILayoutUtils.HorizontalLine(color: Color.gray);
|
||||
MaterialGUI();
|
||||
EditorGUILayoutUtils.HorizontalLine(color: Color.gray);
|
||||
AssetBuilderGUI();
|
||||
EditorGUILayoutUtils.HorizontalLine(color: Color.gray);
|
||||
Texture2DGUI();
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
|
Reference in New Issue
Block a user