Merge pull request #1560 from ousttrue/fix/animation_export_build

AnimationExporter が原因で build に失敗する件を修正
This commit is contained in:
ousttrue
2022-02-28 17:43:13 +09:00
committed by GitHub
18 changed files with 159 additions and 105 deletions

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: cd3120ad83927864fa7b56ce619e60ba
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -2,9 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace UniGLTF
@@ -24,7 +22,6 @@ namespace UniGLTF
public Dictionary<int, InputOutputValues> SamplerMap = new Dictionary<int, InputOutputValues>();
}
#if UNITY_EDITOR
public static List<AnimationClip> GetAnimationClips(Animation animation)
{
var clips = new List<AnimationClip>();
@@ -122,7 +119,6 @@ namespace UniGLTF
Animation = new glTFAnimation(),
};
#if UNITY_5_6_OR_NEWER
List<AnimationCurveData> curveDatum = new List<AnimationCurveData>();
foreach (var binding in AnimationUtility.GetCurveBindings(clip))
@@ -160,7 +156,7 @@ namespace UniGLTF
}
// 同一のsamplerIndexが割り当てられているcurveDataがある場合はそれを使用し、無ければ作る
var curveData = curveDatum.FirstOrDefault(x => x.SamplerIndex == samplerIndex);
var curveData = curveDatum.FirstOrDefault(x => x.SamplerIndex == samplerIndex);
if (curveData == null)
{
curveData = new AnimationCurveData(AnimationUtility.GetKeyRightTangentMode(curve, 0), property, samplerIndex, elementCount);
@@ -218,10 +214,8 @@ namespace UniGLTF
keyframeIndex++;
}
}
#endif
return animation;
}
#endif
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 10bbffd95db4d7a4abb3d0e74f46f994
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 343050b608326344ebef0369448f8159
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -4,7 +4,7 @@ using UniGLTF.M17N;
using UnityEditor;
using UnityEngine;
namespace UniGLTF.Animation
namespace UniGLTF
{
public static class AnimationValidator
{

View 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);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 62c5fa8e50275804b8084f3764f9d8f3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,7 +1,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UniGLTF.Animation;
using UnityEditor;
using UnityEngine;
using VRMShaders;
@@ -104,9 +103,10 @@ namespace UniGLTF
EditorUtility.DisplayProgressBar("export gltf", path, progress);
try
{
var data = new ExportingGltfData();
using (var exporter = new gltfExporter(data, Settings, new EditorProgress()))
using (var exporter = new gltfExporter(data, Settings,
progress: new EditorProgress(),
animationExporter: new EditorAnimationExporter()))
{
exporter.Prepare(State.ExportRoot);
exporter.Export(new EditorTextureSerializer());

View File

@@ -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))
{

View File

@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 1af21722605d44f58deebfcfca642b32
timeCreated: 1537442711

View File

@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 015ae41bf6cb4428b8257ead79772908
timeCreated: 1537443293

View File

@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: e27ef4fb768e49f591c2bb5eadd3b19b
timeCreated: 1537442737

View File

@@ -0,0 +1,10 @@
using System.Collections.Generic;
using UnityEngine;
namespace UniGLTF
{
public interface IAnimationExporter
{
void Export(ExportingGltfData _data, GameObject Copy, List<Transform> Nodes);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7bcb89e584f47c34c9ad19bdce8ccad0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -79,7 +79,10 @@ namespace UniGLTF
m_progress.Report(new ExportProgress("gltfExporter", msg, progress));
}
public gltfExporter(ExportingGltfData data, GltfExportSettings settings, IProgress<ExportProgress> progress = null)
IAnimationExporter m_animationExporter;
public gltfExporter(ExportingGltfData data, GltfExportSettings settings, IProgress<ExportProgress> progress = null,
IAnimationExporter animationExporter = null)
{
_data = data;
@@ -97,6 +100,8 @@ namespace UniGLTF
// default
m_settings = new GltfExportSettings();
}
m_animationExporter = animationExporter;
}
GameObject m_tmpParent = null;
@@ -236,81 +241,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 +333,11 @@ namespace UniGLTF
}
#endregion
ExportAnimations();
if (m_animationExporter != null)
{
ReportProgress("Animations", 0.9f);
m_animationExporter.Export(_data, Copy, Nodes);
}
ExportExtensions(textureSerializer);

View File

@@ -40,11 +40,6 @@ namespace VRM
return new VRMMaterialExporter();
}
public override void ExportAnimations()
{
// do nothing
}
public override void ExportExtensions(ITextureSerializer textureSerializer)
{
// avatar