Creature Generation Pipeline
WEFA uses a 2D+3D hybrid pipeline to generate unique creatures from the player's element choice and local environment.
Pipeline Stages
1. Template Selection
A base creature template is selected from the 9 Massiah creatures based on the player's element. Each template has:
- Anatomy description and silhouette
- Color palette and materials
- Stage descriptors (Seed through Elder)
- Reference image path
2. Trait Generation
A serverless function (/api/creatures/traits) calls Claude API (Sonnet) with a three-layer prompt:
- Layer 1 (immutable anchor): Template anatomy + silhouette constraints
- Layer 2 (stage modifier): Stage-specific descriptors from the template
- Layer 3 (environment adaptation): Biome colors, textures, and local flora
Returns: variant name, traits, signature move, lore, adapted colors, personality.
3. Image Generation
A serverless function (/api/creatures/image) generates a 512x512 PNG sprite via image generation API (Flux/SDXL).
4. 3D Model Generation
A serverless function (/api/creatures/model) starts a Meshy Image-to-3D task. The client polls every 5 seconds with a 180-second timeout.
Target: 15k triangles, PBR textures, GLB format.
5. Fallback
On any failure at any stage, the system falls back to the seed pack — pre-generated creature data stored locally in src/data/creature-seeds.json.
Caching
Creature assets are cached in Dexie's creatureAssets table:
- Sprites: ~100KB per image
- GLB models: ~2-5MB per model
- Stored as Blobs, loaded via
createObjectURLfor R3F
iOS Safari has a ~50MB IndexedDB quota per origin. The cache manager monitors usage and evicts old assets.
Prompt Engineering
The three-layer prompt system ensures:
- Structural consistency: The creature always matches its template silhouette
- Stage-appropriate detail: Seed-stage creatures are small and simple; Elder-stage are elaborate
- Environmental uniqueness: Desert biome creatures have different coloring than rainforest ones
- Meshy compatibility: Texture prompts stay under 600 characters
Key Files
src/modules/creature-generator/prompt-builder.ts- Three-layer prompt systemsrc/modules/creature-generator/trait-service.ts- Claude API trait generationsrc/modules/creature-generator/image-service.ts- Image generationsrc/modules/creature-generator/meshy-service.ts- Meshy 3D model generationsrc/modules/creature-generator/seed-pack.ts- Offline fallbacksrc/modules/creature-generator/cache.ts- IDB blob cachesrc/machines/creatureGeneratorMachine.ts- Pipeline state machine