# engine-guide

Adopt this skill: https://proskills.md/skills/other/htdt-godogen-skills-engine-guide

Page: https://proskills.md/skills/other/htdt-godogen-skills-engine-guide
This document is the public skill bundle for that page. It contains SKILL.md and every helper file the catalog carries. No login is required.

## File: skills/engine-guide/SKILL.md
size: 5152
sha: 8e597d448dd0e685b892db816e75b812422747b5
upstream: https://github.com/htdt/godogen/blob/master/skills/engine-guide/SKILL.md

```text
---
name: engine-guide
description: |
  Building on Godot 4 (C# or GDScript), Bevy, Babylon.js, three.js or HTML: which to choose, installing its toolchain, the project sketch, build commands, headless capture to screenshots and video, and the traps that fail silently. Use when starting or working on a game, a video made in an engine (presentation, explainer, trailer, product showcase), an interactive 3D or 2D page, or anything else built on one of these engines.
---

# Engine guide

One guide per engine sits next to this file: the stack, a project sketch, build commands, headless capture, and the traps that pass a build and break at runtime. Read the chosen engine's guide before writing the project. On an existing project, the engine is already chosen. `setup.md` installs what the engine needs, at current versions.

| Guide | Stack | Pick it for |
|---|---|---|
| `godot.md` | Godot 4, C# | desktop 2D or 3D; the fewest runtime surprises in long unattended runs |
| `godot-gdscript.md` | Godot 4, GDScript | a Godot project the user will keep developing in the editor |
| `bevy.md` | Bevy, Rust | a Rust codebase: ECS, no editor, many entities |
| `babylon.md` | Babylon.js, TypeScript | a browser game that leans on engine systems: physics, GUI, particles, animation |
| `threejs.md` | three.js, TypeScript | a browser piece that leans on its look: custom shaders, stylized rendering, a light page |
| `html.md` | DOM + canvas and three.js, TypeScript | 2D that is mostly text and UI: interactive fiction, cards, grid roguelikes, puzzles, management |

## Choosing

Every engine gets the same loop (build, generate assets, capture), so the choice comes down to what the user holds at the end and how they watch along the way. When the brief leaves it open, it is the user's call as much as yours: it decides what they get, and a switch later is a rewrite. What's already installed can tip a close call: `godot --version` (`mono` in it means the .NET build), `dotnet --version`, `cargo --version`, `node --version`.

- **How the user watches.** On a remote box or steering from a phone, a browser engine wins: the dev server is a URL they refresh while you edit. Godot and Bevy run as desktop apps; from a headless server the user sees them in a recorded video, or pulls the repo and runs it. On the user's own desktop the engines are even.
- **2D.** Godot has a dedicated 2D engine (pixel-space nodes, tilemaps, 2D physics). Bevy handles 2D well. Babylon.js and three.js are 3D-first and draw 2D as sprites and planes. For 2D that is mostly text, panels and buttons, `html` builds on the DOM: type and CSS are the art, with canvas and three.js for motion, effects and 3D moments.
- **Godot: C# or GDScript.** Same engine, scenes and capture. C# compiles: `dotnet build` type-checks the whole project before anything runs, so mistakes surface early; it needs the .NET build of Godot and the .NET SDK. GDScript is Godot's native language, used by most tutorials, addons and Asset Library entries, and runs on any Godot build; whatever the parser can't type fails only at runtime, on the path that runs. GDScript exports everywhere Godot does; check current C# platform support before a web export.
- **Babylon.js or three.js.** Babylon.js is a full engine: Havok physics, GUI, particles, animation groups and an inspector come in the box, so there are fewer seams to wire, at the cost of a heavier bundle. three.js is a renderer: you pick and wire physics (Rapier), UI (HTML over the canvas) and audio, and get the deepest pool of web 3D examples, the most control over the look (custom shaders, postprocessing, WebGPU and TSL node materials) and a small bundle.
- **Bevy** is for a project that should be Rust: code only, ECS, compile-time guarantees, headroom for many entities. It compiles slowest, and its API moves between releases faster than training data catches up, so its guide reads the installed source.
- **No strong preference:** `babylon` for a user who watches and steers from anywhere; `godot` for a desktop game they'll receive as a video or run themselves.

## Beyond games

Godot's movie writer, Bevy's offscreen binary and three.js's stepped capture advance a fixed timestep per saved frame: render cost never shows in the result, and every frame lands exactly where it was scheduled. That makes an engine a studio for more than games. The guides say "the game"; read it as whatever is being built.

- **Video**: a presentation, explainer, trailer, product showcase, data story, music visualization. The capture is the deliverable. Script camera, animation and text on one timeline, place generated voice-over and music (the asset-gen skill) on the same timeline, and mux with ffmpeg. Godot is the strongest pick: deterministic `--write-movie` is built in, it records the scene's own audio in sync, and 3D, 2D, text, particles and tweens are one toolset. three.js when the look is shader-driven or the piece should also live on the web.
- **Interactive pages**: a product configurator, an interactive explainer or data visualization, a 3D landing scene. three.js or Babylon.js, or `html` when it is mostly text and UI.
```

