diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/gltfExporter.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/gltfExporter.cs
index 28b97b39c..4d0ebd261 100644
--- a/Assets/UniGLTF/Runtime/UniGLTF/IO/gltfExporter.cs
+++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/gltfExporter.cs
@@ -236,6 +236,81 @@ 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()
@@ -328,68 +403,7 @@ 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
-#endif
+ ExportAnimations();
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