From e31ddd5631f3eb87797fa6c5728994cd01a341ef Mon Sep 17 00:00:00 2001 From: max Date: Mon, 18 Jan 2021 13:42:45 +0100 Subject: [PATCH] GenerateTexture2DArray in ModelBaker --- Editor/Scripts/ModelBaker/VA_ModelBaker.cs | 18 ++++++++++++------ Editor/Scripts/VA_AssetConverter.cs | 12 ------------ Editor/Scripts/VA_AssetConverter.cs.meta | 11 ----------- Runtime/Scripts/ModelBaker/AnimationBaker.cs | 5 ++++- Runtime/Scripts/VA_AnimationBook.cs | 2 +- Runtime/Scripts/VA_AnimationLibrary.cs | 2 +- Runtime/Scripts/VA_Texture2DArrayUtils.cs | 4 ++-- 7 files changed, 20 insertions(+), 34 deletions(-) delete mode 100644 Editor/Scripts/VA_AssetConverter.cs delete mode 100644 Editor/Scripts/VA_AssetConverter.cs.meta diff --git a/Editor/Scripts/ModelBaker/VA_ModelBaker.cs b/Editor/Scripts/ModelBaker/VA_ModelBaker.cs index 7a9cbe4..2c9ed79 100644 --- a/Editor/Scripts/ModelBaker/VA_ModelBaker.cs +++ b/Editor/Scripts/ModelBaker/VA_ModelBaker.cs @@ -4,7 +4,7 @@ using UnityEditor; namespace TAO.VertexAnimation.Editor { - [CreateAssetMenu(fileName = "new ModelBaker", menuName = "VA_ModelBaker/ModelBaker", order = 400)] + [CreateAssetMenu(fileName = "new ModelBaker", menuName = "TAO/VertexAnimation/ModelBaker", order = 400)] public class VA_ModelBaker : ScriptableObject { #if UNITY_EDITOR @@ -23,6 +23,7 @@ namespace TAO.VertexAnimation.Editor // Output. public GameObject prefab = null; + public Texture2DArray positionMap = null; public Material material = null; public Mesh[] meshes = null; public VA_AnimationBook book = null; @@ -89,6 +90,8 @@ namespace TAO.VertexAnimation.Editor target.ConbineAndConvertGameObject(); bakedData = target.Bake(animationClips, fps, textureWidth); + positionMap = VA_Texture2DArrayUtils.CreateTextureArray(bakedData.positionMaps.ToArray(), false, true, TextureWrapMode.Repeat, FilterMode.Point, 1, string.Format("{0}-PositionMap", name), true); + if (lodSettings.generate) { meshes = bakedData.mesh.GenerateLOD(lodSettings.LODCount(), lodSettings.GetQualitySettings()); @@ -105,16 +108,16 @@ namespace TAO.VertexAnimation.Editor { AssetDatabaseUtils.RemoveChildAssets(this, new Object[2] { book, material }); - // TODO: LODs foreach (var m in meshes) { AssetDatabase.AddObjectToAsset(m, this); } - foreach (var pm in bakedData.positionMaps) - { - AssetDatabase.AddObjectToAsset(pm, this); - } + AssetDatabase.AddObjectToAsset(positionMap, this); + //foreach (var pm in bakedData.positionMaps) + //{ + // AssetDatabase.AddObjectToAsset(pm, this); + //} AssetDatabase.SaveAssets(); @@ -176,6 +179,9 @@ namespace TAO.VertexAnimation.Editor material.shader = materialShader; } + material.SetTexture("_PositionMap", positionMap); + material.SetInt("_MaxFrames", bakedData.maxFrames); + // Generate Prefab prefab = AnimationPrefab.Create(path, name, meshes, material, lodSettings.GetTransitionSettings()); } diff --git a/Editor/Scripts/VA_AssetConverter.cs b/Editor/Scripts/VA_AssetConverter.cs deleted file mode 100644 index 4b5c5c8..0000000 --- a/Editor/Scripts/VA_AssetConverter.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -namespace TAO.VertexAnimation.Editor -{ - [CreateAssetMenu(fileName = "new AssetConverter", menuName = "VA_Animation/AssetConverter", order = 400)] - public class VA_AssetConverter : ScriptableObject - { - - } -} diff --git a/Editor/Scripts/VA_AssetConverter.cs.meta b/Editor/Scripts/VA_AssetConverter.cs.meta deleted file mode 100644 index a364a38..0000000 --- a/Editor/Scripts/VA_AssetConverter.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 55b196764521c964c84e8f2edd5c8da5 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/Scripts/ModelBaker/AnimationBaker.cs b/Runtime/Scripts/ModelBaker/AnimationBaker.cs index 2478cf9..e262bdb 100644 --- a/Runtime/Scripts/ModelBaker/AnimationBaker.cs +++ b/Runtime/Scripts/ModelBaker/AnimationBaker.cs @@ -10,6 +10,7 @@ namespace TAO.VertexAnimation { public Mesh mesh; public List positionMaps; + public int maxFrames; // Returns main position map. public Texture2D GetPositionMap @@ -84,6 +85,7 @@ namespace TAO.VertexAnimation BakedData bd = Bake(model, ac, animationInfo); bakedData.mesh = bd.mesh; bakedData.positionMaps.AddRange(bd.positionMaps); + bakedData.maxFrames = maxFrames; } return bakedData; @@ -106,7 +108,8 @@ namespace TAO.VertexAnimation BakedData bakedData = new BakedData() { mesh = mesh, - positionMaps = new List() { BakePositionMap(model, animationClip, animationInfo) } + positionMaps = new List() { BakePositionMap(model, animationClip, animationInfo) }, + maxFrames = animationInfo.maxFrames }; return bakedData; diff --git a/Runtime/Scripts/VA_AnimationBook.cs b/Runtime/Scripts/VA_AnimationBook.cs index 018dbe0..1ff8a23 100644 --- a/Runtime/Scripts/VA_AnimationBook.cs +++ b/Runtime/Scripts/VA_AnimationBook.cs @@ -3,7 +3,7 @@ using UnityEngine; namespace TAO.VertexAnimation { - [CreateAssetMenu(fileName = "new AnimationBook", menuName = "VA_Animation/AnimationBook", order = 400)] + [CreateAssetMenu(fileName = "new AnimationBook", menuName = "TAO/VertexAnimation/AnimationBook", order = 400)] public class VA_AnimationBook : ScriptableObject { public PlayData playData = null; diff --git a/Runtime/Scripts/VA_AnimationLibrary.cs b/Runtime/Scripts/VA_AnimationLibrary.cs index b56a392..548471c 100644 --- a/Runtime/Scripts/VA_AnimationLibrary.cs +++ b/Runtime/Scripts/VA_AnimationLibrary.cs @@ -3,7 +3,7 @@ using UnityEngine; namespace TAO.VertexAnimation { - [CreateAssetMenu(fileName = "new AnimationLibrary", menuName = "VA_Animation/AnimationLibrary", order = 400)] + [CreateAssetMenu(fileName = "new AnimationLibrary", menuName = "TAO/VertexAnimation/AnimationLibrary", order = 400)] public class VA_AnimationLibrary : ScriptableObject { [SerializeField] diff --git a/Runtime/Scripts/VA_Texture2DArrayUtils.cs b/Runtime/Scripts/VA_Texture2DArrayUtils.cs index 766ae01..431f932 100644 --- a/Runtime/Scripts/VA_Texture2DArrayUtils.cs +++ b/Runtime/Scripts/VA_Texture2DArrayUtils.cs @@ -5,7 +5,7 @@ namespace TAO.VertexAnimation public static class VA_Texture2DArrayUtils { public static Texture2DArray CreateTextureArray(Texture2D[] a_textures, bool a_useMipChain, bool a_isLinear, - TextureWrapMode a_wrapMode = TextureWrapMode.Repeat, FilterMode a_filterMode = FilterMode.Bilinear, int a_anisoLevel = 1, string a_name = "") + TextureWrapMode a_wrapMode = TextureWrapMode.Repeat, FilterMode a_filterMode = FilterMode.Bilinear, int a_anisoLevel = 1, string a_name = "", bool a_makeNoLongerReadable = true) { if(!IsValidForTextureArray(a_textures) || !IsValidCopyTexturePlatform()) { @@ -27,7 +27,7 @@ namespace TAO.VertexAnimation textureArray.anisoLevel = a_anisoLevel; textureArray.name = a_name; - textureArray.Apply(false, false); + textureArray.Apply(false, a_makeNoLongerReadable); return textureArray; }