/// <summary> /// Root ヒエラルキーで使っているリソース /// </summary> /// <returns></returns> public virtual void TransferOwnership(TakeResponsibilityForDestroyObjectFunc take) { foreach (var mesh in Meshes.ToArray()) { take(SubAssetKey.Create(mesh.Mesh), mesh.Mesh); Meshes.Remove(mesh); } AnimationClipFactory.TransferOwnership(take); TextureFactory.TransferOwnership(take); MaterialFactory.TransferOwnership(take); }
/// <summary> /// ImporterContextが所有する UnityEngine.Object を破棄する /// </summary> public virtual void Dispose() { foreach (var x in Meshes) { UnityObjectDestoyer.DestroyRuntimeOrEditor(x.Mesh); } Meshes.Clear(); AnimationClipFactory?.Dispose(); MaterialFactory?.Dispose(); TextureFactory?.Dispose(); }
public virtual async Task LoadAnimationAsync(IAwaitCaller awaitCaller) { if (GLTF.animations != null && GLTF.animations.Any()) { foreach (var(key, gltfAnimation) in Enumerable.Zip(AnimationImporterUtil.EnumerateSubAssetKeys(GLTF), GLTF.animations, (x, y) => (x, y))) { await AnimationClipFactory.LoadAnimationClipAsync(key, async() => { return(AnimationImporterUtil.ConvertAnimationClip(GLTF, gltfAnimation, InvertAxis.Create())); }); } await awaitCaller.NextFrame(); } }
/// <summary> /// AnimationClips を AnimationComponent に載せる /// </summary> protected virtual async Task SetupAnimationsAsync(IAwaitCaller awaitCaller) { if (AnimationClipFactory.LoadedClipKeys.Count == 0) { return; } var animation = Root.AddComponent <Animation>(); for (var clipIdx = 0; clipIdx < AnimationClipFactory.LoadedClipKeys.Count; ++clipIdx) { var key = AnimationClipFactory.LoadedClipKeys[clipIdx]; var clip = AnimationClipFactory.GetAnimationClip(key); animation.AddClip(clip, key.Name); if (clipIdx == 0) { animation.clip = clip; } } await awaitCaller.NextFrame(); }
public ImporterContext( GltfData data, IReadOnlyDictionary <SubAssetKey, UnityEngine.Object> externalObjectMap = null, ITextureDeserializer textureDeserializer = null) { Data = data; TextureDescriptorGenerator = new GltfTextureDescriptorGenerator(Data); MaterialDescriptorGenerator = new GltfMaterialDescriptorGenerator(); ExternalObjectMap = externalObjectMap ?? new Dictionary <SubAssetKey, UnityEngine.Object>(); textureDeserializer = textureDeserializer ?? new UnityTextureDeserializer(); TextureFactory = new TextureFactory(textureDeserializer, ExternalObjectMap .Where(x => x.Value is Texture) .ToDictionary(x => x.Key, x => (Texture)x.Value), Data.MigrationFlags.IsRoughnessTextureValueSquared); MaterialFactory = new MaterialFactory(ExternalObjectMap .Where(x => x.Value is Material) .ToDictionary(x => x.Key, x => (Material)x.Value)); AnimationClipFactory = new AnimationClipFactory(ExternalObjectMap .Where(x => x.Value is AnimationClip) .ToDictionary(x => x.Key, x => (AnimationClip)x.Value)); }