From 1afaa6d81f050b9b708854e77ff1f8bf2defbe38 Mon Sep 17 00:00:00 2001 From: max Date: Thu, 21 Jan 2021 10:43:33 +0100 Subject: [PATCH] Include inactive meshes. Option to include inactive meshes. --- .../ModelBaker/Editor/VA_ModelBakerEditor.cs | 3 ++- Editor/Scripts/ModelBaker/VA_ModelBaker.cs | 5 +++-- Runtime/Scripts/ModelBaker/MeshCombiner.cs | 16 ++++++++++++---- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/Editor/Scripts/ModelBaker/Editor/VA_ModelBakerEditor.cs b/Editor/Scripts/ModelBaker/Editor/VA_ModelBakerEditor.cs index bc00536..853b8ee 100644 --- a/Editor/Scripts/ModelBaker/Editor/VA_ModelBakerEditor.cs +++ b/Editor/Scripts/ModelBaker/Editor/VA_ModelBakerEditor.cs @@ -28,9 +28,10 @@ namespace TAO.VertexAnimation.Editor { EditorGUILayout.PropertyField(serializedObject.FindProperty("model")); EditorGUILayout.PropertyField(serializedObject.FindProperty("animationClips")); - EditorGUILayout.PropertyField(serializedObject.FindProperty("applyRootMotion")); EditorGUILayout.PropertyField(serializedObject.FindProperty("fps")); EditorGUILayout.PropertyField(serializedObject.FindProperty("textureWidth")); + EditorGUILayout.PropertyField(serializedObject.FindProperty("applyRootMotion")); + EditorGUILayout.PropertyField(serializedObject.FindProperty("includeInactive")); } private void BakeGUI() diff --git a/Editor/Scripts/ModelBaker/VA_ModelBaker.cs b/Editor/Scripts/ModelBaker/VA_ModelBaker.cs index f7acae6..b930d05 100644 --- a/Editor/Scripts/ModelBaker/VA_ModelBaker.cs +++ b/Editor/Scripts/ModelBaker/VA_ModelBaker.cs @@ -12,10 +12,11 @@ namespace TAO.VertexAnimation.Editor // Input. public GameObject model; public AnimationClip[] animationClips; - public bool applyRootMotion = false; [Range(1, 60)] public int fps = 24; public int textureWidth = 512; + public bool applyRootMotion = false; + public bool includeInactive = false; public LODSettings lodSettings = new LODSettings(); public bool generateAnimationBook = true; @@ -97,7 +98,7 @@ namespace TAO.VertexAnimation.Editor var target = Instantiate(model); target.name = model.name; - target.ConbineAndConvertGameObject(); + target.ConbineAndConvertGameObject(includeInactive); AnimationBaker.BakedData bakedData = target.Bake(animationClips, applyRootMotion, fps, textureWidth); positionMap = VA_Texture2DArrayUtils.CreateTextureArray(bakedData.positionMaps.ToArray(), false, true, TextureWrapMode.Repeat, FilterMode.Point, 1, string.Format("{0}_PositionMap", name), true); diff --git a/Runtime/Scripts/ModelBaker/MeshCombiner.cs b/Runtime/Scripts/ModelBaker/MeshCombiner.cs index 6a64d7d..abbafd0 100644 --- a/Runtime/Scripts/ModelBaker/MeshCombiner.cs +++ b/Runtime/Scripts/ModelBaker/MeshCombiner.cs @@ -225,17 +225,25 @@ namespace TAO.VertexAnimation return target; } - public static void ConbineAndConvertGameObject(this GameObject gameObject) + public static void ConbineAndConvertGameObject(this GameObject gameObject, bool includeInactive = false) { // Get Skinned Meshes. - List skinnedMeshes = gameObject.GetComponentsInChildren(true).ToList(); + List skinnedMeshes = new List(); + gameObject.GetComponentsInChildren(includeInactive, skinnedMeshes); + + List meshFilters = new List(); + gameObject.GetComponentsInChildren(includeInactive, meshFilters); + // Get Meshes. List<(MeshFilter, MeshRenderer)> meshes = new List<(MeshFilter, MeshRenderer)>(); - foreach (var mf in gameObject.GetComponentsInChildren(true)) + foreach (var mf in meshFilters) { if (mf.TryGetComponent(out MeshRenderer mr)) { - meshes.Add((mf, mr)); + if (includeInactive || (!includeInactive && mr.enabled)) + { + meshes.Add((mf, mr)); + } } }