Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IAnimationImporter を廃止 #1014

Merged
merged 3 commits into from
Jun 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

90 changes: 49 additions & 41 deletions Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,6 @@ namespace UniGLTF
/// </summary>
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; }
Expand Down Expand Up @@ -123,33 +103,61 @@ public virtual async Task LoadAsync(IAwaitCaller awaitCaller = null, Func<string

using (MeasureTime("AnimationImporter"))
{
if (GLTF.animations != null && GLTF.animations.Any())
await LoadAnimationAsync(awaitCaller);
await SetupAnimationsAsync(awaitCaller);
}

await OnLoadHierarchy(awaitCaller, MeasureTime);
}

/// <summary>
/// ImporterContext.AnimationClips に AnimationClip を読み込むところまでが責務
/// </summary>
/// <param name="awaitCaller"></param>
/// <returns></returns>
protected virtual async Task LoadAnimationAsync(IAwaitCaller awaitCaller)
{
if (GLTF.animations != null && GLTF.animations.Any())
{
for (int i = 0; i < GLTF.animations.Count; ++i)
{
var animation = Root.AddComponent<Animation>();
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))
{
clip = value as AnimationClip;
}
else
{
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 = AnimationImporter.Import(GLTF, i, InvertAxis);
AnimationClips.Add(clip);
}

animation.AddClip(clip, clip.name);
if (i == 0)
{
animation.clip = clip;
}
clip = AnimationImporterUtil.ConvertAnimationClip(GLTF, GLTF.animations[i], InvertAxis.Create());
AnimationClips.Add(clip);
}
}

await awaitCaller.NextFrame();
}
}

await OnLoadHierarchy(awaitCaller, MeasureTime);
/// <summary>
/// AnimationClips を AnimationComponent に載せる
/// </summary>
protected virtual async Task SetupAnimationsAsync(IAwaitCaller awaitCaller)
{
if (AnimationClips.Count == 0)
{
return;
}
var animation = Root.AddComponent<Animation>();
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<string, IDisposable> MeasureTime)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class VRM10SpringBoneJoint : MonoBehaviour
[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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public static bool TryExportMaterialAsMToon(Material src, ITextureExporter textu

return true;
}
catch (Exception e)
catch (Exception)
{
dst = null;
return false;
Expand Down