From 3c14c98cf9382ed764a9414a2c46b05a2bc5c2e1 Mon Sep 17 00:00:00 2001 From: max Date: Wed, 17 Feb 2021 00:49:03 +0100 Subject: [PATCH] Update VA_ModelBaker.cs Removed LitGUI debug logs. Updated VA_ModelBaker material creation and setting update. Added mesh finalize function to optimize and upload the mesh data. --- Editor/Scripts/Editor/LitGUI.cs | 3 -- Editor/Scripts/ModelBaker/VA_ModelBaker.cs | 31 +++----------- .../Scripts/ModelBaker/AnimationMaterial.cs | 40 +++++++++++++++++++ Runtime/Scripts/ModelBaker/MeshUtils.cs | 8 ++++ 4 files changed, 54 insertions(+), 28 deletions(-) diff --git a/Editor/Scripts/Editor/LitGUI.cs b/Editor/Scripts/Editor/LitGUI.cs index fcb0f0b..fc879a5 100644 --- a/Editor/Scripts/Editor/LitGUI.cs +++ b/Editor/Scripts/Editor/LitGUI.cs @@ -116,12 +116,10 @@ namespace TAO.VertexAnimation.Editor if (EditorGUI.EndChangeCheck()) { - Debug.Log(value); SetKeyword("USE_INTERPOLATION_ON", value); } } - { bool value = mat.IsKeywordEnabled("USE_NORMALA_ON"); MaterialProperty useNormalA = FindProperty("USE_NORMALA", properties); @@ -148,7 +146,6 @@ namespace TAO.VertexAnimation.Editor if (EditorGUI.EndChangeCheck()) { - Debug.Log(value); SetKeyword("VA_FLIP_UVS_ON", value); } } diff --git a/Editor/Scripts/ModelBaker/VA_ModelBaker.cs b/Editor/Scripts/ModelBaker/VA_ModelBaker.cs index bc45b16..d302e9e 100644 --- a/Editor/Scripts/ModelBaker/VA_ModelBaker.cs +++ b/Editor/Scripts/ModelBaker/VA_ModelBaker.cs @@ -113,6 +113,7 @@ namespace TAO.VertexAnimation.Editor foreach (var m in meshes) { + m.Finalize(); AssetDatabase.AddObjectToAsset(m, this); } @@ -141,40 +142,20 @@ namespace TAO.VertexAnimation.Editor path = path.Remove(start, path.Length - start); path += "/" + name + ".prefab"; + // Get info. + NamingConventionUtils.PositionMapInfo info = bakedData.GetPositionMap.name.GetTextureInfo(); + // Generate Material if (!AssetDatabaseUtils.HasChildAsset(this, material)) { - material = AnimationMaterial.Create(name, materialShader); + material = AnimationMaterial.Create(name, materialShader, positionMap, useNormalA, useInterpolation, info.maxFrames); AssetDatabase.AddObjectToAsset(material, this); } else { - material.shader = materialShader; + material.Update(name, materialShader, positionMap, useNormalA, useInterpolation, info.maxFrames); } - material.SetTexture("_PositionMap", positionMap); - material.SetInt("_MaxFrames", bakedData.maxFrames); - - if (useNormalA) - { - material.EnableKeyword("USE_NORMALA_ON"); - } - else - { - material.DisableKeyword("USE_NORMALA_ON"); - } - - if(useInterpolation) - { - material.EnableKeyword("USE_INTERPOLATION_ON"); - } - else - { - material.DisableKeyword("USE_INTERPOLATION_ON"); - } - - material.enableInstancing = true; - // Generate Prefab prefab = AnimationPrefab.Create(path, name, meshes, material, lodSettings.GetTransitionSettings()); } diff --git a/Runtime/Scripts/ModelBaker/AnimationMaterial.cs b/Runtime/Scripts/ModelBaker/AnimationMaterial.cs index 0fe1b1c..e440daf 100644 --- a/Runtime/Scripts/ModelBaker/AnimationMaterial.cs +++ b/Runtime/Scripts/ModelBaker/AnimationMaterial.cs @@ -14,5 +14,45 @@ namespace TAO.VertexAnimation return material; } + + public static Material Create(string name, Shader shader, Texture2DArray positionMap, bool useNormalA, bool useInterpolation, int maxFrames) + { + Material material = Create(name, shader); + + material.Update(name, shader, positionMap, useNormalA, useInterpolation, maxFrames); + + return material; + } + + public static void Update(this Material material, string name, Shader shader, Texture2DArray positionMap, bool useNormalA, bool useInterpolation, int maxFrames) + { + material.name = name; + + if (material.shader != shader) + { + material.shader = shader; + } + + material.SetTexture("_PositionMap", positionMap); + material.SetInt("_MaxFrames", maxFrames); + + if (useNormalA) + { + material.EnableKeyword("USE_NORMALA_ON"); + } + else + { + material.DisableKeyword("USE_NORMALA_ON"); + } + + if (useInterpolation) + { + material.EnableKeyword("USE_INTERPOLATION_ON"); + } + else + { + material.DisableKeyword("USE_INTERPOLATION_ON"); + } + } } } \ No newline at end of file diff --git a/Runtime/Scripts/ModelBaker/MeshUtils.cs b/Runtime/Scripts/ModelBaker/MeshUtils.cs index a432b4e..6fe29dd 100644 --- a/Runtime/Scripts/ModelBaker/MeshUtils.cs +++ b/Runtime/Scripts/ModelBaker/MeshUtils.cs @@ -4,6 +4,7 @@ namespace TAO.VertexAnimation { public static class MeshUtils { + // Copy a mesh and it's properties. public static Mesh Copy(this Mesh mesh) { Mesh copy = new Mesh @@ -29,5 +30,12 @@ namespace TAO.VertexAnimation return copy; } + + // Optimize the mesh and upload the mesh data, makes the mesh no longer readable. + public static void Finalize(this Mesh mesh) + { + mesh.Optimize(); + mesh.UploadMeshData(true); + } } }