mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-05-11 21:14:19 -05:00
Merge pull request #1543 from ousttrue/fix/vrm_not_export_animations
VRM は Animation をエクスポートしない
This commit is contained in:
commit
0f584fb272
|
|
@ -236,6 +236,81 @@ namespace UniGLTF
|
|||
// do nothing
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// AnimationClip を収集する。
|
||||
/// </summary>
|
||||
List<AnimationClip> GetAnimationClips()
|
||||
{
|
||||
var clips = new List<AnimationClip>();
|
||||
var animator = Copy.GetComponent<Animator>();
|
||||
var animation = Copy.GetComponent<Animation>();
|
||||
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<AnimationClip>();
|
||||
var animator = Copy.GetComponent<Animator>();
|
||||
var animation = Copy.GetComponent<Animation>();
|
||||
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);
|
||||
|
||||
|
|
|
|||
|
|
@ -40,6 +40,11 @@ namespace VRM
|
|||
return new VRMMaterialExporter();
|
||||
}
|
||||
|
||||
public override void ExportAnimations()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
public override void ExportExtensions(ITextureSerializer textureSerializer)
|
||||
{
|
||||
// avatar
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user