From c3fd6886198afb9929ea08dc7aaff2fcb51398ff Mon Sep 17 00:00:00 2001 From: max Date: Tue, 19 Jan 2021 16:35:37 +0100 Subject: [PATCH] Fix texture naming error. Fix texture naming error. FixedString32 -> FixedString64. --- Editor/Scripts/ModelBaker/VA_ModelBaker.cs | 12 ++++++++++++ Runtime/Scripts/ModelBaker/AnimationBaker.cs | 2 +- .../Scripts/ModelBaker/NamingConventionUtils.cs | 9 ++++++--- Runtime/Scripts/VA_Animation.cs | 6 +++--- Runtime/Scripts/VA_AnimationBook.cs | 16 ++++++++++++---- Runtime/Scripts/VA_AnimationLibraryData.cs | 6 +++--- 6 files changed, 37 insertions(+), 14 deletions(-) diff --git a/Editor/Scripts/ModelBaker/VA_ModelBaker.cs b/Editor/Scripts/ModelBaker/VA_ModelBaker.cs index 2cf5360..84fcc14 100644 --- a/Editor/Scripts/ModelBaker/VA_ModelBaker.cs +++ b/Editor/Scripts/ModelBaker/VA_ModelBaker.cs @@ -79,6 +79,18 @@ namespace TAO.VertexAnimation.Editor } } + private void OnValidate() + { + if (materialShader == null) + { + materialShader = Shader.Find("VA_VertexAnimationBase"); + if (materialShader == null) + { + materialShader = Shader.Find("Shader Graphs/VA_VertexAnimationBase"); + } + } + } + public void Bake() { var target = Instantiate(model); diff --git a/Runtime/Scripts/ModelBaker/AnimationBaker.cs b/Runtime/Scripts/ModelBaker/AnimationBaker.cs index e262bdb..8d1118e 100644 --- a/Runtime/Scripts/ModelBaker/AnimationBaker.cs +++ b/Runtime/Scripts/ModelBaker/AnimationBaker.cs @@ -158,7 +158,7 @@ namespace TAO.VertexAnimation GameObject.DestroyImmediate(inst); - positionMap.name = string.Format("VA_N-{0}_F-{1}_MF-{2}_FPS-{3}", animationClip.name, animationInfo.frames, animationInfo.maxFrames, animationInfo.fps); + positionMap.name = string.Format("VA_N-{0}_F-{1}_MF-{2}_FPS-{3}", NamingConventionUtils.ConvertToValidString(animationClip.name), animationInfo.frames, animationInfo.maxFrames, animationInfo.fps); positionMap.filterMode = FilterMode.Point; positionMap.Apply(false, true); diff --git a/Runtime/Scripts/ModelBaker/NamingConventionUtils.cs b/Runtime/Scripts/ModelBaker/NamingConventionUtils.cs index 8e6cc12..3346a27 100644 --- a/Runtime/Scripts/ModelBaker/NamingConventionUtils.cs +++ b/Runtime/Scripts/ModelBaker/NamingConventionUtils.cs @@ -1,6 +1,4 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; +using System.Linq; namespace TAO.VertexAnimation { @@ -50,5 +48,10 @@ namespace TAO.VertexAnimation return textureInfo; } + + public static string ConvertToValidString(this string str) + { + return string.Concat(str.Where(char.IsLetterOrDigit)); + } } } diff --git a/Runtime/Scripts/VA_Animation.cs b/Runtime/Scripts/VA_Animation.cs index 68d8c4a..d935bf2 100644 --- a/Runtime/Scripts/VA_Animation.cs +++ b/Runtime/Scripts/VA_Animation.cs @@ -16,13 +16,13 @@ namespace TAO.VertexAnimation public VA_AnimationData GetData() { // TODO: Fix data name, FixedString32 doesn't transfer from editor? - Data.name = new FixedString32(name); + Data.name = new FixedString64(name); return Data; } - public FixedString32 GetName() + public FixedString64 GetName() { - return new FixedString32(this.name); + return new FixedString64(this.name); } } } \ No newline at end of file diff --git a/Runtime/Scripts/VA_AnimationBook.cs b/Runtime/Scripts/VA_AnimationBook.cs index e5acaaa..9f700df 100644 --- a/Runtime/Scripts/VA_AnimationBook.cs +++ b/Runtime/Scripts/VA_AnimationBook.cs @@ -53,12 +53,20 @@ namespace TAO.VertexAnimation public bool TryAddMaterial(Material material) { - if (!materials.Contains(material)) + if (material != null) { - if (material.HasProperty("_PositionMap") && material.HasProperty("_MaxFrames")) + if (materials == null) { - materials.Add(material); - return true; + materials = new List(); + } + + if (!materials.Contains(material)) + { + if (material.HasProperty("_PositionMap") && material.HasProperty("_MaxFrames")) + { + materials.Add(material); + return true; + } } } diff --git a/Runtime/Scripts/VA_AnimationLibraryData.cs b/Runtime/Scripts/VA_AnimationLibraryData.cs index 6c9002e..cdfdf3f 100644 --- a/Runtime/Scripts/VA_AnimationLibraryData.cs +++ b/Runtime/Scripts/VA_AnimationLibraryData.cs @@ -6,7 +6,7 @@ namespace TAO.VertexAnimation [System.Serializable] public struct VA_AnimationData { - public VA_AnimationData(FixedString32 a_name, int a_frames, int a_maxFrames, int a_fps, int a_positionMapIndex, int a_colorMapIndex = -1) + public VA_AnimationData(FixedString64 a_name, int a_frames, int a_maxFrames, int a_fps, int a_positionMapIndex, int a_colorMapIndex = -1) { name = a_name; frames = a_frames; @@ -18,7 +18,7 @@ namespace TAO.VertexAnimation } // The name of the animation. - public FixedString32 name; + public FixedString64 name; // The frames in this animation. public int frames; // The maximum of frames the texture holds. @@ -42,7 +42,7 @@ namespace TAO.VertexAnimation { public const string AnimationLibraryAssetStoreName = "VA_AnimationLibrary"; - public static int GetAnimation(ref VA_AnimationLibraryData animationsRef, FixedString32 animationName) + public static int GetAnimation(ref VA_AnimationLibraryData animationsRef, FixedString64 animationName) { for (int i = 0; i < animationsRef.animations.Length; i++) {