Skip to main content

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

Seed-pack delivery now uses an explicit asset catalog:

  • thumbnailUrl is the default install-time offline surface
  • previewModelUrl is reserved for future gameplay-friendly 3D variants
  • fullModelUrl is the high-fidelity asset used only on demand

Current seed creatures ship with thumbnails plus full GLBs. Because preview variants do not exist yet, gameplay surfaces intentionally fall back to 2D instead of auto-downloading the heavyweight GLBs.

Cached asset behavior:

  • Seed thumbnails are precached with the app shell
  • Creature GLBs are fetched on demand and stored in Cache Storage
  • Dexie stores creature records plus optional offline pin metadata, not GLB blobs

This keeps the install path small and avoids relying on IndexedDB blob storage on mobile Safari.

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 system
  • src/modules/creature-generator/trait-service.ts - Claude API trait generation
  • src/modules/creature-generator/image-service.ts - Image generation
  • src/modules/creature-generator/meshy-service.ts - Meshy 3D model generation
  • src/modules/creature-generator/seed-pack.ts - Offline fallback
  • src/data/creature-asset-catalog.ts - Versioned asset catalog for shipped creatures
  • src/modules/creature-assets.ts - Surface-aware asset resolution and offline pinning
  • src/machines/creatureGeneratorMachine.ts - Pipeline state machine