Skip to content

Commit

Permalink
Merge pull request #150 from scenario-labs/124-remove-the-sliders-fro…
Browse files Browse the repository at this point in the history
…m-the-controlnet-modes-and-leave-the-values-the-same-as-in-the-webapp

fix: remove the sliders from the controlnet modes and leave the values the same as in the webapp
  • Loading branch information
Morgan-6Freedom authored Mar 7, 2024
2 parents c5b9f53 + 8b7e241 commit 8ec675e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 66 deletions.
24 changes: 6 additions & 18 deletions package/Editor/PromptWindow/PromptWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,25 +203,13 @@ private void PrepareAdvancedModalitySettings(out string modality, out string ope
{
operationType = "controlnet";

if (promptWindowUI.selectedOption1Index > 0)
if (promptWindowUI.selectedOptionIndex > 0)
{
string option1Name = promptWindowUI.dropdownOptions[promptWindowUI.selectedOption1Index - 1];
if (!modalitySettings.ContainsKey(option1Name))
modalitySettings.Add(option1Name, $"{promptWindowUI.sliderValue1:0.00}");
}

if (promptWindowUI.selectedOption2Index > 0)
{
string option2Name = promptWindowUI.dropdownOptions[promptWindowUI.selectedOption2Index - 1];
if (!modalitySettings.ContainsKey(option2Name))
modalitySettings.Add(option2Name, $"{promptWindowUI.sliderValue2:0.00}");
}

if (promptWindowUI.selectedOption3Index > 0)
{
string option3Name = promptWindowUI.dropdownOptions[promptWindowUI.selectedOption3Index - 1];
if (!modalitySettings.ContainsKey(option3Name))
modalitySettings.Add(option3Name, $"{promptWindowUI.sliderValue3:0.00}");
string optionName = promptWindowUI.dropdownOptions[promptWindowUI.selectedOptionIndex - 1];
if (!modalitySettings.ContainsKey(optionName))
{
modalitySettings.Add(optionName, $"{promptWindowUI.sliderValue:0.00}");
}
}

modality = string.Join(",", modalitySettings.Select(kv => $"{kv.Key}:{float.Parse(kv.Value).ToString(CultureInfo.InvariantCulture)}"));
Expand Down
24 changes: 16 additions & 8 deletions package/Editor/PromptWindow/PromptWindowUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,21 @@ public partial class PromptWindowUI
};

public string selectedPreset = "";
public int selectedOption1Index = 0;
public int selectedOption2Index = 0;
public int selectedOption3Index = 0;
public float sliderValue1 = 0.1f;
public float sliderValue2 = 0.1f;
public float sliderValue3 = 0.1f;

/// <summary>
/// Correspond of the index value selected from the modalities dropdown value
/// </summary>
public int selectedOptionIndex = 0;

/// <summary>
/// Variable to display in interface on slider element.
/// </summary>
public int sliderDisplayedValue = 100;

/// <summary>
/// Value from the guidance slider in controlNet options, use to send to generation
/// </summary>
public float sliderValue = 0.0f;

internal bool isImageToImage = false;
internal bool isControlNet = false;
Expand Down Expand Up @@ -302,8 +311,7 @@ private Rect DrawUploadedImage(Rect dropArea)
widthSliderValue = matchingWidth != -1 ? matchingWidth : currentWidth;
heightSliderValue = matchingHeight != -1 ? matchingHeight : currentHeight;

selectedOption1Index = NearestValueIndex(widthSliderValue, allowedWidthValues);
selectedOption2Index = NearestValueIndex(heightSliderValue, allowedHeightValues);
selectedOptionIndex = NearestValueIndex(widthSliderValue, allowedWidthValues);
});

toolsMenu.DropDown(dropdownButtonRect);
Expand Down
53 changes: 13 additions & 40 deletions package/Editor/PromptWindow/Views/ControlNetView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,50 +31,23 @@ private void RenderControlNetFoldout()
if (isAdvancedSettings)
{
GUILayout.BeginHorizontal();
GUILayout.Label("Model 1", EditorStyles.label);
GUILayout.Label("Modality :", EditorStyles.label);

List<string> availableOptions1 = new List<string> { "None" };
availableOptions1.AddRange(dropdownOptions);
selectedOption1Index = EditorGUILayout.Popup(selectedOption1Index, availableOptions1.ToArray());

GUILayout.Label("Slider 1", EditorStyles.label);
sliderValue1 = Mathf.Round(EditorGUILayout.Slider(Mathf.Clamp(sliderValue1, 0.1f, 1.0f), 0.1f, 1.0f) * 100) / 100;
GUILayout.EndHorizontal();

if (selectedOption1Index > 0)
{
GUILayout.BeginHorizontal();
GUILayout.Label("Model 2", EditorStyles.label);

List<string> availableOptions2 = new List<string> { "None" };
availableOptions2.AddRange(dropdownOptions);
availableOptions2.RemoveAt(selectedOption1Index);
selectedOption2Index = EditorGUILayout.Popup(selectedOption2Index, availableOptions2.ToArray());

GUILayout.Label("Slider 2", EditorStyles.label);
sliderValue2 = Mathf.Round(EditorGUILayout.Slider(Mathf.Clamp(sliderValue2, 0.1f, 1.0f), 0.1f, 1.0f) * 100) / 100;
GUILayout.EndHorizontal();
}

if (selectedOption2Index > 0)
{
GUILayout.BeginHorizontal();
GUILayout.Label("Model 3", EditorStyles.label);

List<string> availableOptions3 = new List<string> { "None" };
availableOptions3.AddRange(dropdownOptions);
int option1Index = Array.IndexOf(dropdownOptions, availableOptions1[selectedOption1Index]);
int option2Index = Array.IndexOf(dropdownOptions, dropdownOptions[selectedOption2Index]);

availableOptions3.RemoveAt(option1Index + 1);
availableOptions3.RemoveAt(option2Index);

selectedOption3Index = EditorGUILayout.Popup(selectedOption3Index, availableOptions3.ToArray());

GUILayout.Label("Slider 3", EditorStyles.label);
sliderValue3 = Mathf.Round(EditorGUILayout.Slider(Mathf.Clamp(sliderValue3, 0.1f, 1.0f), 0.1f, 1.0f) * 100) / 100;
GUILayout.EndHorizontal();
selectedOptionIndex = EditorGUILayout.Popup(selectedOptionIndex, availableOptions1.ToArray());

if (selectedOptionIndex > 0)
{
GUILayout.Label("Influence :", EditorStyles.label);
sliderDisplayedValue = (int)EditorGUILayout.Slider(Mathf.Clamp(sliderDisplayedValue, 0, 100), 0, 100);
sliderValue = sliderDisplayedValue / 100.0f;
if (sliderValue == 0)
{
sliderValue = 0.01f;
}
}
GUILayout.EndHorizontal();
}
else
{
Expand Down

0 comments on commit 8ec675e

Please sign in to comment.