diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/gltfExporter.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/gltfExporter.cs index 28b97b39c..8b7260964 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/gltfExporter.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/gltfExporter.cs @@ -236,6 +236,73 @@ 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() + { + 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() @@ -329,66 +396,9 @@ namespace UniGLTF #endregion #if UNITY_EDITOR - #region Animations - ReportProgress("Animations", 0.9f); - - 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); - } - - if (clips.Any()) - { - 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); - } - - } - #endregion + // 関連する一部の関数が Editor 専用のため、 + // Editor 時のみ Export する。 + ExportAnimations(); #endif ExportExtensions(textureSerializer); diff --git a/Assets/VRM/Runtime/IO/VRMExporter.cs b/Assets/VRM/Runtime/IO/VRMExporter.cs index 47178ed03..14e6e84f2 100644 --- a/Assets/VRM/Runtime/IO/VRMExporter.cs +++ b/Assets/VRM/Runtime/IO/VRMExporter.cs @@ -40,6 +40,11 @@ namespace VRM return new VRMMaterialExporter(); } + public override void ExportAnimations() + { + // do nothing + } + public override void ExportExtensions(ITextureSerializer textureSerializer) { // avatar