Refactor AIImages UI layout for improved positioning and consistency. Remove ShotType settings and related code to simplify prompt generation. Update models to include new properties for hair and apparel definitions, enhancing data handling for character appearance.

This commit is contained in:
Leonid Pershin
2025-10-26 18:23:40 +03:00
parent 0f60721162
commit 6715544952
8 changed files with 100 additions and 99 deletions

View File

@@ -39,6 +39,7 @@ namespace AIImages.Services
string
>
{
{ ArtStyle.None, "" },
{ ArtStyle.Realistic, "photorealistic, hyperrealistic, realistic photo, photography" },
{ ArtStyle.SemiRealistic, "semi-realistic, detailed illustration, realistic art" },
{ ArtStyle.Anime, "anime style, manga style, anime character" },
@@ -52,18 +53,6 @@ namespace AIImages.Services
{ ArtStyle.CellShaded, "cell shaded, flat colors, toon shading, stylized" },
};
private static readonly Dictionary<ShotType, string> ShotTypePrompts = new Dictionary<
ShotType,
string
>
{
{ ShotType.Portrait, "portrait, head and shoulders" },
{ ShotType.HalfBody, "half body shot, waist up" },
{ ShotType.FullBody, "full body, full length" },
{ ShotType.CloseUp, "close up, face focus, detailed face" },
{ ShotType.ThreeQuarter, "three-quarter view, 3/4 view" },
};
public string GeneratePositivePrompt(
PawnAppearanceData appearanceData,
StableDiffusionSettings settings
@@ -75,18 +64,17 @@ namespace AIImages.Services
StringBuilder prompt = new StringBuilder();
// 1. Художественный стиль
if (ArtStylePrompts.TryGetValue(settings.ArtStyle, out string stylePrompt))
if (
ArtStylePrompts.TryGetValue(settings.ArtStyle, out string stylePrompt)
&& !string.IsNullOrEmpty(stylePrompt)
)
{
prompt.Append(stylePrompt);
prompt.Append(", ");
}
// 2. Тип кадра
if (ShotTypePrompts.TryGetValue(settings.ShotType, out string shotPrompt))
{
prompt.Append(shotPrompt);
prompt.Append(" of ");
}
// 2. Тип кадра - автоматически добавляем "portrait" для генерации персонажей
prompt.Append("portrait, head and shoulders of ");
// 3. Базовое описание (возраст и пол)
prompt.Append(GetAgeAndGenderDescription(appearanceData));
@@ -157,16 +145,18 @@ namespace AIImages.Services
);
// Специфичные для стиля негативы
if (
settings.ArtStyle == ArtStyle.Realistic
|| settings.ArtStyle == ArtStyle.SemiRealistic
)
switch (settings.ArtStyle)
{
negativePrompt.Append("cartoon, anime, painting, drawing, illustration, ");
}
else if (settings.ArtStyle == ArtStyle.Anime)
{
negativePrompt.Append("realistic, photo, photography, 3d, ");
case ArtStyle.Realistic:
case ArtStyle.SemiRealistic:
negativePrompt.Append("cartoon, anime, painting, drawing, illustration, ");
break;
case ArtStyle.Anime:
negativePrompt.Append("realistic, photo, photography, 3d, ");
break;
case ArtStyle.None:
// Без дополнительных негативных промптов для стиля None
break;
}
// Пользовательский негативный промпт
@@ -244,7 +234,7 @@ namespace AIImages.Services
private string GetHairDescription(PawnAppearanceData data)
{
if (string.IsNullOrEmpty(data.HairStyle))
if (string.IsNullOrEmpty(data.HairDefName))
return "";
StringBuilder hair = new StringBuilder();
@@ -254,10 +244,8 @@ namespace AIImages.Services
hair.Append(hairColor);
hair.Append(" ");
// Стиль прически (упрощаем сложные названия)
string style = data
.HairStyle.ToLower()
.Replace("_", " ")
// Стиль прически - используем DefName для английского названия
string style = CleanDefName(data.HairDefName)
.Replace("shaved", "very short")
.Replace("mohawk", "mohawk hairstyle");
@@ -310,15 +298,15 @@ namespace AIImages.Services
itemDesc.Append(" ");
}
// Материал
if (!string.IsNullOrEmpty(item.Material))
// Материал - используем DefName для английского названия
if (!string.IsNullOrEmpty(item.MaterialDefName))
{
itemDesc.Append(item.Material.ToLower());
itemDesc.Append(CleanDefName(item.MaterialDefName));
itemDesc.Append(" ");
}
// Название предмета
itemDesc.Append(item.Label.ToLower());
// Название предмета - используем DefName для английского названия
itemDesc.Append(CleanDefName(item.DefName));
items.Add(itemDesc.ToString());
}
@@ -332,22 +320,56 @@ namespace AIImages.Services
{
var baseTags = "highly detailed, professional, masterpiece, best quality";
if (style == ArtStyle.Realistic || style == ArtStyle.SemiRealistic)
switch (style)
{
return $"{baseTags}, professional photography, 8k uhd, dslr, high quality, sharp focus";
}
else if (style == ArtStyle.Anime)
{
return $"{baseTags}, anime masterpiece, high resolution, vibrant colors";
}
else if (style == ArtStyle.ConceptArt)
{
return $"{baseTags}, trending on artstation, professional digital art";
}
else
{
return baseTags;
case ArtStyle.None:
return baseTags;
case ArtStyle.Realistic:
case ArtStyle.SemiRealistic:
return $"{baseTags}, professional photography, 8k uhd, dslr, high quality, sharp focus";
case ArtStyle.Anime:
return $"{baseTags}, anime masterpiece, high resolution, vibrant colors";
case ArtStyle.ConceptArt:
return $"{baseTags}, trending on artstation, professional digital art";
default:
return baseTags;
}
}
/// <summary>
/// Преобразует defName в читаемый английский текст для промпта
/// Пример: "Apparel_Pants" -> "pants", "Synthread" -> "synthread"
/// </summary>
private string CleanDefName(string defName)
{
if (string.IsNullOrEmpty(defName))
return "";
string cleaned = defName;
// Убираем распространенные префиксы RimWorld
cleaned = System.Text.RegularExpressions.Regex.Replace(
cleaned,
"^(Apparel_|Armor_|Weapon_|Thing_)",
"",
System.Text.RegularExpressions.RegexOptions.IgnoreCase
);
// Разделяем CamelCase на слова
cleaned = System.Text.RegularExpressions.Regex.Replace(
cleaned,
"([a-z])([A-Z])",
"$1 $2"
);
// Заменяем подчеркивания на пробелы
cleaned = cleaned.Replace("_", " ");
// Убираем множественные пробелы
cleaned = System.Text.RegularExpressions.Regex.Replace(cleaned, @"\s+", " ");
// Приводим к нижнему регистру и убираем лишние пробелы
return cleaned.Trim().ToLower();
}
}
}