From 4c417c035ff6c67b772ca15541535be9e74be2b7 Mon Sep 17 00:00:00 2001 From: TheRed Games <30622829+TheLLspectre@users.noreply.github.com> Date: Fri, 28 Jun 2024 09:14:33 +0200 Subject: [PATCH 1/2] feat: scenario tab created (#189) fix: auto refreshing when image, models are loaded --- package/Editor/CompositionEditor/CompositionEditor.cs | 2 +- package/Editor/DataBuilder/DataBuilder.cs | 2 +- package/Editor/ImageEditor/ImageEditor.cs | 2 +- package/Editor/Images/Images.cs | 3 ++- package/Editor/InpaintingEditor/InpaintingEditor.cs | 2 +- package/Editor/Isometric Workflow/IsometricWorkflow.cs | 3 ++- package/Editor/LayerEditor/LayerEditor.cs | 2 +- package/Editor/Models/Models.cs | 5 ++++- package/Editor/PixelEditor/PixelEditor.cs | 2 +- package/Editor/Plugins/APIPricing.cs | 2 +- package/Editor/PromptWindow/PromptBuilderWindow.cs | 2 +- package/Editor/PromptWindow/PromptWindow.cs | 2 +- package/Editor/Settings/PluginSettings.cs | 2 +- package/Editor/UpscaleEditor/UpscaleEditor.cs | 2 +- 14 files changed, 19 insertions(+), 14 deletions(-) diff --git a/package/Editor/CompositionEditor/CompositionEditor.cs b/package/Editor/CompositionEditor/CompositionEditor.cs index 6170dea..5405ae3 100644 --- a/package/Editor/CompositionEditor/CompositionEditor.cs +++ b/package/Editor/CompositionEditor/CompositionEditor.cs @@ -18,7 +18,7 @@ public class CompositionEditor : EditorWindow internal RenderTexture renderTexture; private Texture2D screenshot; - [MenuItem("Window/Scenario/Editors/Composition Editor", false,0)] + [MenuItem("Scenario/Editors/Composition Editor", false,0)] public static void ShowWindow() { var window = GetWindow("Composition Editor"); diff --git a/package/Editor/DataBuilder/DataBuilder.cs b/package/Editor/DataBuilder/DataBuilder.cs index 882a9f7..7cba62b 100644 --- a/package/Editor/DataBuilder/DataBuilder.cs +++ b/package/Editor/DataBuilder/DataBuilder.cs @@ -25,7 +25,7 @@ private enum ScreenshotType private float cameraDistance = 2f; private float lightDistance = 2f; - [MenuItem("Window/Scenario/Builders/3D Data Builder", false, 0)] + [MenuItem("Scenario/Builders/3D Data Builder", false, 0)] public static void ShowWindow() { GetWindow("3d Data Builder"); diff --git a/package/Editor/ImageEditor/ImageEditor.cs b/package/Editor/ImageEditor/ImageEditor.cs index 65d39d2..05be0f3 100644 --- a/package/Editor/ImageEditor/ImageEditor.cs +++ b/package/Editor/ImageEditor/ImageEditor.cs @@ -10,7 +10,7 @@ public class ImageEditor : EditorWindow private static float minimumWidth = 1775f; - [MenuItem("Window/Scenario/Editors/Image Editor", false, 1)] + [MenuItem("Scenario/Editors/Image Editor", false, 1)] public static void ShowWindow() { ImageEditor window = GetWindow("Image Editor"); diff --git a/package/Editor/Images/Images.cs b/package/Editor/Images/Images.cs index 5a8aac5..74a45f9 100644 --- a/package/Editor/Images/Images.cs +++ b/package/Editor/Images/Images.cs @@ -34,7 +34,7 @@ public class Images : EditorWindow /// internal static string cdnExtension = "&format=jpeg&quality=80&width=256"; - [MenuItem("Window/Scenario/Images", false, 10)] + [MenuItem("Scenario/Images", false, 10)] public static void ShowWindow() { if (isVisible) @@ -46,6 +46,7 @@ public static void ShowWindow() GetInferencesData(); var images = (Images)GetWindow(typeof(Images)); + images.autoRepaintOnSceneChange = true; ImagesUI.Init(images); } diff --git a/package/Editor/InpaintingEditor/InpaintingEditor.cs b/package/Editor/InpaintingEditor/InpaintingEditor.cs index b1cc519..7410c6e 100644 --- a/package/Editor/InpaintingEditor/InpaintingEditor.cs +++ b/package/Editor/InpaintingEditor/InpaintingEditor.cs @@ -9,7 +9,7 @@ public class InpaintingEditor : EditorWindow private static InpaintingEditorUI inpaintingEditorUI; private static Texture2D inpaintingTexture; - [MenuItem("Window/Scenario/Editors/Inpainting Editor", false, 2)] + [MenuItem("Scenario/Editors/Inpainting Editor", false, 2)] public static void ShowWindow() { InpaintingEditor window = GetWindow("Inpainting Editor"); diff --git a/package/Editor/Isometric Workflow/IsometricWorkflow.cs b/package/Editor/Isometric Workflow/IsometricWorkflow.cs index aa0db93..973f3ea 100644 --- a/package/Editor/Isometric Workflow/IsometricWorkflow.cs +++ b/package/Editor/Isometric Workflow/IsometricWorkflow.cs @@ -156,7 +156,7 @@ public class IsometricWorkflow : EditorWindow #endregion - [MenuItem("Window/Scenario/Workflows/1. Isometric Workflow")] + [MenuItem("Scenario/Workflows/1. Isometric Workflow")] public static void ShowWindow() { if (isVisible) @@ -165,6 +165,7 @@ public static void ShowWindow() InferenceManager.SilenceMode = true; var isometricWorkflow = GetWindow("Isometric Workflow"); + isometricWorkflow.autoRepaintOnSceneChange = true; isometricWorkflow.minSize = new Vector2(1024, 625); if (isometricWorkflow.isometricStartScreen == null) diff --git a/package/Editor/LayerEditor/LayerEditor.cs b/package/Editor/LayerEditor/LayerEditor.cs index 8b895c4..3366777 100644 --- a/package/Editor/LayerEditor/LayerEditor.cs +++ b/package/Editor/LayerEditor/LayerEditor.cs @@ -40,7 +40,7 @@ public class LayerEditor : EditorWindow private LayerEditorRightPanel rightPanel; private ContextMenuActions contextMenuActions; - [MenuItem("Window/Scenario/Editors/Layer Editor", false, 3)] + [MenuItem("Scenario/Editors/Layer Editor", false, 3)] public static void ShowWindow() { GetWindow("Layer Editor"); diff --git a/package/Editor/Models/Models.cs b/package/Editor/Models/Models.cs index be7cff2..e5e88a1 100644 --- a/package/Editor/Models/Models.cs +++ b/package/Editor/Models/Models.cs @@ -88,6 +88,7 @@ private void OnGUI() private void OnEnable() { + ShowWindow(); SetTab(privacyQuickStart); } @@ -96,14 +97,16 @@ private void OnDestroy() isProcessing = false; } + #endregion #region Public Methods - [MenuItem("Window/Scenario/Models", false, 11)] + [MenuItem("Scenario/Models", false, 11)] public static void ShowWindow() { window = GetWindow("Models"); + window.autoRepaintOnSceneChange = true; window.minSize = new Vector2(MinimumWidth, window.minSize.y); } diff --git a/package/Editor/PixelEditor/PixelEditor.cs b/package/Editor/PixelEditor/PixelEditor.cs index ec93db8..659b2af 100644 --- a/package/Editor/PixelEditor/PixelEditor.cs +++ b/package/Editor/PixelEditor/PixelEditor.cs @@ -8,7 +8,7 @@ public class PixelEditor : EditorWindow private static readonly float MinimumWidth = 1650f; private PixelEditorUI pixelEditorUI = new(); - [MenuItem("Window/Scenario/Editors/Pixel Editor", false, 4)] + [MenuItem("Scenario/Editors/Pixel Editor", false, 4)] public static void ShowWindow() { var window = EditorWindow.GetWindow(typeof(PixelEditor), false, "Pixel Editor") as PixelEditor; diff --git a/package/Editor/Plugins/APIPricing.cs b/package/Editor/Plugins/APIPricing.cs index 206fc24..002c27a 100644 --- a/package/Editor/Plugins/APIPricing.cs +++ b/package/Editor/Plugins/APIPricing.cs @@ -5,7 +5,7 @@ namespace Scenario.Editor { public class APIPricingWindow : EditorWindow { - [MenuItem("Window/Scenario/API Pricing", false, 101)] + [MenuItem("Scenario/API Pricing", false, 101)] public static void ShowWindow() { Application.OpenURL("https://docs.scenario.com/page/api-pricing"); diff --git a/package/Editor/PromptWindow/PromptBuilderWindow.cs b/package/Editor/PromptWindow/PromptBuilderWindow.cs index a98766a..a9cb702 100644 --- a/package/Editor/PromptWindow/PromptBuilderWindow.cs +++ b/package/Editor/PromptWindow/PromptBuilderWindow.cs @@ -25,7 +25,7 @@ public class PromptBuilderWindow : EditorWindow public static Action onReturn; public static PromptBuilderWindow Instance; - [MenuItem("Window/Scenario/Builders/Prompt Builder", false, 1)] + [MenuItem("Scenario/Builders/Prompt Builder", false, 1)] public static void ShowWindow() { Instance = GetWindow("Prompt Builder"); diff --git a/package/Editor/PromptWindow/PromptWindow.cs b/package/Editor/PromptWindow/PromptWindow.cs index 9f2dcb7..eba8878 100644 --- a/package/Editor/PromptWindow/PromptWindow.cs +++ b/package/Editor/PromptWindow/PromptWindow.cs @@ -16,7 +16,7 @@ public class PromptWindow : EditorWindow private CreationMode activeMode = null; - [MenuItem("Window/Scenario/Prompt Window", false, 5)] + [MenuItem("Scenario/Prompt Window", false, 5)] public static void ShowWindow() { var promptWindow = GetWindow("Prompt Window"); diff --git a/package/Editor/Settings/PluginSettings.cs b/package/Editor/Settings/PluginSettings.cs index 189a065..1c1fedf 100644 --- a/package/Editor/Settings/PluginSettings.cs +++ b/package/Editor/Settings/PluginSettings.cs @@ -89,7 +89,7 @@ private void OnEnable() } } - [MenuItem("Window/Scenario/Scenario Settings", false, 100)] + [MenuItem("Scenario/Scenario Settings", false, 100)] public static void ShowWindow() { GetWindow("Scenario Settings"); diff --git a/package/Editor/UpscaleEditor/UpscaleEditor.cs b/package/Editor/UpscaleEditor/UpscaleEditor.cs index 6df688e..b5cc216 100644 --- a/package/Editor/UpscaleEditor/UpscaleEditor.cs +++ b/package/Editor/UpscaleEditor/UpscaleEditor.cs @@ -8,7 +8,7 @@ public class UpscaleEditor : EditorWindow private static readonly float MinimumWidth = 1650f; private static readonly UpscaleEditorUI UpscaleEditorUI = new(); - [MenuItem("Window/Scenario/Editors/Upscale Editor", false, 5)] + [MenuItem("Scenario/Editors/Upscale Editor", false, 5)] public static void ShowWindow() { var window = EditorWindow.GetWindow(typeof(UpscaleEditor), false, "Upscale Editor") as UpscaleEditor; From 9710962e598642fee865b5c382bd0a03cc0f138d Mon Sep 17 00:00:00 2001 From: TheRed Games <30622829+TheLLspectre@users.noreply.github.com> Date: Fri, 28 Jun 2024 11:13:44 +0200 Subject: [PATCH 2/2] fix: update upscale editor (#188) * fix: update scale editor interface * fix: get asset id then upscale and get the result * fix: documentation on edit code * fix: resizing and photorealistic * fix: 3d rendered and photo * fix: auto refresh on upscale * fix: add loading placeholder on upscale image --- package/Editor/Images/ImagesUI.cs | 2 +- package/Editor/UpscaleEditor/UpscaleEditor.cs | 172 ++++++++++- .../Editor/UpscaleEditor/UpscaleEditorUI.cs | 284 +++++++++++++----- 3 files changed, 385 insertions(+), 73 deletions(-) diff --git a/package/Editor/Images/ImagesUI.cs b/package/Editor/Images/ImagesUI.cs index 28ca46d..97de71a 100644 --- a/package/Editor/Images/ImagesUI.cs +++ b/package/Editor/Images/ImagesUI.cs @@ -183,7 +183,7 @@ private void InitializeButtons() }, { "Upscale Image", () => { CommonUtils.FetchTextureFromURL(Images.GetImageDataById(selectedTextureId).Url, response => { - UpscaleEditor.ShowWindow(response, Images.GetImageDataById(selectedTextureId)); + UpscaleEditor.UpscaleEditor.ShowWindow(response, Images.GetImageDataById(selectedTextureId)); }); } }, diff --git a/package/Editor/UpscaleEditor/UpscaleEditor.cs b/package/Editor/UpscaleEditor/UpscaleEditor.cs index b5cc216..ce09b1a 100644 --- a/package/Editor/UpscaleEditor/UpscaleEditor.cs +++ b/package/Editor/UpscaleEditor/UpscaleEditor.cs @@ -1,18 +1,32 @@ +using Newtonsoft.Json; +using System; +using System.Collections; +using System.Collections.Generic; +using Unity.EditorCoroutines.Editor; using UnityEditor; using UnityEngine; -namespace Scenario.Editor +namespace Scenario.Editor.UpscaleEditor { public class UpscaleEditor : EditorWindow { - private static readonly float MinimumWidth = 1650f; + #region Public Fields + #endregion + + #region Private Fields + private static readonly UpscaleEditorUI UpscaleEditorUI = new(); + #endregion + + #region MonoBehaviourCallback + [MenuItem("Scenario/Editors/Upscale Editor", false, 5)] public static void ShowWindow() { var window = EditorWindow.GetWindow(typeof(UpscaleEditor), false, "Upscale Editor") as UpscaleEditor; - window.minSize = new Vector2(MinimumWidth, window.minSize.y); + window.autoRepaintOnSceneChange = true; + window.minSize = new Vector2(720, 540); } public static void ShowWindow(Texture2D selectedTexture, ImageDataStorage.ImageData imageData) @@ -25,11 +39,163 @@ public static void ShowWindow(Texture2D selectedTexture, ImageDataStorage.ImageD private void OnGUI() { UpscaleEditorUI.OnGUI(this.position); + UpscaleEditorUI.UpscaleEditor = this; } private void OnDestroy() { UpscaleEditorUI.currentImage = null; } + + #endregion + + #region Public Methods + + /// + /// Trigger the coroutine to get the upscale result. + /// + /// + /// + public void LaunchProgressUpscale(string _jobId, Action _answer) + { + if (!string.IsNullOrEmpty(_jobId)) + { + EditorCoroutineUtility.StartCoroutineOwnerless(GetProgressUpscale(_jobId, _answer)); + } + } + + #endregion + + #region Private Methods + + /// + /// Editor Coroutine to processing upscale. + /// Get the progress of the job id and wait the success status. + /// + /// JobId to listen + /// Return the result of the content at the end of the process + /// + IEnumerator GetProgressUpscale(string _jobId, Action _response) + { + bool inProgress = true; + + while (inProgress) + { + if (inProgress) + { + ApiClient.RestGet($"jobs/{_jobId}", response => + { + var progressResponse = JsonConvert.DeserializeObject(response.Content); + + if (progressResponse != null) + { + if (!string.IsNullOrEmpty(progressResponse.job.status)) + { + if (!progressResponse.job.status.Equals("success")) + { + switch (progressResponse.job.status) + { + case "warming-up": + Debug.Log("Upscale in preparation... wait..."); + break; + + case "queued": + Debug.Log("Upscale in queue... wait ..."); + break; + + case "in-progress": + Debug.Log("Upscale in progress... wait..."); + break; + + default: + Debug.Log("Upscale... wait..."); + break; + } + inProgress = true; + } + else + { + Debug.Log("Upscale progress done: " + response.Content); + inProgress = false; + _response?.Invoke(response.Content); + return; + } + } + } + }); + yield return new WaitForSecondsRealtime(4); + } + else + { + yield break; + } + } + + yield return null; + } + + #endregion + } + + #region API_DTO + + /// + /// Asset result object + /// + public class Asset + { + public string id { get; set; } + public string url { get; set; } + public string mimeType { get; set; } + public Metadata metadata { get; set; } + public string ownerId { get; set; } + public string authorId { get; set; } + public DateTime createdAt { get; set; } + public DateTime updatedAt { get; set; } + public string privacy { get; set; } + public List tags { get; set; } + public List collectionIds { get; set; } + } + + /// + /// Job result object + /// + public class Job + { + public string jobId { get; set; } + public string jobType { get; set; } + public string status { get; set; } + public float progress { get; set; } + public Metadata metadata { get; set; } + } + + /// + /// Metadata result object + /// + public class Metadata + { + public string type { get; set; } + public string preset { get; set; } + public string parentId { get; set; } + public string rootParentId { get; set; } + public string kind { get; set; } + public string[] assetIds { get; set; } + public int scalingFactor { get; set; } + public bool magic { get; set; } + public bool forceFaceRestoration { get; set; } + public bool photorealist { get; set; } + } + + /// + /// Root object to be deserialized from json. + /// + public class Root + { + public Asset asset { get; set; } + public Job job { get; set; } + public string image { get; set; } + } + + #endregion } \ No newline at end of file diff --git a/package/Editor/UpscaleEditor/UpscaleEditorUI.cs b/package/Editor/UpscaleEditor/UpscaleEditorUI.cs index 3345fae..b5aa1fe 100644 --- a/package/Editor/UpscaleEditor/UpscaleEditorUI.cs +++ b/package/Editor/UpscaleEditor/UpscaleEditorUI.cs @@ -1,36 +1,87 @@ +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.IO; -using Newtonsoft.Json; using UnityEditor; using UnityEngine; -namespace Scenario.Editor +namespace Scenario.Editor.UpscaleEditor { public class UpscaleEditorUI { + #region Public Fields + public static Texture2D currentImage = null; + public static ImageDataStorage.ImageData imageData = null; - + + public UpscaleEditor UpscaleEditor { get { return upscaleEditor; } set { upscaleEditor = value; } } + + #endregion + + #region Private Fields + private static List imageDataList = new(); + /// + /// Reference object to the upscale editor parent class. + /// + private UpscaleEditor upscaleEditor = null; + private List upscaledImages = new(); + private Texture2D selectedTexture = null; + private Vector2 scrollPosition = Vector2.zero; private string imageDataUrl = ""; - private string assetId = ""; + + private string assetId = string.Empty; private bool returnImage = true; - private bool forceFaceRestoration = false; - private bool usePhotorealisticModel = false; - + + /// + /// Default scaling factor + /// private int scalingFactor = 2; + + /// + /// Style selected on the upscale + /// + private string styleSelected = "Standard"; + + /// + /// Preset selected on the upscale + /// + private string presetSelected = "Balanced"; + + /// + /// All style available in upscale + /// + private string[] styleChoices = new string[] + { + "Standard", + "Cartoon", + "Anime", + "Comic", + "Minimalist", + "Photorealistic", + "3D Rendered" + }; + + /// + /// Flag of the style selected + /// + private int styleFlag = 0; + private int itemsPerRow = 1; private readonly float padding = 10f; + private readonly float leftSectionWidth = 150; + #endregion + public void OnGUI(Rect position) { DrawBackground(position); @@ -65,35 +116,76 @@ private void DrawRightSection(Rect position) Rect rect = GUILayoutUtility.GetRect(leftSectionWidth, leftSectionWidth, GUILayout.Width(300), GUILayout.Height(300)); GUI.DrawTexture(rect, currentImage, ScaleMode.ScaleToFit); - EditorStyle.Button("Clear Image", ()=>currentImage = null); + EditorStyle.Button("Clear Image", ()=> + { + currentImage = null; + assetId = string.Empty; + }); } EditorStyle.Label("Upscale Image Options", bold: true); + styleFlag = EditorGUILayout.Popup("Style: ", styleFlag, styleChoices); + styleSelected = styleChoices[styleFlag]; + + EditorStyle.Label("Scaling Factor:"); GUILayout.BeginHorizontal(); { - EditorStyle.Label("Scaling Factor:"); - if (GUILayout.Toggle(scalingFactor == 2, "2", EditorStyles.miniButtonLeft)) + if (GUILayout.Toggle(scalingFactor == 2, "2x", EditorStyles.miniButtonLeft)) { scalingFactor = 2; } - if (GUILayout.Toggle(scalingFactor == 4, "4", EditorStyles.miniButtonRight)) + if (GUILayout.Toggle(scalingFactor == 4, "4x", EditorStyles.miniButtonRight)) { scalingFactor = 4; } + + if (GUILayout.Toggle(scalingFactor == 8, "8x", EditorStyles.miniButtonRight)) + { + scalingFactor = 8; + } + + if (GUILayout.Toggle(scalingFactor == 16, "16x", EditorStyles.miniButtonRight)) + { + scalingFactor = 16; + } } GUILayout.EndHorizontal(); - forceFaceRestoration = EditorGUILayout.Toggle("Force Face Restoration", forceFaceRestoration); - usePhotorealisticModel = EditorGUILayout.Toggle("Use Photorealistic Model", usePhotorealisticModel); + CustomStyle.Space(25); + + EditorStyle.Label("Preset:"); + GUILayout.BeginHorizontal(); + { + + if (GUILayout.Toggle(presetSelected.Equals("Precise"), "Precise", EditorStyles.miniButtonLeft)) + { + presetSelected = "Precise"; + } + + if (GUILayout.Toggle(presetSelected.Equals("Balanced"), "Balanced", EditorStyles.miniButtonRight)) + { + presetSelected = "Balanced"; + } + + if (GUILayout.Toggle(presetSelected.Equals("Creative"), "Creative", EditorStyles.miniButtonRight)) + { + presetSelected = "Creative"; + } + } + GUILayout.EndHorizontal(); EditorStyle.Button("Upscale Image", () => { if (currentImage == null) return; + upscaledImages.Add(null); imageDataUrl = CommonUtils.Texture2DToDataURL(currentImage); - assetId = imageData.Id; + if (imageData != null) + { + assetId = imageData.Id; + } FetchUpscaledImage(imageDataUrl); }); @@ -195,50 +287,140 @@ private void DrawTextureButton(int i) } } + /// + /// Try to get asset of reference to upscale. + /// Then launch the upscale into a job. + /// Get back the result to an asset and download the image resulting of the process. + /// + /// private void FetchUpscaledImage(string imgUrl) { string json = GetJsonPayload(imgUrl); - Debug.Log(json); - - ApiClient.RestPut("images/upscale",json, response => + + if (string.IsNullOrEmpty(assetId)) { - var pixelatedResponse = JsonConvert.DeserializeObject(response.Content); - Texture2D texture = CommonUtils.DataURLToTexture2D(pixelatedResponse.image); - ImageDataStorage.ImageData newImageData = new ImageDataStorage.ImageData + ApiClient.RestPost("assets", json, response => { - Id = pixelatedResponse.asset.id, - Url = pixelatedResponse.image, - InferenceId = pixelatedResponse.asset.ownerId, - }; - upscaledImages.Insert(0, texture); - imageDataList.Insert(0, newImageData); - }); + var jsonResponse = JsonConvert.DeserializeObject(response.Content); + assetId = jsonResponse.asset.id; + + json = GetJsonPayload(imgUrl); + + ApiClient.RestPost("generate/upscale", json, response => + { + var upscaleResponse = JsonConvert.DeserializeObject(response.Content); + + var jobId = upscaleResponse.job.jobId; + + upscaleEditor.LaunchProgressUpscale(jobId, _answer => { + var assetAnswer = JsonConvert.DeserializeObject(_answer); + ApiClient.RestGet($"assets/{assetAnswer.job.metadata.assetIds[0]}", response => + { + var asset = JsonConvert.DeserializeObject(response.Content); + Texture2D texture = new Texture2D(2, 2); + CommonUtils.FetchTextureFromURL(asset.asset.url, response => { + texture = response; + ImageDataStorage.ImageData newImageData = new ImageDataStorage.ImageData + { + Id = asset.asset.id, + Url = asset.asset.url, + }; + if (upscaledImages[0] == null) + { + upscaledImages[0] = texture; + } + else + { + upscaledImages.Insert(0, texture); + } + imageDataList.Insert(0, newImageData); + }); + }); + }); + }); + }, errorAction => { + upscaledImages.RemoveAt(0); + }); + } + else + { + ApiClient.RestPost("generate/upscale", json, response => + { + var upscaleResponse = JsonConvert.DeserializeObject(response.Content); + + var jobId = upscaleResponse.job.jobId; + + upscaleEditor.LaunchProgressUpscale(jobId, _answer => { + var assetAnswer = JsonConvert.DeserializeObject(_answer); + ApiClient.RestGet($"assets/{assetAnswer.job.metadata.assetIds[0]}", response => + { + var asset = JsonConvert.DeserializeObject(response.Content); + Texture2D texture = new Texture2D(2, 2); + CommonUtils.FetchTextureFromURL(asset.asset.url, response => { + texture = response; + ImageDataStorage.ImageData newImageData = new ImageDataStorage.ImageData + { + Id = asset.asset.id, + Url = asset.asset.url, + }; + if (upscaledImages[0] == null) + { + upscaledImages[0] = texture; + } + else + { + upscaledImages.Insert(0, texture); + } + imageDataList.Insert(0, newImageData); + }); + }); + }); + }); + } } + /// + /// Prepare the json payload to the upscale. + /// + /// + /// private string GetJsonPayload(string imgUrl) { string json; - if (assetId == "") + + switch (styleSelected) + { + case "3D Rendered": + styleSelected = "3d-rendered"; + break; + + case "Photorealistic": + styleSelected = "photography"; + break; + } + + if (string.IsNullOrEmpty(assetId)) { var payload = new { image = imgUrl, - forceFaceRestoration = forceFaceRestoration, - photorealist = usePhotorealisticModel, + preset = presetSelected.ToLower(), + style = styleSelected.ToLower(), scalingFactor = scalingFactor, returnImage = returnImage, name = "" }; + json = JsonConvert.SerializeObject(payload); } else { var payload = new { - image = imgUrl, + image = assetId, assetId = assetId, - forceFaceRestoration = forceFaceRestoration, - photorealist = usePhotorealisticModel, + preset = presetSelected.ToLower(), + style = styleSelected.ToLower(), scalingFactor = scalingFactor, returnImage = returnImage, name = CommonUtils.GetRandomImageFileName() @@ -248,42 +430,6 @@ private string GetJsonPayload(string imgUrl) return json; } - - #region API_DTO - - public class Asset - { - public string id { get; set; } - public string url { get; set; } - public string mimeType { get; set; } - public Metadata metadata { get; set; } - public string ownerId { get; set; } - public string authorId { get; set; } - public DateTime createdAt { get; set; } - public DateTime updatedAt { get; set; } - public string privacy { get; set; } - public List tags { get; set; } - public List collectionIds { get; set; } - } - - public class Metadata - { - public string type { get; set; } - public string parentId { get; set; } - public string rootParentId { get; set; } - public string kind { get; set; } - public bool magic { get; set; } - public bool forceFaceRestoration { get; set; } - public bool photorealist { get; set; } - } - - public class Root - { - public Asset asset { get; set; } - public string image { get; set; } - } - - #endregion } }