Keep backgrounds separate and prevent player trails
Browse files
app.py
CHANGED
|
@@ -108,6 +108,7 @@ FREE_IMAGE_STEPS = int(os.environ.get("FREE_IMAGE_STEPS", "5"))
|
|
| 108 |
USE_HF_PROMPT_PROVIDER = os.environ.get("USE_HF_PROMPT_PROVIDER", "0") == "1"
|
| 109 |
USE_HF_IMAGE_PROVIDER = os.environ.get("USE_HF_IMAGE_PROVIDER", "0") == "1"
|
| 110 |
USE_DIFFUSION_FOR_SPRITES = os.environ.get("USE_DIFFUSION_FOR_SPRITES", "0") == "1"
|
|
|
|
| 111 |
HF_IMAGE_MODEL = os.environ.get("HF_IMAGE_MODEL", "black-forest-labs/FLUX.1-schnell")
|
| 112 |
HF_PROMPT_MODEL = os.environ.get("HF_PROMPT_MODEL", "Qwen/Qwen2.5-Coder-7B-Instruct:fastest")
|
| 113 |
HF_PROMPT_ENDPOINT = os.environ.get("HF_PROMPT_ENDPOINT", "https://router.huggingface.co/v1/chat/completions")
|
|
@@ -202,7 +203,8 @@ def build_asset_prompt(role: str, prompt: str, style_hint: str) -> str:
|
|
| 202 |
if is_background:
|
| 203 |
asset_instruction = (
|
| 204 |
"Create one complete 2D game background scene, not a texture tile, not a material sample, "
|
| 205 |
-
"not a UV map. Full scene composition for a canvas game."
|
|
|
|
| 206 |
)
|
| 207 |
else:
|
| 208 |
asset_instruction = (
|
|
@@ -1062,7 +1064,8 @@ def free_diffusion_png(spec: AssetSpec, index: int, run_id: int) -> tuple[bytes
|
|
| 1062 |
negative_prompt = (
|
| 1063 |
"texture map, material texture, seamless texture, tiled pattern, uv map, uv unwrap, "
|
| 1064 |
"skin texture, 3d model texture, normal map, roughness map, diffuse map, sprite sheet, "
|
| 1065 |
-
"atlas, multiple objects, cropped subject, close-up surface, fabric swatch, text, watermark"
|
|
|
|
| 1066 |
)
|
| 1067 |
image = FREE_DIFFUSION_PIPE(
|
| 1068 |
spec.prompt,
|
|
@@ -1114,6 +1117,14 @@ def generate_asset(spec: AssetSpec, index: int, run_id: int) -> tuple[str, str,
|
|
| 1114 |
None,
|
| 1115 |
"shape-aware 2D sprite generator",
|
| 1116 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1117 |
|
| 1118 |
png_content, free_error = free_diffusion_png(spec, index, run_id)
|
| 1119 |
source = FREE_IMAGE_MODEL
|
|
@@ -1244,7 +1255,15 @@ def embed_assets(html_code: str, assets: dict[str, str], specs: list[AssetSpec])
|
|
| 1244 |
var current = image.getAttribute("src") || image.src || "";
|
| 1245 |
var mapped = pickAsset(current);
|
| 1246 |
if (mapped && mapped !== current) image.src = mapped;
|
| 1247 |
-
if (!image.complete || image.naturalWidth === 0 || image.naturalHeight === 0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1248 |
}}
|
| 1249 |
return originalDrawImage.apply(this, arguments);
|
| 1250 |
}} catch (error) {{
|
|
|
|
| 108 |
USE_HF_PROMPT_PROVIDER = os.environ.get("USE_HF_PROMPT_PROVIDER", "0") == "1"
|
| 109 |
USE_HF_IMAGE_PROVIDER = os.environ.get("USE_HF_IMAGE_PROVIDER", "0") == "1"
|
| 110 |
USE_DIFFUSION_FOR_SPRITES = os.environ.get("USE_DIFFUSION_FOR_SPRITES", "0") == "1"
|
| 111 |
+
USE_DIFFUSION_FOR_BACKGROUNDS = os.environ.get("USE_DIFFUSION_FOR_BACKGROUNDS", "0") == "1"
|
| 112 |
HF_IMAGE_MODEL = os.environ.get("HF_IMAGE_MODEL", "black-forest-labs/FLUX.1-schnell")
|
| 113 |
HF_PROMPT_MODEL = os.environ.get("HF_PROMPT_MODEL", "Qwen/Qwen2.5-Coder-7B-Instruct:fastest")
|
| 114 |
HF_PROMPT_ENDPOINT = os.environ.get("HF_PROMPT_ENDPOINT", "https://router.huggingface.co/v1/chat/completions")
|
|
|
|
| 203 |
if is_background:
|
| 204 |
asset_instruction = (
|
| 205 |
"Create one complete 2D game background scene, not a texture tile, not a material sample, "
|
| 206 |
+
"not a UV map. Full scene composition for a canvas game. Empty environment only: no player, "
|
| 207 |
+
"no character, no creature, no vehicle, no mascot, no foreground subject."
|
| 208 |
)
|
| 209 |
else:
|
| 210 |
asset_instruction = (
|
|
|
|
| 1064 |
negative_prompt = (
|
| 1065 |
"texture map, material texture, seamless texture, tiled pattern, uv map, uv unwrap, "
|
| 1066 |
"skin texture, 3d model texture, normal map, roughness map, diffuse map, sprite sheet, "
|
| 1067 |
+
"atlas, multiple objects, cropped subject, close-up surface, fabric swatch, text, watermark, "
|
| 1068 |
+
"person, character, player, hero, creature, monster, vehicle, mascot, foreground subject"
|
| 1069 |
)
|
| 1070 |
image = FREE_DIFFUSION_PIPE(
|
| 1071 |
spec.prompt,
|
|
|
|
| 1117 |
None,
|
| 1118 |
"shape-aware 2D sprite generator",
|
| 1119 |
)
|
| 1120 |
+
if is_background_spec(spec) and not USE_DIFFUSION_FOR_BACKGROUNDS:
|
| 1121 |
+
png_content = local_asset_png(spec, index, run_id)
|
| 1122 |
+
return (
|
| 1123 |
+
png_bytes_to_data_uri(png_content),
|
| 1124 |
+
write_gallery_image(png_content, spec.role),
|
| 1125 |
+
None,
|
| 1126 |
+
"scene-safe 2D background generator",
|
| 1127 |
+
)
|
| 1128 |
|
| 1129 |
png_content, free_error = free_diffusion_png(spec, index, run_id)
|
| 1130 |
source = FREE_IMAGE_MODEL
|
|
|
|
| 1255 |
var current = image.getAttribute("src") || image.src || "";
|
| 1256 |
var mapped = pickAsset(current);
|
| 1257 |
if (mapped && mapped !== current) image.src = mapped;
|
| 1258 |
+
if (!image.complete || image.naturalWidth === 0 || image.naturalHeight === 0) {{
|
| 1259 |
+
var looksLikeBackground = /background|backdrop|scene|map|level|bg/i.test(current);
|
| 1260 |
+
var coversCanvas = arguments.length >= 5 && arguments[1] === 0 && arguments[2] === 0 &&
|
| 1261 |
+
arguments[3] >= this.canvas.width * 0.8 && arguments[4] >= this.canvas.height * 0.8;
|
| 1262 |
+
if (looksLikeBackground || coversCanvas) {{
|
| 1263 |
+
this.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
| 1264 |
+
}}
|
| 1265 |
+
return;
|
| 1266 |
+
}}
|
| 1267 |
}}
|
| 1268 |
return originalDrawImage.apply(this, arguments);
|
| 1269 |
}} catch (error) {{
|