Asset Generation: Campfire, Tent, Sleeping Bag, UI Elements (Health, Inventory, Dialog). Cleaned GrassScene.

This commit is contained in:
2026-01-28 07:45:24 +01:00
parent b686be33ab
commit 94565adffc
69 changed files with 5208 additions and 122 deletions

View File

@@ -0,0 +1,97 @@
import cv2
import numpy as np
import os
import shutil
def process_and_replace_assets():
# Paths to the newly generated artifacts
# NOTE: In a real scenario, I would validly know these paths.
# Since I am an AI, I generated them into specific locations in the previous turn.
# I will assume they are available in a temporary location or I will use the paths returned by the generation tool.
# Based on previous output:
# Campfire: .../campfire_simple_1769580346960.png
# Tent: .../tent_new_color_1769580361961.png
# Sleeping Bag: .../sleeping_bag_asset_1769580261243.png
# I need to find them or use the strings directly.
# Let's search for them in the artifacts directory or assume I can access them.
# For this script to work on the USER's machine, the files must be there.
# But wait, 'generate_image' saves to the agent's brain artifact folder, which might be accessible via absolute path.
# Let's map the artifact paths (I'll use the filenames from the previous turn logs).
# Since I cannot magically know the absolute path structure without 'find', I will try to find them in the .gemini artifacts folder.
artifacts_dir = '/Users/davidkotnik/.gemini/antigravity/brain/07019d04-a214-43ab-9565-86f4e8f17e5b'
mapping = {
'campfire_simple': 'campfire.png',
'tent_new_color': 'tent.png',
'sleeping_bag_asset': 'sleeping_bag.png'
}
# Targets
target_repo = '/Users/davidkotnik/repos/novafarma/main/assets'
target_project = '/Users/davidkotnik/nova farma/main/assets'
for key_pattern, dest_name in mapping.items():
# Find the file in artifacts
found_path = None
for f in os.listdir(artifacts_dir):
if key_pattern in f and f.endswith('.png'):
found_path = os.path.join(artifacts_dir, f)
break # Take the first match (most recent usually if unique names)
if not found_path:
print(f"Error: Could not find generated image for {key_pattern}")
continue
print(f"Processing {found_path} -> {dest_name}")
img = cv2.imread(found_path, cv2.IMREAD_UNCHANGED)
# 1. Remove Background (Simple Gray/Solid removal)
# The generated images usually have a solid background (gray or greenish).
# Best approach: Grab corner color and remove everything similar?
if img.shape[2] == 3:
img = cv2.cvtColor(img, cv2.COLOR_BGR2BGRA)
# Sampling corners
corners = [img[0,0], img[0, -1], img[-1, 0], img[-1, -1]]
# Take the most common color (usually bg)
bg_color = corners[0] # Naive approach
# Tolerance
tol = 30
lower = np.clip(bg_color[:3] - tol, 0, 255)
upper = np.clip(bg_color[:3] + tol, 0, 255)
mask = cv2.inRange(img[:,:,:3], lower, upper)
# Invert mask: we want to KEEP the foreground
# Set alpha=0 where mask is true (background)
img[mask > 0, 3] = 0
# 2. Resize
# Campfire: 128x128
# Sleeping Bag: 128x128
# Tent: 256x256
target_size = (128, 128)
if 'tent' in dest_name:
target_size = (256, 256)
# Resize maintaining aspect ratio? Or just fit?
# Isometric assets often square-ish. Let's just resize to fit box.
img = cv2.resize(img, target_size, interpolation=cv2.INTER_AREA)
# Save
local_dest = os.path.join(target_repo, dest_name)
cv2.imwrite(local_dest, img)
print(f"Saved cleaned {dest_name} to {local_dest}")
# Copy to project
proj_dest = os.path.join(target_project, dest_name)
shutil.copy2(local_dest, proj_dest)
print(f"Synced to {proj_dest}")
if __name__ == "__main__":
process_and_replace_assets()