Enhance AIImages mod with settings support and improved UI for image generation. Update localized strings in English and Russian for better clarity. Refactor code for better organization and maintainability.
This commit is contained in:
165
Source/AIImages/Services/ColorDescriptionService.cs
Normal file
165
Source/AIImages/Services/ColorDescriptionService.cs
Normal file
@@ -0,0 +1,165 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace AIImages.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Сервис для умного определения цветов (вместо RGB значений)
|
||||
/// </summary>
|
||||
public static class ColorDescriptionService
|
||||
{
|
||||
/// <summary>
|
||||
/// Получает текстовое описание цвета волос
|
||||
/// </summary>
|
||||
public static string GetHairColorDescription(Color color)
|
||||
{
|
||||
float h,
|
||||
s,
|
||||
v;
|
||||
Color.RGBToHSV(color, out h, out s, out v);
|
||||
|
||||
// Проверяем на оттенки серого
|
||||
if (s < 0.15f)
|
||||
{
|
||||
return GetGrayscaleDescription(v);
|
||||
}
|
||||
|
||||
// Определяем оттенок
|
||||
string hueDescription = GetHueDescription(h);
|
||||
string brightnessModifier = GetBrightnessModifier(v, s);
|
||||
|
||||
return $"{brightnessModifier}{hueDescription}".Trim();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получает текстовое описание цвета кожи
|
||||
/// </summary>
|
||||
public static string GetSkinToneDescription(Color color)
|
||||
{
|
||||
// Вычисляем яркость
|
||||
float brightness = (color.r + color.g + color.b) / 3f;
|
||||
|
||||
// Определяем оттенок кожи
|
||||
if (brightness >= 0.85f)
|
||||
return "very fair skin";
|
||||
else if (brightness >= 0.75f)
|
||||
return "fair skin";
|
||||
else if (brightness >= 0.65f)
|
||||
return "light skin";
|
||||
else if (brightness >= 0.55f)
|
||||
return "medium skin";
|
||||
else if (brightness >= 0.45f)
|
||||
return "olive skin";
|
||||
else if (brightness >= 0.35f)
|
||||
return "tan skin";
|
||||
else if (brightness >= 0.25f)
|
||||
return "brown skin";
|
||||
else if (brightness >= 0.15f)
|
||||
return "dark brown skin";
|
||||
else
|
||||
return "very dark skin";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получает описание цвета одежды
|
||||
/// </summary>
|
||||
public static string GetApparelColorDescription(Color color)
|
||||
{
|
||||
float h,
|
||||
s,
|
||||
v;
|
||||
Color.RGBToHSV(color, out h, out s, out v);
|
||||
|
||||
// Проверяем на оттенки серого
|
||||
if (s < 0.1f)
|
||||
{
|
||||
return GetGrayscaleDescription(v);
|
||||
}
|
||||
|
||||
// Определяем оттенок
|
||||
string hueDescription = GetHueDescription(h);
|
||||
|
||||
// Модификаторы насыщенности и яркости
|
||||
string saturationModifier = "";
|
||||
if (s < 0.3f)
|
||||
saturationModifier = "pale ";
|
||||
else if (s > 0.8f)
|
||||
saturationModifier = "vivid ";
|
||||
|
||||
string brightnessModifier = "";
|
||||
if (v < 0.3f)
|
||||
brightnessModifier = "dark ";
|
||||
else if (v > 0.8f)
|
||||
brightnessModifier = "bright ";
|
||||
|
||||
return $"{brightnessModifier}{saturationModifier}{hueDescription}".Trim();
|
||||
}
|
||||
|
||||
private static string GetGrayscaleDescription(float value)
|
||||
{
|
||||
if (value >= 0.95f)
|
||||
return "white";
|
||||
else if (value >= 0.8f)
|
||||
return "light gray";
|
||||
else if (value >= 0.6f)
|
||||
return "gray";
|
||||
else if (value >= 0.4f)
|
||||
return "dark gray";
|
||||
else if (value >= 0.2f)
|
||||
return "charcoal";
|
||||
else
|
||||
return "black";
|
||||
}
|
||||
|
||||
private static string GetHueDescription(float hue)
|
||||
{
|
||||
// Hue from 0 to 1
|
||||
if (hue < 0.05f || hue >= 0.95f)
|
||||
return "red";
|
||||
if (hue < 0.083f)
|
||||
return "orange-red";
|
||||
if (hue < 0.15f)
|
||||
return "orange";
|
||||
if (hue < 0.19f)
|
||||
return "golden";
|
||||
if (hue < 0.22f)
|
||||
return "yellow";
|
||||
if (hue < 0.35f)
|
||||
return "yellow-green";
|
||||
if (hue < 0.45f)
|
||||
return "green";
|
||||
if (hue < 0.52f)
|
||||
return "cyan";
|
||||
if (hue < 0.58f)
|
||||
return "light blue";
|
||||
if (hue < 0.65f)
|
||||
return "blue";
|
||||
if (hue < 0.72f)
|
||||
return "deep blue";
|
||||
if (hue < 0.78f)
|
||||
return "purple";
|
||||
if (hue < 0.85f)
|
||||
return "violet";
|
||||
if (hue < 0.92f)
|
||||
return "magenta";
|
||||
|
||||
return "pink";
|
||||
}
|
||||
|
||||
private static string GetBrightnessModifier(float value, float saturation)
|
||||
{
|
||||
// Для волос используем специальные термины
|
||||
if (value < 0.2f)
|
||||
return "jet black ";
|
||||
else if (value < 0.3f)
|
||||
return "black ";
|
||||
else if (value < 0.45f)
|
||||
return "dark ";
|
||||
else if (value > 0.85f && saturation < 0.3f)
|
||||
return "platinum ";
|
||||
else if (value > 0.75f)
|
||||
return "light ";
|
||||
else
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user