## File: skills/engine-guide/babylon.md
size: 2897
sha: 9bb2203da3bbe37a5faf53ee499450e13495c866
upstream: https://github.com/htdt/godogen/blob/master/skills/engine-guide/babylon.md

```text
# Babylon.js engine guide

Stack: **Babylon.js** (`@babylonjs/core` + `@babylonjs/loaders`), **Vite**, **TypeScript**, Node (current LTS).

## Project shape

A plain Vite + TS project is enough. Scaffold one (`npm create vite@latest . -- --template vanilla-ts`), add `@babylonjs/core` and `@babylonjs/loaders`, then:

- A fullscreen `<canvas>` in `index.html` and a render loop: create an `Engine`, build a `Scene`, call `engine.runRenderLoop(() => scene.render())`, and resize on `window`.
- Put gameplay in `src/` modules; keep generated assets under `src/assets/` and load them through Vite (`import url from './assets/x.glb?url'`).
- Drive gameplay off `scene.onBeforeRenderObservable` and the engine delta — don't assume a fixed frame rate.

Commands: `npm install` · `npm run dev` · `npm run build`.

**Bind the dev server to `0.0.0.0` on a fixed port** (`server: { host: true, port: 5173 }`) so `http://<host>:5173` is reachable from other machines on the LAN or through a tunnel.

## Imports

Import from `@babylonjs/core` subpaths (e.g. `@babylonjs/core/Meshes/meshBuilder`). Some features are registered by a **side-effect module** that tree-shaking drops — code compiles but throws at runtime with `"<Feature> needs to be imported before it can be used"`. When you hit that, add the named side-effect import it asks for (e.g. `import "@babylonjs/core/Meshes/instancedMesh"`, `import "@babylonjs/core/Culling/ray"`, `import "@babylonjs/loaders/glTF"`).

## Physics

Havok is available via `@babylonjs/havok`. Serve `HavokPhysics.wasm` from `public/` and load it with `HavokPhysics({ locateFile: () => "/HavokPhysics.wasm" })` — a `?url` import is blocked by the package `exports`. Enabling physics needs its side-effect module registered (per the rule above); then use `PhysicsAggregate`.

## Capture

Load the running dev URL in headless Chrome/Chromium (`playwright-core`, or `google-chrome --headless`) and screenshot.

- **Use a real GPU.** Headless Chrome silently falls back to SwiftShader/llvmpipe, which renders slowly or blank. On Linux, run under `xvfb-run` and request hardware (`--use-angle=vulkan`); read the WebGL `RENDERER` string and warn if it contains `swiftshader`/`llvmpipe`/`lavapipe`.
- **Wait before shooting.** Capture only after the scene has rendered a frame and textures/GLBs have loaded — gate on a ready flag the game sets, or settle a fixed delay after network idle. Screenshotting too early gives a misleading blank frame.
- **Video:** screenshot on an interval (~30fps) into a temp dir, then encode at ~720p: `ffmpeg -framerate 30 -i frame_%04d.png -c:v libx264 -pix_fmt yuv420p video.mp4`.

## Babylon API lookups

