From 63d1744984cad29030b5da6b07c6c7b6f607bc01 Mon Sep 17 00:00:00 2001
From: TheRed Games <30622829+TheLLspectre@users.noreply.github.com>
Date: Mon, 18 Mar 2024 08:37:32 +0100
Subject: [PATCH] fix: 125 control net options should have the same naming as
on the webapp (#152)
* fix: Update modalities option and manage model type options values
* fix: modality options is now according with the webapp
According to tag some modalities option are now available.
And has a corresponding translation to call correct modality inside api.
---
package/Editor/Models/ModelsUI.cs | 8 ++--
package/Editor/PromptWindow/PromptWindow.cs | 2 +-
package/Editor/PromptWindow/PromptWindowUI.cs | 41 +++++++++++++++++--
.../PromptWindow/Views/ControlNetView.cs | 35 ++++++++++++++--
package/Editor/_Services/DataCache.cs | 10 +++++
5 files changed, 86 insertions(+), 10 deletions(-)
diff --git a/package/Editor/Models/ModelsUI.cs b/package/Editor/Models/ModelsUI.cs
index 4d8fbb5..0d34348 100644
--- a/package/Editor/Models/ModelsUI.cs
+++ b/package/Editor/Models/ModelsUI.cs
@@ -92,10 +92,10 @@ private void UpdatePage()
{
continue;
}
-
- pageModels.Add(models[i]);
+
+ pageModels.Add(models[i]);
}
- numberPages = (models.Count / maxModelsPerPage) +1;
+ numberPages = (models.Count / maxModelsPerPage) + 1;
if (currentPage < numberPages)
{
@@ -196,6 +196,8 @@ private void DrawTextureBox(float boxWidth, float boxHeight, float rowPadding, L
if (globalIndex >= 0 && globalIndex < models.Count)
{
DataCache.instance.SelectedModelId = models[globalIndex].id;
+ DataCache.instance.SelectedModelType = models[globalIndex].type;
+
EditorPrefs.SetString("SelectedModelName", name);
}
diff --git a/package/Editor/PromptWindow/PromptWindow.cs b/package/Editor/PromptWindow/PromptWindow.cs
index a4b80bf..07abb1d 100644
--- a/package/Editor/PromptWindow/PromptWindow.cs
+++ b/package/Editor/PromptWindow/PromptWindow.cs
@@ -205,7 +205,7 @@ private void PrepareAdvancedModalitySettings(out string modality, out string ope
if (promptWindowUI.selectedOptionIndex > 0)
{
- string optionName = promptWindowUI.dropdownOptions[promptWindowUI.selectedOptionIndex - 1];
+ string optionName = promptWindowUI.correspondingOptionsValue[promptWindowUI.selectedOptionIndex - 1];
if (!modalitySettings.ContainsKey(optionName))
{
modalitySettings.Add(optionName, $"{promptWindowUI.sliderValue:0.00}");
diff --git a/package/Editor/PromptWindow/PromptWindowUI.cs b/package/Editor/PromptWindow/PromptWindowUI.cs
index dc0a610..66ea29a 100644
--- a/package/Editor/PromptWindow/PromptWindowUI.cs
+++ b/package/Editor/PromptWindow/PromptWindowUI.cs
@@ -12,18 +12,53 @@ public partial class PromptWindowUI
internal static Texture2D imageUpload;
+ ///
+ /// First dropdown options according to SDXL models
+ ///
public readonly string[] dropdownOptions =
{
"",
+ "Character",
+ "Landscape",
+ "Structure",
+ "Pose",
+ "Depth",
+ "Segmentation",
+ "Illusion"
+ };
+
+ ///
+ /// Seconds dropdown options according to SD 1.5 models
+ ///
+ public readonly string[] dropdownOptionsSD15 =
+ {
+ "City",
+ "Interior",
+ "Edges",
+ "Scribble",
+ "Normal Map",
+ "Line Art"
+ };
+
+ ///
+ /// Translation to api calling modalities options, treat previous values in the exact same order.
+ ///
+ public readonly string[] correspondingOptionsValue =
+ {
+ "",
+ "character",
+ "landscape",
"canny",
"pose",
"depth",
- "lines",
"seg",
+ "illusion",
+ "city",
+ "interior",
+ "lines",
"scribble",
- "lineart",
"normal-map",
- "shuffle"
+ "lineart"
};
internal readonly string[] schedulerOptions = new string[] // Scheduler options extracted from your HTML
diff --git a/package/Editor/PromptWindow/Views/ControlNetView.cs b/package/Editor/PromptWindow/Views/ControlNetView.cs
index 83d2d6d..12cad7f 100644
--- a/package/Editor/PromptWindow/Views/ControlNetView.cs
+++ b/package/Editor/PromptWindow/Views/ControlNetView.cs
@@ -33,9 +33,38 @@ private void RenderControlNetFoldout()
GUILayout.BeginHorizontal();
GUILayout.Label("Modality :", EditorStyles.label);
- List availableOptions1 = new List { "None" };
- availableOptions1.AddRange(dropdownOptions);
- selectedOptionIndex = EditorGUILayout.Popup(selectedOptionIndex, availableOptions1.ToArray());
+ List availableOptions = new List { "None" };
+
+
+ if (!string.IsNullOrEmpty(DataCache.instance.SelectedModelType))
+ {
+ switch (DataCache.instance.SelectedModelType)
+ {
+ case "sd-xl-composition":
+ availableOptions.AddRange(dropdownOptions);
+ break;
+
+ case "sd-xl-lora":
+ availableOptions.AddRange(dropdownOptions);
+ break;
+
+ case "sd-xl":
+ availableOptions.AddRange(dropdownOptions);
+ break;
+
+ case "sd-1_5":
+ availableOptions.AddRange(dropdownOptions);
+ availableOptions.AddRange(dropdownOptionsSD15);
+ break;
+
+ default:
+ break;
+
+ }
+ }
+
+ //availableOptions.AddRange(dropdownOptions);
+ selectedOptionIndex = EditorGUILayout.Popup(selectedOptionIndex, availableOptions.ToArray());
if (selectedOptionIndex > 0)
{
diff --git a/package/Editor/_Services/DataCache.cs b/package/Editor/_Services/DataCache.cs
index 85fea90..ba145f9 100644
--- a/package/Editor/_Services/DataCache.cs
+++ b/package/Editor/_Services/DataCache.cs
@@ -12,6 +12,10 @@ namespace Scenario.Editor
///
public class DataCache : ScriptableSingleton
{
+
+ public Models.ModelData SelectedModelData { get { return selectedModelData; } set { selectedModelData = value; } }
+ private Models.ModelData selectedModelData = null;
+
#region ImageDataList
[SerializeField] private List imageDataList = new();
@@ -151,6 +155,12 @@ public string SelectedModelId
set => EditorPrefs.SetString("SelectedModelId", value);
}
+ public string SelectedModelType
+ {
+ get => EditorPrefs.GetString("SelectedModelType", "");
+ set => EditorPrefs.SetString("SelectedModelType", value);
+ }
+
public int GetReservedSpaceCount()
{
return imageDataList.Count(x => x.Id == "-1");