From 7c2d123066dc9a89f0e1186f471217cfce028d62 Mon Sep 17 00:00:00 2001 From: ichi23 Date: Mon, 8 Mar 2021 16:22:56 +0900 Subject: [PATCH 1/2] fix GetFromPath to return self when empty string is passed --- Assets/UniGLTF/Runtime/Extensions/UnityExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/UniGLTF/Runtime/Extensions/UnityExtensions.cs b/Assets/UniGLTF/Runtime/Extensions/UnityExtensions.cs index 4a3890053..37018488f 100644 --- a/Assets/UniGLTF/Runtime/Extensions/UnityExtensions.cs +++ b/Assets/UniGLTF/Runtime/Extensions/UnityExtensions.cs @@ -213,7 +213,7 @@ namespace UniGLTF { var current = self; - var split = path.Split('/'); + var split = path.Split(new [] {'/'}, StringSplitOptions.RemoveEmptyEntries); foreach (var childName in split) { From 4d9245f480624717f5d79c71898972c2921d2228 Mon Sep 17 00:00:00 2001 From: ichi23 Date: Mon, 8 Mar 2021 18:33:41 +0900 Subject: [PATCH 2/2] add animation validation when exporting gltf --- Assets/UniGLTF/Editor/Animation.meta | 3 + .../Editor/Animation/AnimationValidator.cs | 57 +++++++++++++++++++ .../Animation/AnimationValidator.cs.meta | 3 + .../Editor/UniGLTF/GltfExportWindow.cs | 3 +- 4 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 Assets/UniGLTF/Editor/Animation.meta create mode 100644 Assets/UniGLTF/Editor/Animation/AnimationValidator.cs create mode 100644 Assets/UniGLTF/Editor/Animation/AnimationValidator.cs.meta diff --git a/Assets/UniGLTF/Editor/Animation.meta b/Assets/UniGLTF/Editor/Animation.meta new file mode 100644 index 000000000..15f03e950 --- /dev/null +++ b/Assets/UniGLTF/Editor/Animation.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 31c3691403d341e2a9b49d6eb895e013 +timeCreated: 1615194750 \ No newline at end of file diff --git a/Assets/UniGLTF/Editor/Animation/AnimationValidator.cs b/Assets/UniGLTF/Editor/Animation/AnimationValidator.cs new file mode 100644 index 000000000..8545cac80 --- /dev/null +++ b/Assets/UniGLTF/Editor/Animation/AnimationValidator.cs @@ -0,0 +1,57 @@ +using System.Collections.Generic; +using System.Linq; +using MeshUtility; +using MeshUtility.M17N; +using UnityEditor; +using UnityEngine; + +namespace UniGLTF.Animation +{ + public static class AnimationValidator + { + private enum ExporterValidatorMessages + { + [LangMsg(Languages.ja, "ExportRootをanimateすることはできません")] + [LangMsg(Languages.en, "ExportRoot cannot be animated")] + ROOT_ANIMATED, + } + + public static IEnumerable Validate(GameObject root) + { + if (root == null) + { + yield break; + } + + var animationClips = new List(); + var animator = root.GetComponent(); + var animation = root.GetComponent(); + if (animator != null) + { + animationClips = AnimationExporter.GetAnimationClips(animator); + } + else if (animation != null) + { + animationClips = AnimationExporter.GetAnimationClips(animation); + } + + if (!animationClips.Any()) + { + yield break; + } + + foreach (var animationClip in animationClips) + { + foreach (var editorCurveBinding in AnimationUtility.GetCurveBindings(animationClip)) + { + // is root included in animation? + if (string.IsNullOrEmpty(editorCurveBinding.path)) + { + yield return Validation.Error(ExporterValidatorMessages.ROOT_ANIMATED.Msg()); + yield break; + } + } + } + } + } +} \ No newline at end of file diff --git a/Assets/UniGLTF/Editor/Animation/AnimationValidator.cs.meta b/Assets/UniGLTF/Editor/Animation/AnimationValidator.cs.meta new file mode 100644 index 000000000..fe5511b47 --- /dev/null +++ b/Assets/UniGLTF/Editor/Animation/AnimationValidator.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 0f8cc79b14e847b6a9f12c3ff2631661 +timeCreated: 1615188291 \ No newline at end of file diff --git a/Assets/UniGLTF/Editor/UniGLTF/GltfExportWindow.cs b/Assets/UniGLTF/Editor/UniGLTF/GltfExportWindow.cs index 6e6d9070a..2e60f932f 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/GltfExportWindow.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/GltfExportWindow.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; -using MeshUtility.M17N; +using UniGLTF.Animation; using UnityEditor; using UnityEngine; @@ -123,6 +123,7 @@ namespace UniGLTF IEnumerable ValidatorFactory() { yield return MeshUtility.Validators.HierarchyValidator.ValidateRoot; + yield return AnimationValidator.Validate; if (!m_state.ExportRoot) { yield break;