For exact import paths, loader behavior, or Vite specifics on the installed version, read the package sources under `node_modules/@babylonjs/core` and `node_modules/@babylonjs/loaders`; fall back to `https://doc.babylonjs.com/`.
```

## File: skills/engine-guide/bevy.md
size: 4048
sha: 9a785505e583cc290f8a382409fe115ffec2720e
upstream: https://github.com/htdt/godogen/blob/master/skills/engine-guide/bevy.md

````text
# Bevy engine guide

Stack: **current stable Bevy**, current stable Rust. Run `cargo add bevy` to resolve the latest stable release (skip any `-rc` prerelease), pin the exact version it writes, and keep every `bevy_*` crate on that same minor — mismatched minors pull two copies of bevy into the dependency tree and their types stop unifying.

> Whatever minor you land on is likely newer than this model's training data, so APIs may have changed under you. **Verify shapes against the installed version** rather than from memory: read the source under `~/.cargo/registry/src/.../bevy-*`, run `cargo doc --open`, or grep the crate. When a runtime log names a missing feature or a moved item, trust it over recollection.

## Project shape

One Cargo package: a tiny `src/main.rs` calling into `src/lib.rs` (which builds the `App`, sets the primary window, adds `DefaultPlugins`, registers a root `GamePlugin`), feature plugins under `src/game/`, and `assets/` for runtime-loaded files only (keep refs/captures out of it). Include dev-profile opt settings so iteration isn't glacial:

```toml
[dependencies]
bevy = "x.y.z"           # the exact version cargo add resolved; add features as needed, e.g. features = ["jpeg"] for jpg glTF textures
[profile.dev]
opt-level = 1
[profile.dev.package."*"]
opt-level = 3
```

Build gate: `cargo fmt` · `cargo check` · `cargo build`. Construct the world from systems run `OnEnter(state)` (spawn a world root, camera, lights, UI), mark entities for teardown on state exit, and keep `src/lib.rs` as the single `App`-wiring point.

## Verify against the installed version

A few things that have bitten real builds and won't error at compile time — check them if they bite:

- glTF scenes only load texture formats enabled in the manifest — `.jpg` textures load white until `features = ["jpeg"]` is set (the log says `feature "jpeg" is not enabled`).
- UI box properties (`border_radius`, layout) live **inside** the `Node` component, not as separately spawned bundle items.
- Procedural meshes are back-face culled by default — terrain wound the wrong way renders invisible (looks like "broken generation"; it's index order). A transform anchor with visible children needs both `Transform` and `Visibility`.

## Capture

Do **not** record the windowed binary — on headless Linux the primary-window path panics under virtual X even when it runs fine on a desktop. Use a **dedicated offscreen capture binary** (`src/bin/capture.rs`) in the same crate that reuses the real scene code but renders to a `RenderTarget::Image`:

- `DefaultPlugins` with `WindowPlugin { primary_window: None, exit_condition: DontExit }`, `WinitPlugin` disabled, and `ScheduleRunnerPlugin` as the runner.
- Allocate the target `Image` **directly in the world** (`world_mut().resource_mut::<Assets<Image>>()`) and publish its handle *before* the camera/`OnEnter` systems read it — adding it via `Commands` in `Startup` is deferred and yields black captures.
- Point the scene camera at `RenderTarget::Image(handle)`; capture with `Screenshot::image(handle).observe(save_to_disk(path))`. Saving is async — exit on a latched completion or an absolute finish tick recorded once, not `current_tick + delay`.
- Use `TimeUpdateStrategy::ManualDuration(1/30s)` so motion is deterministic across saved frames, and drive capture-time action from the script, not live input.
- Run it from the crate root (`cargo run --bin capture -- ...`) so `AssetServer` resolves `assets/` from the CWD. Quiet the logs with `RUST_LOG=warn` and a unique `[capture]` marker.

```bash
RESULT=screenshots/result/0
cargo run --bin capture -- frames "$RESULT" 450     # 450 frames @30fps = 15s
ffmpeg -y -framerate 30 -i "$RESULT/frame%05d.png" \
  -c:v libx264 -pix_fmt yuv420p -movflags +faststart "$RESULT/video.mp4"
