diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/AnimationIO/AnimationCurveData.cs b/Assets/UniGLTF/Editor/Animation/AnimationCurveData.cs similarity index 100% rename from Assets/UniGLTF/Runtime/UniGLTF/IO/AnimationIO/AnimationCurveData.cs rename to Assets/UniGLTF/Editor/Animation/AnimationCurveData.cs diff --git a/Assets/UniGLTF/Editor/Animation/AnimationCurveData.cs.meta b/Assets/UniGLTF/Editor/Animation/AnimationCurveData.cs.meta new file mode 100644 index 000000000..9fd968c7c --- /dev/null +++ b/Assets/UniGLTF/Editor/Animation/AnimationCurveData.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: cd3120ad83927864fa7b56ce619e60ba +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/AnimationIO/AnimationExporter.cs b/Assets/UniGLTF/Editor/Animation/AnimationExporter.cs similarity index 100% rename from Assets/UniGLTF/Runtime/UniGLTF/IO/AnimationIO/AnimationExporter.cs rename to Assets/UniGLTF/Editor/Animation/AnimationExporter.cs diff --git a/Assets/UniGLTF/Editor/Animation/AnimationExporter.cs.meta b/Assets/UniGLTF/Editor/Animation/AnimationExporter.cs.meta new file mode 100644 index 000000000..e938c1fe5 --- /dev/null +++ b/Assets/UniGLTF/Editor/Animation/AnimationExporter.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 10bbffd95db4d7a4abb3d0e74f46f994 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/AnimationIO/AnimationKeyframeData.cs b/Assets/UniGLTF/Editor/Animation/AnimationKeyframeData.cs similarity index 100% rename from Assets/UniGLTF/Runtime/UniGLTF/IO/AnimationIO/AnimationKeyframeData.cs rename to Assets/UniGLTF/Editor/Animation/AnimationKeyframeData.cs diff --git a/Assets/UniGLTF/Editor/Animation/AnimationKeyframeData.cs.meta b/Assets/UniGLTF/Editor/Animation/AnimationKeyframeData.cs.meta new file mode 100644 index 000000000..ba88208ba --- /dev/null +++ b/Assets/UniGLTF/Editor/Animation/AnimationKeyframeData.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 343050b608326344ebef0369448f8159 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UniGLTF/Editor/Animation/AnimationValidator.cs b/Assets/UniGLTF/Editor/Animation/AnimationValidator.cs index b451d4e9d..91812a93d 100644 --- a/Assets/UniGLTF/Editor/Animation/AnimationValidator.cs +++ b/Assets/UniGLTF/Editor/Animation/AnimationValidator.cs @@ -4,7 +4,7 @@ using UniGLTF.M17N; using UnityEditor; using UnityEngine; -namespace UniGLTF.Animation +namespace UniGLTF { public static class AnimationValidator { diff --git a/Assets/UniGLTF/Editor/Animation/EditorAnimationExporter.cs b/Assets/UniGLTF/Editor/Animation/EditorAnimationExporter.cs new file mode 100644 index 000000000..cbf8c3404 --- /dev/null +++ b/Assets/UniGLTF/Editor/Animation/EditorAnimationExporter.cs @@ -0,0 +1,75 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using UnityEngine; + +namespace UniGLTF +{ + public class EditorAnimationExporter : IAnimationExporter + { + /// + /// AnimationClip を収集する。 + /// + static List GetAnimationClips(GameObject Copy) + { + var clips = new List(); + var animator = Copy.GetComponent(); + var animation = Copy.GetComponent(); + if (animator != null) + { + clips = AnimationExporter.GetAnimationClips(animator); + } + else if (animation != null) + { + clips = AnimationExporter.GetAnimationClips(animation); + } + return clips; + } + + public void Export(ExportingGltfData _data, GameObject Copy, List Nodes) + { + var clips = GetAnimationClips(Copy); + + foreach (AnimationClip clip in clips) + { + var animationWithCurve = AnimationExporter.Export(clip, Copy.transform, Nodes); + + foreach (var kv in animationWithCurve.SamplerMap) + { + var sampler = animationWithCurve.Animation.samplers[kv.Key]; + + var inputAccessorIndex = _data.ExtendBufferAndGetAccessorIndex(kv.Value.Input); + sampler.input = inputAccessorIndex; + + var outputAccessorIndex = _data.ExtendBufferAndGetAccessorIndex(kv.Value.Output); + sampler.output = outputAccessorIndex; + + // modify accessors + var outputAccessor = _data.Gltf.accessors[outputAccessorIndex]; + var channel = animationWithCurve.Animation.channels.First(x => x.sampler == kv.Key); + switch (glTFAnimationTarget.GetElementCount(channel.target.path)) + { + case 1: + outputAccessor.type = "SCALAR"; + //outputAccessor.count = ; + break; + case 3: + outputAccessor.type = "VEC3"; + outputAccessor.count /= 3; + break; + + case 4: + outputAccessor.type = "VEC4"; + outputAccessor.count /= 4; + break; + + default: + throw new NotImplementedException(); + } + } + animationWithCurve.Animation.name = clip.name; + _data.Gltf.animations.Add(animationWithCurve.Animation); + } + } + } +} diff --git a/Assets/UniGLTF/Editor/Animation/EditorAnimationExporter.cs.meta b/Assets/UniGLTF/Editor/Animation/EditorAnimationExporter.cs.meta new file mode 100644 index 000000000..f8961ddbf --- /dev/null +++ b/Assets/UniGLTF/Editor/Animation/EditorAnimationExporter.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 62c5fa8e50275804b8084f3764f9d8f3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/GltfExportWindow.cs b/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/GltfExportWindow.cs index 30f85d0bf..9e789c59a 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/GltfExportWindow.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/GltfExportWindow.cs @@ -1,7 +1,6 @@ using System.Collections.Generic; using System.IO; using System.Linq; -using UniGLTF.Animation; using UnityEditor; using UnityEngine; using VRMShaders; @@ -106,6 +105,7 @@ namespace UniGLTF { var data = new ExportingGltfData(); + Settings.AnimationExporter = new EditorAnimationExporter(); using (var exporter = new gltfExporter(data, Settings, new EditorProgress())) { exporter.Prepare(State.ExportRoot); diff --git a/Assets/UniGLTF/Runtime/UniGLTF/Format/glTFAnimation.cs b/Assets/UniGLTF/Runtime/UniGLTF/Format/glTFAnimation.cs index 89460cce7..23f9b4395 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/Format/glTFAnimation.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/Format/glTFAnimation.cs @@ -47,7 +47,7 @@ namespace UniGLTF } [Obsolete] - internal static AnimationProperties AnimationPropertysToAnimationProperties(AnimationPropertys property) + public static AnimationProperties AnimationPropertysToAnimationProperties(AnimationPropertys property) { if (!Enum.IsDefined(typeof(AnimationProperties), property)) { diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/AnimationIO/AnimationCurveData.cs.meta b/Assets/UniGLTF/Runtime/UniGLTF/IO/AnimationIO/AnimationCurveData.cs.meta deleted file mode 100644 index a6b2101b9..000000000 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/AnimationIO/AnimationCurveData.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 1af21722605d44f58deebfcfca642b32 -timeCreated: 1537442711 \ No newline at end of file diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/AnimationIO/AnimationExporter.cs.meta b/Assets/UniGLTF/Runtime/UniGLTF/IO/AnimationIO/AnimationExporter.cs.meta deleted file mode 100644 index 6603cc132..000000000 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/AnimationIO/AnimationExporter.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 015ae41bf6cb4428b8257ead79772908 -timeCreated: 1537443293 \ No newline at end of file diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/AnimationIO/AnimationKeyframeData.cs.meta b/Assets/UniGLTF/Runtime/UniGLTF/IO/AnimationIO/AnimationKeyframeData.cs.meta deleted file mode 100644 index 06d8ca4ad..000000000 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/AnimationIO/AnimationKeyframeData.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: e27ef4fb768e49f591c2bb5eadd3b19b -timeCreated: 1537442737 \ No newline at end of file diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/AnimationIO/IAnimationExporter.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/AnimationIO/IAnimationExporter.cs new file mode 100644 index 000000000..2c20ba056 --- /dev/null +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/AnimationIO/IAnimationExporter.cs @@ -0,0 +1,10 @@ +using System.Collections.Generic; +using UnityEngine; + +namespace UniGLTF +{ + public interface IAnimationExporter + { + void Export(ExportingGltfData _data, GameObject Copy, List Nodes); + } +} diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/AnimationIO/IAnimationExporter.cs.meta b/Assets/UniGLTF/Runtime/UniGLTF/IO/AnimationIO/IAnimationExporter.cs.meta new file mode 100644 index 000000000..3e53284dc --- /dev/null +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/AnimationIO/IAnimationExporter.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7bcb89e584f47c34c9ad19bdce8ccad0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfExportSettings.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfExportSettings.cs index b29f85d82..c9a7bba27 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfExportSettings.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfExportSettings.cs @@ -45,5 +45,7 @@ namespace UniGLTF /// Keep VertexColor /// public bool KeepVertexColor; + + public IAnimationExporter AnimationExporter; } } diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/gltfExporter.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/gltfExporter.cs index 4d0ebd261..4e70a09ed 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/gltfExporter.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/gltfExporter.cs @@ -236,81 +236,6 @@ namespace UniGLTF // do nothing } - /// - /// AnimationClip を収集する。 - /// - List GetAnimationClips() - { - var clips = new List(); - var animator = Copy.GetComponent(); - var animation = Copy.GetComponent(); - if (animator != null) - { - clips = AnimationExporter.GetAnimationClips(animator); - } - else if (animation != null) - { - clips = AnimationExporter.GetAnimationClips(animation); - } - return clips; - } - - public virtual void ExportAnimations() - { - if (Application.isPlaying) - { - // UnityEditor.AnimationUtility などが Editor 専用のため、 - // Editor 時のみ Export できる。 - // !Application.isPlaying ならば Editor であろう。 - return; - } - - ReportProgress("Animations", 0.9f); - - var clips = GetAnimationClips(); - - foreach (AnimationClip clip in clips) - { - var animationWithCurve = AnimationExporter.Export(clip, Copy.transform, Nodes); - - foreach (var kv in animationWithCurve.SamplerMap) - { - var sampler = animationWithCurve.Animation.samplers[kv.Key]; - - var inputAccessorIndex = _data.ExtendBufferAndGetAccessorIndex(kv.Value.Input); - sampler.input = inputAccessorIndex; - - var outputAccessorIndex = _data.ExtendBufferAndGetAccessorIndex(kv.Value.Output); - sampler.output = outputAccessorIndex; - - // modify accessors - var outputAccessor = _gltf.accessors[outputAccessorIndex]; - var channel = animationWithCurve.Animation.channels.First(x => x.sampler == kv.Key); - switch (glTFAnimationTarget.GetElementCount(channel.target.path)) - { - case 1: - outputAccessor.type = "SCALAR"; - //outputAccessor.count = ; - break; - case 3: - outputAccessor.type = "VEC3"; - outputAccessor.count /= 3; - break; - - case 4: - outputAccessor.type = "VEC4"; - outputAccessor.count /= 4; - break; - - default: - throw new NotImplementedException(); - } - } - animationWithCurve.Animation.name = clip.name; - _gltf.animations.Add(animationWithCurve.Animation); - } - } - public virtual void Export(ITextureSerializer textureSerializer) { Nodes = Copy.transform.Traverse() @@ -403,7 +328,11 @@ namespace UniGLTF } #endregion - ExportAnimations(); + if (m_settings.AnimationExporter != null) + { + ReportProgress("Animations", 0.9f); + m_settings.AnimationExporter.Export(_data, Copy, Nodes); + } ExportExtensions(textureSerializer); diff --git a/Assets/VRM/Runtime/IO/VRMExporter.cs b/Assets/VRM/Runtime/IO/VRMExporter.cs index 14e6e84f2..47178ed03 100644 --- a/Assets/VRM/Runtime/IO/VRMExporter.cs +++ b/Assets/VRM/Runtime/IO/VRMExporter.cs @@ -40,11 +40,6 @@ namespace VRM return new VRMMaterialExporter(); } - public override void ExportAnimations() - { - // do nothing - } - public override void ExportExtensions(ITextureSerializer textureSerializer) { // avatar