From 76c3c6dc2335bfa800af6f2657ac3b6b58b012f2 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Tue, 8 Jun 2021 18:10:28 +0900 Subject: [PATCH 1/3] =?UTF-8?q?IAnimationImporter=20=E3=82=92=E5=BB=83?= =?UTF-8?q?=E6=AD=A2=E3=81=97=E3=80=81=20virtual=20async=20Task=20Importer?= =?UTF-8?q?Context.LoadAnimationAsync=20=E3=82=92=E8=BF=BD=E5=8A=A0?= =?UTF-8?q?=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IO/AnimationIO/IAnimationImporter.cs | 11 ------- .../IO/AnimationIO/IAnimationImporter.cs.meta | 11 ------- .../IO/AnimationIO/RootAnimationImporter.cs | 12 ------- .../AnimationIO/RootAnimationImporter.cs.meta | 11 ------- .../Runtime/UniGLTF/IO/ImporterContext.cs | 33 ++++++------------- 5 files changed, 10 insertions(+), 68 deletions(-) delete mode 100644 Assets/UniGLTF/Runtime/UniGLTF/IO/AnimationIO/IAnimationImporter.cs delete mode 100644 Assets/UniGLTF/Runtime/UniGLTF/IO/AnimationIO/IAnimationImporter.cs.meta delete mode 100644 Assets/UniGLTF/Runtime/UniGLTF/IO/AnimationIO/RootAnimationImporter.cs delete mode 100644 Assets/UniGLTF/Runtime/UniGLTF/IO/AnimationIO/RootAnimationImporter.cs.meta diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/AnimationIO/IAnimationImporter.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/AnimationIO/IAnimationImporter.cs deleted file mode 100644 index 6e9a2f773..000000000 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/AnimationIO/IAnimationImporter.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Collections.Generic; -using UnityEngine; -using VRMShaders; - -namespace UniGLTF -{ - public interface IAnimationImporter - { - AnimationClip Import(glTF gltf, int i, Axes invertAxis); - } -} diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/AnimationIO/IAnimationImporter.cs.meta b/Assets/UniGLTF/Runtime/UniGLTF/IO/AnimationIO/IAnimationImporter.cs.meta deleted file mode 100644 index 83586e086..000000000 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/AnimationIO/IAnimationImporter.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 4f950ba9271cbff4cbc4345f5a23a5d8 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/AnimationIO/RootAnimationImporter.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/AnimationIO/RootAnimationImporter.cs deleted file mode 100644 index 980caec8a..000000000 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/AnimationIO/RootAnimationImporter.cs +++ /dev/null @@ -1,12 +0,0 @@ -using UnityEngine; - -namespace UniGLTF -{ - public sealed class RootAnimationImporter : IAnimationImporter - { - public AnimationClip Import(glTF gltf, int i, Axes invertAxis) - { - return AnimationImporterUtil.ConvertAnimationClip(gltf, gltf.animations[i], invertAxis.Create()); - } - } -} diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/AnimationIO/RootAnimationImporter.cs.meta b/Assets/UniGLTF/Runtime/UniGLTF/IO/AnimationIO/RootAnimationImporter.cs.meta deleted file mode 100644 index 2ea8cfbed..000000000 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/AnimationIO/RootAnimationImporter.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 27640e6274339664ea492827be5a2217 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs index f513391e3..04bb99268 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs @@ -12,26 +12,6 @@ namespace UniGLTF /// public class ImporterContext : IDisposable { - #region Animation - protected IAnimationImporter m_animationImporter; - public void SetAnimationImporter(IAnimationImporter animationImporter) - { - m_animationImporter = animationImporter; - } - public IAnimationImporter AnimationImporter - { - get - { - if (m_animationImporter == null) - { - m_animationImporter = new RootAnimationImporter(); - } - return m_animationImporter; - } - } - - #endregion - public ITextureDescriptorGenerator TextureDescriptorGenerator { get; protected set; } public IMaterialDescriptorGenerator MaterialDescriptorGenerator { get; protected set; } public TextureFactory TextureFactory { get; } @@ -121,6 +101,13 @@ namespace UniGLTF await LoadGeometryAsync(awaitCaller, MeasureTime); + await LoadAnimationAsync(awaitCaller, MeasureTime); + + await OnLoadHierarchy(awaitCaller, MeasureTime); + } + + protected virtual async Task LoadAnimationAsync(IAwaitCaller awaitCaller, Func MeasureTime) + { using (MeasureTime("AnimationImporter")) { if (GLTF.animations != null && GLTF.animations.Any()) @@ -136,7 +123,7 @@ namespace UniGLTF } else { - clip = AnimationImporter.Import(GLTF, i, InvertAxis); + clip = AnimationImporterUtil.ConvertAnimationClip(GLTF, GLTF.animations[i], InvertAxis.Create()); AnimationClips.Add(clip); } @@ -146,10 +133,10 @@ namespace UniGLTF animation.clip = clip; } } + + await awaitCaller.NextFrame(); } } - - await OnLoadHierarchy(awaitCaller, MeasureTime); } protected virtual async Task LoadGeometryAsync(IAwaitCaller awaitCaller, Func MeasureTime) From 8d02eec68e1f8585b637310bc880fd3dc7c080c1 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Tue, 8 Jun 2021 18:21:51 +0900 Subject: [PATCH 2/3] =?UTF-8?q?SetupAnimationsAsync=20=E3=82=92=E5=88=86?= =?UTF-8?q?=E9=9B=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Runtime/UniGLTF/IO/ImporterContext.cs | 69 ++++++++++++------- 1 file changed, 45 insertions(+), 24 deletions(-) diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs index 04bb99268..616afcda2 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs @@ -101,42 +101,63 @@ namespace UniGLTF await LoadGeometryAsync(awaitCaller, MeasureTime); - await LoadAnimationAsync(awaitCaller, MeasureTime); + using (MeasureTime("AnimationImporter")) + { + await LoadAnimationAsync(awaitCaller); + await SetupAnimationsAsync(awaitCaller); + } await OnLoadHierarchy(awaitCaller, MeasureTime); } - protected virtual async Task LoadAnimationAsync(IAwaitCaller awaitCaller, Func MeasureTime) + /// + /// ImporterContext.AnimationClips に AnimationClip を読み込むところまでが責務 + /// + /// + /// + protected virtual async Task LoadAnimationAsync(IAwaitCaller awaitCaller) { - using (MeasureTime("AnimationImporter")) + if (GLTF.animations != null && GLTF.animations.Any()) { - if (GLTF.animations != null && GLTF.animations.Any()) + for (int i = 0; i < GLTF.animations.Count; ++i) { - var animation = Root.AddComponent(); - for (int i = 0; i < GLTF.animations.Count; ++i) + var gltfAnimation = GLTF.animations[i]; + AnimationClip clip = default; + if (_externalObjectMap.TryGetValue(new SubAssetKey(typeof(AnimationClip), gltfAnimation.name), out UnityEngine.Object value)) { - var gltfAnimation = GLTF.animations[i]; - AnimationClip clip = default; - if (_externalObjectMap.TryGetValue(new SubAssetKey(typeof(AnimationClip), gltfAnimation.name), out UnityEngine.Object value)) - { - clip = value as AnimationClip; - } - else - { - clip = AnimationImporterUtil.ConvertAnimationClip(GLTF, GLTF.animations[i], InvertAxis.Create()); - AnimationClips.Add(clip); - } - - animation.AddClip(clip, clip.name); - if (i == 0) - { - animation.clip = clip; - } + clip = value as AnimationClip; } + else + { + clip = AnimationImporterUtil.ConvertAnimationClip(GLTF, GLTF.animations[i], InvertAxis.Create()); + AnimationClips.Add(clip); + } + } - await awaitCaller.NextFrame(); + await awaitCaller.NextFrame(); + } + } + + /// + /// AnimationClips を AnimationComponent に載せる + /// + protected virtual async Task SetupAnimationsAsync(IAwaitCaller awaitCaller) + { + if (AnimationClips.Count == 0) + { + return; + } + var animation = Root.AddComponent(); + for (int i = 0; i < AnimationClips.Count; ++i) + { + var clip = AnimationClips[i]; + animation.AddClip(clip, clip.name); + if (i == 0) + { + animation.clip = clip; } } + await awaitCaller.NextFrame(); } protected virtual async Task LoadGeometryAsync(IAwaitCaller awaitCaller, Func MeasureTime) From 098d0458a13faa17ad5b0a28d615b0c2ca059f9d Mon Sep 17 00:00:00 2001 From: ousttrue Date: Tue, 8 Jun 2021 18:22:06 +0900 Subject: [PATCH 3/3] remove waning --- .../VRM10/Runtime/Components/SpringBone/VRM10SpringBoneJoint.cs | 2 +- Assets/VRM10/Runtime/IO/Material/Vrm10MToonMaterialExporter.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringBoneJoint.cs b/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringBoneJoint.cs index 9ad55c194..3c8d4e44b 100644 --- a/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringBoneJoint.cs +++ b/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringBoneJoint.cs @@ -28,7 +28,7 @@ namespace UniVRM10 [SerializeField, Range(0, 0.5f), Header("Collision")] public float m_jointRadius = 0.02f; - SpringBoneLogic m_logic; + SpringBoneLogic m_logic = null; public void DrawGizmo(Transform center, Color color) { diff --git a/Assets/VRM10/Runtime/IO/Material/Vrm10MToonMaterialExporter.cs b/Assets/VRM10/Runtime/IO/Material/Vrm10MToonMaterialExporter.cs index c565911a5..407ea4515 100644 --- a/Assets/VRM10/Runtime/IO/Material/Vrm10MToonMaterialExporter.cs +++ b/Assets/VRM10/Runtime/IO/Material/Vrm10MToonMaterialExporter.cs @@ -141,7 +141,7 @@ namespace UniVRM10 return true; } - catch (Exception e) + catch (Exception) { dst = null; return false;