```

Software Vulkan (`llvmpipe`) works for capture — just slower.

Bevy's `headless_renderer` and `screenshot` examples show the exact offscreen-render and still-capture wiring — read them from the Bevy repo for the current API.
````

## File: skills/engine-guide/godot-gdscript.md
size: 6649
sha: 475097a9dd229b6a53a1c59a5718d7a4e9d7eba5
upstream: https://github.com/htdt/godogen/blob/master/skills/engine-guide/godot-gdscript.md

````text
# Godot engine guide (GDScript)

Stack: **Godot 4**, **GDScript**, statically typed. Any Godot 4 build runs it — the standard build or the .NET one.

## Project shape

- `project.godot` — config, input actions, display, physics. **Match `config_version` to the installed toolchain** (`godot --version`) — don't hardcode it from memory; on an existing project preserve it. For 3D, set `3d/physics_engine="Jolt Physics"` and a fixed `physics_ticks_per_second`.
- `scripts/*.gd` runtime behavior · `scenes/*.tscn` scenes · `assets/` **only** files the running game loads (keep generation inputs/refs outside it).
- Build gate: `godot --headless --import` after asset changes and after adding or renaming a `class_name` (other scripts can't resolve it until then), then `godot --headless --check-only --script <file>.gd` on each changed script (exit 1 on parse and type errors), then `godot --headless --quit` (RID/ObjectDB-leak errors on headless exit are benign).

## Types are the only compile step

The parser checks what it can type; untyped code fails at runtime, and only on the path that runs. Type every declaration and signature. `:=` rejects values the parser can't type — calls on an untyped receiver (`load(...).instantiate()`), `abs`/`clamp`/`lerp`/`min`/`max`, reads from untyped arrays and dictionaries — so annotate the type (`var s: PackedScene = load(...)`) or use the typed variants (`absf`, `clampf`, `lerpf`, `maxi`, ...).

A runtime `SCRIPT ERROR` aborts only the function it's in: the game keeps running and the exit code stays 0. Gate headless runs on the log — grep it for `SCRIPT ERROR`.

## Scenes are generated at build time, not by hand

Write scenes as **`extends SceneTree` scripts** that build in `_initialize()`, run once headless, and emit a `.tscn`: `godot --headless --script scenes/build_x.gd`. A builder builds the node hierarchy, sets properties, attaches scripts, packs, and `quit()`s — it contains **no** runtime logic (no `_ready`/`_process`, signal connections, or game state). Build **leaf scenes first**, parents after, and `load()` them — a `preload()` of a scene that isn't generated yet is a parse error.

The serialization rules below are silent-failure — they pass the parser and drop nodes, values, or bloat files only in the saved `.tscn`:

- **Owner chain:** every node must have `owner` set to the scene root or it won't serialize. After building, walk the tree and set `child.owner = root` on all descendants — but **do not recurse into instantiated GLB/`.tscn` nodes** (those have a non-empty `scene_file_path`). Recursing into a GLB inlines all its meshes as text → 100MB+ `.tscn`.
- **Validate the pack:** count nodes before packing, `instantiate()` the `PackedScene` after, and compare counts; gate `ResourceSaver.save()` on the match. A silent drop otherwise looks like success.
- **Attach a script before setting its properties.** `set()` of an `@export` the node doesn't have yet is dropped without a warning — `set_script()` first, then assign.
- **Builder nodes are outside the tree.** `look_at()` and `global_*` log an error and the builder carries on — `look_at()` leaves the rotation unchanged, `global_position` lands as a local offset. Set local transforms; `Transform3D.looking_at()` composes a facing.

Sketch of the shared save path:

```gdscript
func pack_and_save(root: Node, path: String) -> void:
	set_owner_recursive(root, root)               # skip nodes with scene_file_path set
	var expected := count_nodes(root)
	var packed := PackedScene.new()
	if packed.pack(root) != OK:
		quit(1); return
	var test := packed.instantiate()
	var got := count_nodes(test)
	test.free()
	if got < expected:
		push_error("nodes dropped"); quit(1); return   # serialization failed silently
	ResourceSaver.save(packed, path)
	quit(0)
```

GLB models: instantiate the `PackedScene`, measure the `MeshInstance3D` AABB to scale, and use a **primitive** collision shape (Box/Sphere/Capsule) from the AABB — never `create_trimesh_shape()`/`create_convex_shape()` on imported meshes (drops to <1 FPS).

## Quirks worth knowing (silent-failure)

Most Godot behavior the model already knows; these few fail with no error:

- **On macOS a fatal error hangs instead of exiting.** Godot reports it in an `NSAlert` modal that `--headless` can't dismiss, so the process idles at 0% CPU forever (a missing main scene does it too). Run every `godot` call under `timeout`; exit 124 is the failure.
- **`SurfaceTool.generate_normals()`** is required for a procedural mesh to *receive* shadows. Without it (or with `CULL_DISABLED` as a "safety net"), shadows silently vanish — fix winding instead.
- **MultiMeshInstance3D + GLB** loses the mesh on pack/save; use individual instances. `material_override` on GLB-internal nodes also won't serialize (owner is skipped) — use a procedural `ArrayMesh` when a custom material is needed.
- **Raycasts don't reliably hit `ConcavePolygonShape3D`** (trimesh) — use a shape query or sample terrain height analytically.
- **`.gdignore`** in a directory makes the importer skip it silently — only `screenshots/` should have one, never `assets/`.
- Frame-rate-independent damping: `speed *= exp(-rate * delta)`, not `speed *= (1 - drag)` per tick.

## Capture

Video needs hardware **Vulkan** (Metal on macOS); software Vulkan (`llvmpipe`/`lavapipe`) is good for stills only. macOS has no `xvfb`, so capture runs in a real window there — adding `--headless` to `--write-movie` aborts (`Parameter "t" is null`).

Capture deterministically with Godot's movie writer from a dedicated capture `SceneTree` script under `test/`:

```bash
# under xvfb-run -a -s '-screen 0 1920x1080x24' on a headless Linux box; prefer the hardware Vulkan ICD
godot --headless --import
godot --write-movie screenshots/result/frame.png --fixed-fps 30 --quit-after 450 --script test/presentation.gd
ffmpeg -y -framerate 30 -pattern_type glob -i 'screenshots/result/frame*.png' \
  -c:v libx264 -pix_fmt yuv420p -movflags +faststart screenshots/result/video.mp4
```

`--fixed-fps` makes motion deterministic (450 frames @30fps = 15s). **Pre-position the camera** in the builder/`_initialize()` (the first movie frame renders before `_process`) — but `_ready()` of nodes added there runs after `_initialize()` returns and overwrites what it set on them. Autoloads are loaded, yet a `SceneTree` script can't name them — use `root.get_node("Name")`. Drive capture-time input from the script, not live keys. The movie writer also records the scene's audio, in sync, to `frame.wav` beside the frames: add it as a second ffmpeg input when the video needs sound.
````

## File: skills/engine-guide/godot.md
size: 5847
sha: 77f7c688e156acfe5e81d85d5d18432ec5ce7230
upstream: https://github.com/htdt/godogen/blob/master/skills/engine-guide/godot.md

````text
# Godot engine guide

Stack: **Godot 4 (.NET / Mono build)**, **C#**. All Godot C# classes must be `partial`.

## Project shape

- `project.godot` — config, input actions, display, physics. **Match version-sensitive fields to the installed toolchain** (`config_version`, and in `.csproj` the `Godot.NET.Sdk/...` version + `TargetFramework`) — run `godot --version` / `dotnet --version` and don't hardcode values from memory; on an existing project preserve them. For 3D, set `3d/physics_engine="Jolt Physics"` and a fixed `physics_ticks_per_second`.
- `{ProjectName}.csproj` — name must match `assembly_name`; `<EnableDynamicLoading>true</EnableDynamicLoading>`.
- `scripts/*.cs` runtime behavior · `scenes/*.tscn` scenes · `assets/` **only** files the running game loads (keep generation inputs/refs outside it).
- Build gate: `dotnet build`, then `godot --headless --import` after asset changes, then `godot --headless --quit` (RID-leak warnings on headless exit are benign).

## Scenes are generated at build time, not by hand

Write scenes as **C# `SceneTree` scripts** that run once headless and emit a `.tscn`: `godot --headless --script scenes/BuildX.cs`. A builder builds the node hierarchy, sets properties, attaches scripts, packs, and `Quit()`s — it contains **no** runtime logic (no `_Ready`/`_Process`, signals, or game state). Build **leaf scenes first**, parents after.

The serialization rules below are silent-failure — they pass compilation and drop nodes or bloat files only in the saved `.tscn`:

- **Owner chain:** every node must have `Owner` set to the scene root or it won't serialize. After building, walk the tree and set `child.Owner = root` on all descendants — but **do not recurse into instantiated GLB/`.tscn` nodes** (those have a non-empty `SceneFilePath`). Recursing into a GLB inlines all its meshes as text → 100MB+ `.tscn`.
- **Validate the pack:** count nodes before packing, `Instantiate()` the `PackedScene` after, and compare counts; gate `ResourceSaver.Save()` on the match. A silent drop otherwise looks like success.
- **`SetScript()` disposes the C# wrapper** — set scripts *last*, after the hierarchy is built. For the root, add it under a temp `Node`, set the script, then re-fetch it via `temp.GetChild(0)` before packing.

Sketch of the shared save path:

```csharp
void PackAndSave(Node root, string path) {
    SetOwnerRecursive(root, root);               // skip nodes with SceneFilePath set
    int expected = CountNodes(root);
    var packed = new PackedScene();
    if (packed.Pack(root) != Error.Ok) { Quit(1); return; }
    var test = packed.Instantiate(); int got = CountNodes(test); test.Free();
    if (got < expected) { GD.PushError("nodes dropped"); Quit(1); return; }   // serialization failed silently
    ResourceSaver.Save(packed, path);
    Quit(0);
}
```

GLB models: instantiate the `PackedScene`, measure the `MeshInstance3D` AABB to scale, and use a **primitive** collision shape (Box/Sphere/Capsule) from the AABB — never `CreateTrimeshShape()`/`CreateConvexShape()` on imported meshes (drops to <1 FPS).

## Quirks worth knowing (silent-failure)

Most Godot behavior the model already knows; these few fail with no error:

- **On macOS a fatal error hangs instead of exiting.** Godot reports it in an `NSAlert` modal that `--headless` can't dismiss, so the process idles at 0% CPU forever (a missing main scene does it too). Run every `godot` call under `timeout`; exit 124 is the failure. Output ending at `.NET: Initializing module...` means `GodotSharp/` wasn't found — `godot` on `PATH` is a symlink rather than a wrapper script.
- **`ArrayMesh.GenerateNormals()`** is required for a procedural mesh to *receive* shadows. Without it (or with `CullMode.Disabled` as a "safety net"), shadows silently vanish — fix winding instead.
- **MultiMeshInstance3D + GLB** loses the mesh on pack/save; use individual instances. `MaterialOverride` on GLB-internal nodes also won't serialize (owner is skipped) — use a procedural `ArrayMesh` when a custom material is needed.
- **Raycasts don't reliably hit `ConcavePolygonShape3D`** (trimesh) — use a shape query or sample terrain height analytically.
- **`.gdignore`** in a directory makes the importer skip it silently — only `screenshots/` should have one, never `assets/`.
- **C# enum names:** training data is GDScript-biased, so guessed C# enum names are often wrong (`BGMode.Sky`, not `BGModeEnum.Sky`). Verify against the installed Godot — read the C# API in the Godot docs/assemblies rather than guessing.
- Frame-rate-independent damping: `speed *= Mathf.Exp(-rate * delta)`, not `speed *= (1 - drag)` per tick.

## Capture

Video needs hardware **Vulkan** (Metal on macOS); software Vulkan (`llvmpipe`/`lavapipe`) is good for stills only. macOS has no `xvfb`, so capture runs in a real window there — adding `--headless` to `--write-movie` aborts (`Parameter "t" is null`).

Capture deterministically with Godot's movie writer from a dedicated capture `SceneTree` script under `test/`:

```bash
# under xvfb-run -a -s '-screen 0 1920x1080x24' on a headless Linux box; prefer the hardware Vulkan ICD
godot --headless --import
godot --write-movie screenshots/result/frame.png --fixed-fps 30 --quit-after 450 --script test/Presentation.cs
ffmpeg -y -framerate 30 -pattern_type glob -i 'screenshots/result/frame*.png' \
  -c:v libx264 -pix_fmt yuv420p -movflags +faststart screenshots/result/video.mp4
```

`--fixed-fps` makes motion deterministic (450 frames @30fps = 15s). **Pre-position the camera** in the builder/`_Initialize` (the first movie frame renders before `_Process`). Drive capture-time input from the script, not live keys. The movie writer also records the scene's audio, in sync, to `frame.wav` beside the frames: add it as a second ffmpeg input when the video needs sound.
````

## File: skills/engine-guide/html.md
size: 3087
sha: 723e73f0ada405708e40b88622bed1c8248d1583
upstream: https://github.com/htdt/godogen/blob/master/skills/engine-guide/html.md

```text
# HTML engine guide

Stack: **DOM + CSS + TypeScript**, **Vite**, Node (current LTS), with `<canvas>` and **three.js** wherever motion or a scene makes the game better. No UI framework: the page is the game. Made for 2D games built around text and UI — interactive fiction, card and board games, roguelikes on a character grid, puzzles, management and incremental games.

## Project shape

Scaffold a plain Vite + TS project (`npm create vite@latest . -- --template vanilla-ts`), then:

- One game-state object is the source of truth; rules are functions of state, and a `render()` brings the DOM up to date after every action.
- Fonts are self-hosted (`@fontsource/<name>`), the palette lives in CSS variables, and generated images (portraits, card art, backdrops) live under `src/assets/`, imported through Vite.
- Text and controls are DOM; animation and interactive elements can be canvas or three.js layered with it — don't limit the look to plain HTML.
- Build for the device the user plays on — the one the brief names, else a desktop browser — and make it look its best there: a rich page on that device beats a plain one that runs on any old phone.

Commands: `npm install` · `npm run dev` · `npm run build`.

**Bind the dev server to `0.0.0.0` on a fixed port** (`server: { host: true, port: 5173 }`) so `http://<host>:5173` is reachable from other machines on the LAN or through a tunnel.

## Quirks worth knowing (silent-failure)

- **Every edit reloads the page** and resets the game the user is in the middle of. Autosave state to `localStorage` after each action and restore on load. Version the save and discard a mismatched one — an old save loaded into a new state shape throws, and looks like a new bug. `?new` starts clean and `?seed=N` fixes the RNG.
- **Rewriting `innerHTML` destroys what lived there**: a text input's focus and caret, a log's scroll position, running transitions, listeners on children. Keep the command line and the scrolling log outside the re-rendered region (append to the log), and handle clicks by delegation on a stable parent.
- **Headless Chrome renders WebGL in software** (SwiftShader), slowly or blank, so a three.js layer can be missing from a capture and fine in a browser. On Linux run under `xvfb-run` with `--use-angle=vulkan`, and read the WebGL `RENDERER` string before trusting the shot.
- **Glyph fallback.** A character missing from the font is drawn from whatever system font has it, at its own width — a character grid drifts out of line, and a machine without an emoji font draws emoji as empty boxes. Pick a monospace font that covers the glyph set (box drawing, arrows, suits) and keep emoji out of grids.
- **Hidden tabs stall time.** `requestAnimationFrame` stops and timers drop to about once a second in a background tab. Compute idle and real-time progress from elapsed wall-clock time, not from tick counts.
- **Sound needs a gesture.** An `AudioContext` created before the first click or key stays suspended, and `play()` rejects, with only a console warning. Resume it in the first input handler.
```

## File: skills/engine-guide/setup.md
size: 3071
sha: 621aed2183881fc05cd90d099c51cdc82d0a377f
upstream: https://github.com/htdt/godogen/blob/master/skills/engine-guide/setup.md

```text
# Setup

Install what the chosen engine needs, at the current stable release. Every toolchain here has moved past what training data knows, so resolve "latest" at install time (the release page or API, the package manager), never from memory. On an existing project, keep the versions it pins. System packages need root; when you don't have it, give the user the one command to run.

## All engines

- `ffmpeg` (encoding captures), ImageMagick (`magick`), and on headless Linux `xvfb` (a virtual display) and `vulkan-tools` (`vulkaninfo`).
- Video capture wants a hardware GPU path; software rendering (`llvmpipe`, `lavapipe`, SwiftShader) is good for stills only. On Linux, `vulkaninfo --summary` names the device; with an NVIDIA GPU, `VK_ICD_FILENAMES=/usr/share/vulkan/icd.d/nvidia_icd.json` selects it.
- macOS has no `timeout`, which the Godot guide wraps every call in: `brew install coreutils` provides it as `gtimeout`.

## Godot

The current stable is the newest release on GitHub: `curl -s https://api.github.com/repos/godotengine/godot/releases/latest` gives the tag (`X.Y.Z-stable`) and its asset names.

- **C# needs the .NET build** (`..._mono_linux_x86_64.zip`). The standard build (`..._linux.x86_64.zip`) runs only GDScript; the .NET build runs both. `godot --version` ends in `.mono` for the .NET build.
- **`GodotSharp/` must sit next to the binary** that runs. The .NET zip holds both: move them together, e.g. the binary to `/usr/local/bin/godot` and `GodotSharp/` to `/usr/local/bin/GodotSharp/` (or both into `~/.local/bin/` without root).
- **macOS:** `brew install --cask godot-mono` for C#; the plain `godot` cask's command runs without C#. Make `godot` on `PATH` a wrapper script, not a symlink — `exec /Applications/Godot_mono.app/Contents/MacOS/Godot "$@"` — since Godot looks for `GodotSharp/` beside the path it was invoked as, and through a symlink it hangs on a fatal-error modal that `--headless` can't dismiss.
- **.NET SDK for C#:** the newest one (`dotnet-install.sh` from dot.net into `~/.dotnet`, with `DOTNET_ROOT` set and it on `PATH`; `brew install dotnet` on macOS). A newer SDK builds an older target framework, and Godot raises the one it writes into new projects over releases.
- **Check:** `timeout 60 godot --headless --quit` (RID-leak warnings are harmless). Assembly errors on Linux, or a timeout with output ending at `.NET: Initializing module...` on macOS, mean `godot` can't find `GodotSharp/`.

## Bevy

Rust through rustup on current stable (`rustup update stable`). Linux builds link system libraries (ALSA, udev, X11 or Wayland): Bevy's `docs/linux_dependencies.md` lists the packages per distro.

## Babylon.js, three.js, HTML

- Node.js at the current LTS, from nodejs.org or a version manager. Vite's minimum rises with its releases, and `npm create vite@latest` says when the installed Node is too old.
- Chrome or Chromium for headless runs; set `CHROME_BIN` when it isn't on a common path. Babylon.js and three.js capture, and HTML games that use three.js, need hardware WebGL2 (their guides, Capture).
```

## File: skills/engine-guide/threejs.md
size: 3776
sha: a129e2eb878a1392f2f4d774575dd1a844713bed
upstream: https://github.com/htdt/godogen/blob/master/skills/engine-guide/threejs.md

```text
# three.js engine guide

Stack: **three.js** (`three`), **Vite**, **TypeScript**, Node (current LTS).

> three ships a release a month and deprecates as it goes, so the installed one is likely newer than this model's training data. When the console warns that something is deprecated, follow it; for exact shapes read `node_modules/three/src` (addons under `node_modules/three/examples/jsm`), not memory.

## Project shape

A plain Vite + TS project is enough. Scaffold one (`npm create vite@latest . -- --template vanilla-ts`), add `three` and `@types/three` on the same `0.N` release (three ships no types of its own), then:

- A fullscreen `<canvas>`, a `WebGLRenderer` driven by `renderer.setAnimationLoop`, and resize on `window`. Addons (loaders, controls, postprocessing, `SkeletonUtils`) import from `three/addons/...`.
- Put gameplay in `src/` modules; keep generated assets under `src/assets/` and load them through Vite (`import url from './assets/x.glb?url'`).
- three is a renderer, not an engine — physics, UI, and audio are yours to choose. For physics, `@dimforge/rapier3d-compat` inlines its wasm (`await RAPIER.init()` before use); the plain `@dimforge/rapier3d` imports `.wasm` as a module, which Vite doesn't handle without a plugin.

Commands: `npm install` · `npm run dev` · `npm run build`.

**Bind the dev server to `0.0.0.0` on a fixed port** (`server: { host: true, port: 5173 }`) so `http://<host>:5173` is reachable from other machines on the LAN or through a tunnel.

## Quirks worth knowing (silent-failure)

- **Color space.** Textures you load or build yourself default to `NoColorSpace`; set `colorSpace = SRGBColorSpace` on color maps (albedo, sprites, UI, sky) or they render washed out. The glTF loader tags its own.
- **Lights are physical.** Point and spot lights fall off with inverse-square (`decay = 2`) — intensities from older examples leave the scene near-black a few meters out. A directional light's shadow camera spans ±5 units: size `light.shadow.camera` to the play area and move it with the player, or shadows stop at its edge.
- **Rigged clones.** `clone()` on a skinned GLB keeps the copy bound to the original's bones, so it renders in the original's pose. Clone rigs with `SkeletonUtils.clone()`.
- **WebGPU falls back.** `WebGPURenderer` (`three/webgpu`, TSL node materials) runs on its WebGL2 backend when the browser has no WebGPU adapter, with only a console warning — check `renderer.backend.isWebGPUBackend` before trusting a capture of a WebGPU-only effect.

## Capture

Load the running dev URL in headless Chrome/Chromium (`playwright-core`, or `google-chrome --headless`) and screenshot.

- **Use a real GPU.** Headless Chrome silently falls back to SwiftShader/llvmpipe, which renders slowly or blank. On Linux, run under `xvfb-run` and request hardware (`--use-angle=vulkan`); read the WebGL `RENDERER` string and warn if it contains `swiftshader`/`llvmpipe`/`lavapipe`.
- **Wait before shooting.** Capture only after the scene has rendered a frame and textures/GLBs have loaded — gate on a ready flag the game sets. Screenshotting too early gives a misleading blank frame.
- **Step time from the capture script.** A screenshot takes longer than a frame, so shooting the live loop on an interval gives a sped-up, stuttering clip. Give the game a capture mode (a query flag) that stops `setAnimationLoop` and exposes a hook advancing one fixed 1/30 s step and rendering; shoot after each call — 450 steps = 15 s. Reading pixels with `canvas.toDataURL()` returns blank unless it runs right after `render()` in the same task, or the renderer has `preserveDrawingBuffer: true`.
- **Video:** encode the frames at ~720p: `ffmpeg -framerate 30 -i frame_%04d.png -c:v libx264 -pix_fmt yuv420p video.mp4`.
```

## File: README.md
upstream: https://github.com/htdt/godogen/blob/master/README.md

````text
# Godogen

Skills for Claude Code, Codex and Antigravity to build games, and anything else a game engine renders well: video presentations, trailers, interactive 3D.

The agent is already a capable developer. Godogen doesn't plan for it, check its work or decide when it's done. It provides tools and building blocks the agent can't work out fast on its own, and stays out of the way.

## Two skills

- **engine-guide**: Godot (C# or GDScript), Bevy, Babylon.js, three.js and HTML. How to choose between them, a project sketch, headless capture to screenshots and video, and the traps that fail without an error. You pick the engine with the agent, per project.
- **asset-gen**: images, sprites and animated sprites from GPT-Image-2.6; textured 3D, rigged and animated humanoids, sound effects and voice, free on your GPU with [godogen_assets](https://github.com/htdt/godogen_assets); Blender for exact 3D; paid APIs for the rest. Your brief sets the spend.

## Install

In your project folder (needs Node.js):

```bash
npx skills add htdt/godogen
```

The [skills CLI](https://github.com/vercel-labs/skills) asks which agents you use and puts both skills in the project's `.agents/skills/`, which Codex and Antigravity read, with links from `.claude/skills/` for Claude Code. Commit them and every clone of the project has them. `-g` installs them for all your projects instead, and `npx skills update` brings new versions.

The agent installs what the chosen engine and the assets need, at current versions. Only you can provide:

- API keys for paid generation, as environment variables: `OPENAI_API_KEY` (images, recommended), `XAI_API_KEY`, `GEMINI_API_KEY` (or `GOOGLE_API_KEY`), `TRIPO_API_KEY`.
- For free local 3D, sound and voice: an NVIDIA GPU, on which the agent sets up [godogen_assets](https://github.com/htdt/godogen_assets).

<details>
<summary>Install from a clone</summary>

To work on the skills, or to update them with `git pull`, link a clone into each agent's user skills folder:

```bash
git clone https://github.com/htdt/godogen && cd godogen
mkdir -p ~/.claude/skills && ln -sfn "$PWD"/skills/* ~/.claude/skills/                 # Claude Code
mkdir -p ~/.agents/skills && ln -sfn "$PWD"/skills/* ~/.agents/skills/                 # Codex
mkdir -p ~/.gemini/config/skills && ln -sfn "$PWD"/skills/* ~/.gemini/config/skills/   # Antigravity
```

Antigravity skips linked folders inside a project's `.agents/skills/`, so copy them there rather than link.

</details>

## Use

Open the agent in the project (an empty folder for something new) and describe what you want: a game, a video, an interactive page.

- The skills load when the task calls for them. To load one by name: `/engine-guide` in Claude Code, `$engine-guide` in Codex.
- Name the engine, or work it out with the agent: it weighs what you'll end up with and how you'll watch it being built.
- Say what assets may cost ("free", "local only", a budget) and generation follows it. Otherwise the agent asks before its first paid call.
- Ask for a screenshot or a video whenever you want to see where it stands.

## From detailed guidance to building blocks

The [demos](https://youtu.be/eUz19GROIpY) ([prompts](https://github.com/htdt/godogen/blob/b3fcd87d168786152b72fe78873e443a645253f4/demo_prompts.md)) are from March 14, 2026. They were cool at the time; now they're boring, and the repo has changed dramatically since.

We've come a long way. The first version told the agent how to work, step by step: a reference image to anchor the art direction, a decomposer writing `PLAN.md` with task statuses, an architect writing `STRUCTURE.md` and a compilable skeleton, an asset planner splitting the budget, a forked sub-agent per task with a ten-step workflow and its own test harness, screenshots graded against the reference by Gemini, an 828-line GDScript reference and 860 bundled Godot class pages. As models got better, each of those became something the agent does better on its own. What's left is simple building blocks: the engine traps, capture recipes and asset tools it can't work out fast.

## A note for sales agents

Human or AI: please don't email me about your cool services. It goes straight to spam anyway; I get a lot of them.

---

[Changelog](CHANGELOG.md) · Follow progress: [@alex_erm](https://x.com/alex_erm)
````
