The Generation Pipeline
The core of the AI asset generation system is the AssetGenerator
class in gen_assets/generate_backgrounds.py
. This class orchestrates the entire process from receiving a request to saving a finished image file.
AssetGenerator
Class
This class is the main interface for the rest of the application to generate assets. It abstracts away the complexity of the underlying AI models and optimizations.
Initialization
When initialized, the AssetGenerator
sets up the necessary directories and detects the available hardware. It uses a lazy initialization strategy for the SDXL pipeline, meaning the large AI model is only loaded into memory when the first image generation is requested.
class AssetGenerator:
def __init__(self, use_mock=False):
self.use_mock = use_mock
self.optimizer = RTX5070Optimizer()
self.device = self.optimizer.device
self.pipeline = None # Pipeline is loaded on demand
# ... directory setup ...
def _initialize_pipeline(self):
if self.pipeline is None:
# ... loads the StableDiffusionXLPipeline ...
# ... applies RTX 5070 optimizations ...
pass
A use_mock
flag allows the generator to produce simple placeholder images without a GPU, which is useful for development and testing.
Generation Process
The main methods for asset creation are generate_hero_background
, generate_hero_sprite
, and generate_ui_element
.
Here is a breakdown of the steps when generate_hero_background('mage')
is called:
- Get Art Direction: It requests a detailed prompt from the
ArtDirection
class. -
Check Cache: It generates a unique filename based on the prompt content and checks if an image with that name already exists in the
assets/backgrounds
directory. If it does, it returns the path to the cached file immediately.# Simplified caching logic prompt_config = ArtDirection.get_hero_background_prompt(hero_type) cache_filename = self._get_cache_filename(prompt_config) cache_path = os.path.join(BACKGROUNDS_DIR, cache_filename) if os.path.exists(cache_path): return cache_path
-
Generate Image: If no cached file is found, it proceeds with generation. It ensures the pipeline is initialized, then calls it with the prompt and parameters from the
RTX5070Optimizer
. - Enhance Image: The raw output from the AI model is passed to an
_enhance_image_quality
method, which applies post-processing filters like sharpening and contrast adjustment to match the game's defined art style. - Save and Return: The final, enhanced image is saved to the cache path, and the path is returned.
How to Generate Assets
You can trigger the asset generation from the command line.
Generate all hero backgrounds:
python -c "from gen_assets.generate_backgrounds import AssetGenerator; AssetGenerator().generate_all_hero_backgrounds()"
Generate a specific hero's sprite:
python -c "from gen_assets.generate_backgrounds import AssetGenerator; AssetGenerator().generate_hero_sprite('assassin')"
Generate all defined UI elements:
python -c "from gen_assets.generate_backgrounds import AssetGenerator; AssetGenerator().generate_all_ui_elements()"