mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-05-15 07:00:10 -05:00
EditorAnimationExporter
This commit is contained in:
parent
551a828083
commit
e19ab9808a
11
Assets/UniGLTF/Editor/Animation/AnimationCurveData.cs.meta
Normal file
11
Assets/UniGLTF/Editor/Animation/AnimationCurveData.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: cd3120ad83927864fa7b56ce619e60ba
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
11
Assets/UniGLTF/Editor/Animation/AnimationExporter.cs.meta
Normal file
11
Assets/UniGLTF/Editor/Animation/AnimationExporter.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 10bbffd95db4d7a4abb3d0e74f46f994
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 343050b608326344ebef0369448f8159
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -4,7 +4,7 @@ using UniGLTF.M17N;
|
|||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UniGLTF.Animation
|
||||
namespace UniGLTF
|
||||
{
|
||||
public static class AnimationValidator
|
||||
{
|
||||
|
|
|
|||
75
Assets/UniGLTF/Editor/Animation/EditorAnimationExporter.cs
Normal file
75
Assets/UniGLTF/Editor/Animation/EditorAnimationExporter.cs
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UniGLTF
|
||||
{
|
||||
public class EditorAnimationExporter : IAnimationExporter
|
||||
{
|
||||
/// <summary>
|
||||
/// AnimationClip を収集する。
|
||||
/// </summary>
|
||||
static List<AnimationClip> GetAnimationClips(GameObject Copy)
|
||||
{
|
||||
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 void Export(ExportingGltfData _data, GameObject Copy, List<Transform> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 62c5fa8e50275804b8084f3764f9d8f3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,3 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1af21722605d44f58deebfcfca642b32
|
||||
timeCreated: 1537442711
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 015ae41bf6cb4428b8257ead79772908
|
||||
timeCreated: 1537443293
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e27ef4fb768e49f591c2bb5eadd3b19b
|
||||
timeCreated: 1537442737
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UniGLTF
|
||||
{
|
||||
public interface IAnimationExporter
|
||||
{
|
||||
void Export(ExportingGltfData _data, GameObject Copy, List<Transform> Nodes);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7bcb89e584f47c34c9ad19bdce8ccad0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -45,5 +45,7 @@ namespace UniGLTF
|
|||
/// Keep VertexColor
|
||||
/// </summary>
|
||||
public bool KeepVertexColor;
|
||||
|
||||
public IAnimationExporter AnimationExporter;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -236,81 +236,6 @@ 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()
|
||||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -40,11 +40,6 @@ 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