From 292a15bbf66a108a34d60ddf402f67446c533638 Mon Sep 17 00:00:00 2001 From: Michael Winsor Date: Wed, 11 May 2022 14:53:56 -0600 Subject: [PATCH] [Editor API] - Exposed texture overrides for animations to the content loader public interface. --- .../_Interfaces/IGorgonContentLoader.cs | 8 ++++- .../Gorgon2D/_Internal/ContentLoader2D.cs | 34 +++++++++++++++---- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/Tools/Editor/Gorgon.Editor.API/Gorgon2D/_Interfaces/IGorgonContentLoader.cs b/Tools/Editor/Gorgon.Editor.API/Gorgon2D/_Interfaces/IGorgonContentLoader.cs index 581bf4eac..4c080446a 100644 --- a/Tools/Editor/Gorgon.Editor.API/Gorgon2D/_Interfaces/IGorgonContentLoader.cs +++ b/Tools/Editor/Gorgon.Editor.API/Gorgon2D/_Interfaces/IGorgonContentLoader.cs @@ -175,6 +175,7 @@ GorgonTextureCache TextureCache /// Function to load an animation from the editor file system. /// /// The path to the animation content. + /// [Optional] The textures used to override the textures for a texture track in the animation. /// A new containing the animation data from the file system. /// /// @@ -185,6 +186,11 @@ GorgonTextureCache TextureCache /// Doing this will allow a user to create a custom image codec plug in and use that to read animation data. /// /// + /// When the contains a list of textures, the loader will override any matching textures in any texture tracks within the animation. This allows user defined pre + /// loading of texture data for an animation. The textures in the list will be matched by name to the key . If the + /// texture is matched with one from the override list, then it will be used for the key. Otherwise, the codec will load the appropriate texture via other means. + /// + /// ///

Technical info

/// /// Plug ins must generate the following metadata for the files in the editor file system. @@ -195,7 +201,7 @@ GorgonTextureCache TextureCache /// ///
///
- Task LoadAnimationAsync(string path); + Task LoadAnimationAsync(string path, IEnumerable textureOverrides = null); /// /// Function to load an image as a texture from the editor file system. diff --git a/Tools/Editor/Gorgon.Editor.API/Gorgon2D/_Internal/ContentLoader2D.cs b/Tools/Editor/Gorgon.Editor.API/Gorgon2D/_Internal/ContentLoader2D.cs index 34cfa8f14..79d20236d 100644 --- a/Tools/Editor/Gorgon.Editor.API/Gorgon2D/_Internal/ContentLoader2D.cs +++ b/Tools/Editor/Gorgon.Editor.API/Gorgon2D/_Internal/ContentLoader2D.cs @@ -308,6 +308,7 @@ public IReadOnlyDictionary GetFileAttributes(string path) /// Function to load an animation from the editor file system. /// /// The path to the animation content. + /// [Optional] The textures used to override the textures for a texture track in the animation. /// A new containing the animation data from the file system. /// Thrown when the parameter is null. /// Thrown when the parameter is empty. @@ -321,6 +322,11 @@ public IReadOnlyDictionary GetFileAttributes(string path) /// Doing this will allow a user to create a custom image codec plug in and use that to read animation data. /// /// + /// When the contains a list of textures, the loader will override any matching textures in any texture tracks within the animation. This allows user defined pre + /// loading of texture data for an animation. The textures in the list will be matched by name to the key . If the + /// texture is matched with one from the override list, then it will be used for the key. Otherwise, the codec will load the appropriate texture via other means. + /// + /// ///

Technical info

/// /// Plug ins must generate the following metadata for the files in the editor file system. @@ -331,7 +337,7 @@ public IReadOnlyDictionary GetFileAttributes(string path) /// ///
/// - public async Task LoadAnimationAsync(string path) + public async Task LoadAnimationAsync(string path, IEnumerable textureOverrides = null) { if (path is null) { @@ -371,20 +377,36 @@ public async Task LoadAnimationAsync(string path) _graphics.Log.Print($"Loading animation '{path}'...", LoggingLevel.Verbose); - IEnumerable textures = null; - if ((metadata.DependsOn.TryGetValue(CommonEditorContentTypes.ImageType, out List paths)) && (paths is not null) && (paths.Count > 0)) { - IEnumerable> dependencyTasks = paths.Select(item => TextureCache.GetTextureAsync(item, ReadTextureAsync)); + IEnumerable> dependencyTasks; + + if ((textureOverrides is null) || (!textureOverrides.Any())) + { + dependencyTasks = paths.Select(item => TextureCache.GetTextureAsync(item, ReadTextureAsync)); + } + else + { + dependencyTasks = paths.Except(textureOverrides.Select(item => item.Texture.Name)) + .Select(item => TextureCache.GetTextureAsync(item, ReadTextureAsync)); + } + await Task.WhenAll(dependencyTasks); - textures = dependencyTasks.Select(item => item.Result.GetShaderResourceView()); + if (textureOverrides is null) + { + textureOverrides = dependencyTasks.Select(item => item.Result.GetShaderResourceView()); + } + else + { + textureOverrides = textureOverrides.Concat(dependencyTasks.Select(item => item.Result.GetShaderResourceView())); + } } using Stream stream = animationFile.OpenStream(); - return animationCodec.FromStream(stream, textureOverrides: textures); + return animationCodec.FromStream(stream, textureOverrides: textureOverrides); } ///