Skip to content

Commit

Permalink
Merge branch 'develop' into 107-planar-projection-texture-generator
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLLspectre committed Jul 15, 2024
2 parents b47f321 + 9710962 commit 2083cc1
Show file tree
Hide file tree
Showing 16 changed files with 404 additions and 87 deletions.
2 changes: 1 addition & 1 deletion package/Editor/CompositionEditor/CompositionEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<CompositionEditor>("Composition Editor");
Expand Down
2 changes: 1 addition & 1 deletion package/Editor/DataBuilder/DataBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DataBuilder>("3d Data Builder");
Expand Down
2 changes: 1 addition & 1 deletion package/Editor/ImageEditor/ImageEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ImageEditor>("Image Editor");
Expand Down
3 changes: 2 additions & 1 deletion package/Editor/Images/Images.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class Images : EditorWindow
/// </summary>
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)
Expand All @@ -46,6 +46,7 @@ public static void ShowWindow()
GetInferencesData();

var images = (Images)GetWindow(typeof(Images));
images.autoRepaintOnSceneChange = true;
ImagesUI.Init(images);
//ImagesUI.
}
Expand Down
2 changes: 1 addition & 1 deletion package/Editor/Images/ImagesUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,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));
});
}
},
Expand Down
2 changes: 1 addition & 1 deletion package/Editor/InpaintingEditor/InpaintingEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<InpaintingEditor>("Inpainting Editor");
Expand Down
3 changes: 2 additions & 1 deletion package/Editor/Isometric Workflow/IsometricWorkflow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public class IsometricWorkflow : EditorWindow

#endregion

[MenuItem("Window/Scenario/Workflows/1. Isometric Workflow", false, 1)]
[MenuItem("Scenario/Workflows/1. Isometric Workflow")]
public static void ShowWindow()
{
if (isVisible)
Expand All @@ -165,6 +165,7 @@ public static void ShowWindow()
InferenceManager.SilenceMode = true;

var isometricWorkflow = GetWindow<IsometricWorkflow>("Isometric Workflow");
isometricWorkflow.autoRepaintOnSceneChange = true;
isometricWorkflow.minSize = new Vector2(1024, 625);

if (isometricWorkflow.isometricStartScreen == null)
Expand Down
2 changes: 1 addition & 1 deletion package/Editor/LayerEditor/LayerEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<LayerEditor>("Layer Editor");
Expand Down
5 changes: 4 additions & 1 deletion package/Editor/Models/Models.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ private void OnGUI()

private void OnEnable()
{
ShowWindow();
SetTab(privacyQuickStart);
}

Expand All @@ -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>("Models");
window.autoRepaintOnSceneChange = true;
window.minSize = new Vector2(MinimumWidth, window.minSize.y);
}

Expand Down
2 changes: 1 addition & 1 deletion package/Editor/PixelEditor/PixelEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion package/Editor/Plugins/APIPricing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion package/Editor/PromptWindow/PromptBuilderWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class PromptBuilderWindow : EditorWindow
public static Action<string> 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<PromptBuilderWindow>("Prompt Builder");
Expand Down
2 changes: 1 addition & 1 deletion package/Editor/PromptWindow/PromptWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,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<PromptWindow>("Prompt Window");
Expand Down
2 changes: 1 addition & 1 deletion package/Editor/Settings/PluginSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PluginSettings>("Scenario Settings");
Expand Down
174 changes: 170 additions & 4 deletions package/Editor/UpscaleEditor/UpscaleEditor.cs
Original file line number Diff line number Diff line change
@@ -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();

[MenuItem("Window/Scenario/Editors/Upscale Editor", false, 5)]
#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)
Expand All @@ -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

/// <summary>
/// Trigger the coroutine to get the upscale result.
/// </summary>
/// <param name="_jobId"></param>
/// <param name="_answer"></param>
public void LaunchProgressUpscale(string _jobId, Action<string> _answer)
{
if (!string.IsNullOrEmpty(_jobId))
{
EditorCoroutineUtility.StartCoroutineOwnerless(GetProgressUpscale(_jobId, _answer));
}
}

#endregion

#region Private Methods

/// <summary>
/// Editor Coroutine to processing upscale.
/// Get the progress of the job id and wait the success status.
/// </summary>
/// <param name="_jobId"> JobId to listen </param>
/// <param name="_response"> Return the result of the content at the end of the process </param>
/// <returns></returns>
IEnumerator GetProgressUpscale(string _jobId, Action<string> _response)
{
bool inProgress = true;

while (inProgress)
{
if (inProgress)
{
ApiClient.RestGet($"jobs/{_jobId}", response =>
{
var progressResponse = JsonConvert.DeserializeObject<Root>(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

/// <summary>
/// Asset result object
/// </summary>
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<object> tags { get; set; }
public List<object> collectionIds { get; set; }
}

/// <summary>
/// Job result object
/// </summary>
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; }
}

/// <summary>
/// Metadata result object
/// </summary>
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; }
}

/// <summary>
/// Root object to be deserialized from json.
/// </summary>
public class Root
{
public Asset asset { get; set; }
public Job job { get; set; }
public string image { get; set; }
}

#endregion
}
Loading

0 comments on commit 2083cc1

Please sign in to comment.