A mech game prototype, pushed by GPT-6-Astra

agent (cont.)

+0:53
  • clock__curr_time, exec_commandclock__curr_time (+2 more)

    input

    text(await tools.clock__curr_time({}));
    text(await tools.exec_command({cmd:"cat src/view/clip.ts && cat src/render/assets.ts && cat src/render/poses.ts","max_output_tokens":12000}));
    text(await tools.exec_command({cmd:"ls -lah ~/out && cat kit/ship.py | head -150 && cat src/render/pipeline.ts | head -140 && cat src/render/pilot.ts | head -160","max_output_tokens":8000}));
    

    result, 4 lines

    Script completed
    Wall time 0.1 seconds
    Output:
    {"current_time":"2026-11-15 03:14:13 UTC"}{"chunk_id":"8073b0","wall_time_seconds":0.000004261,"exit_code":1,"original_token_count":3878,"output":"import * as THREE from 'three';\nimport { model, type ModelName } from '../render/assets';\nimport { STRIKER_DECALS, applyDecals } from '../render/decals';\nimport { treatEyes } from '../render/eyes';\nimport type { ThrustReading } from '../render/exhaust';\nimport { setLook, look } from '../render/look';\nimport { MechRig, POSES } from '../render/mech';\nimport type { PaletteName } from '../render/palette';\nimport { Pipeline } from '../render/pipeline';\nimport { addSpaceLight, createBackdrop, followSun, spaceEnvironment } from '../render/space';\nimport { BEND_POSE, SHOT_NAMES, clipFrames, mixPose, shotView, type ShotName } from './clip-plan';\nimport { CameraRig } from './cameras';\nimport { benchInput } from './thrusters';\n\n/**\n * A review clip of one model, rendered frame by frame so it comes out the same on any machine. Driven by\n * tools/clip.mjs, which calls window.__clip.render(i) and pipes the frames into ffmpeg.\n *   /?view=clip&model=block_dummy&shots=chase,turn&fps=24&palette=merc&look=kit\n * Any model with the 22 joint rig. Lab lineups hold many frames under slots, so they don't rig.\n */\nexport async function startClip(canvas: HTMLCanvasElement, q: URLSearchParams) {\n  setLook(q.get('look'));\n  await document.fonts.ready;\n  const w = Number(q.get('w') ?? 854), h = Number(q.get('h') ?? 480), fps = Number(q.get('fps') ?? 24);\n  const shots = (q.get('shots')?.split(',') ?? SHOT_NAMES) as ShotName[];\n  const frames = clipFrames(shots, fps);\n\n  const scene = new THREE.Scene();\n  const camera = new THREE.PerspectiveCamera(35, w / h, 0.3, 2e5);\n  const backdrop = createBackdrop();\n  const pipe = new Pipeline(canvas, scene, camera, backdrop);\n  pipe.resize(w, h);\n  const sun = addSpaceLight(scene);\n  scene.environment = spaceEnvironment(pipe.renderer, backdrop);\n  scene.environmentIntensity = 0.8 * look().fill;\n\n  const name = (q.get('model') ?? 'striker') as ModelName;\n  const palette = (q.get('palette') ?? 'merc') as PaletteName;\n  const root = await model(name, palette);\n  if (name === 'striker') applyDecals(root, STRIKER_DECALS);\n  treatEyes(root, 'spill');\n  scene.add(root);\n  const rig = new MechRig(root);\n  root.updateMatrixWorld(true);\n  rig.apply(POSES.stand);\n  root.updateMatrixWorld(true);\n  const box = new THREE.Box3().setFromObject(root);\n  const height = box.getSize(new THREE.Vector3()).y;\n  const footY = box.min.y;\n  const size = height / 17.6;\n\n  const light = new THREE.PointLight('#ffffff', 0, 0, 2);\n  scene.add(light);\n\n  // the pilot and deck for the scale shot: a person is the one thing everyone knows the size of\n  const ground = new THREE.Group();\n  const deck = new THREE.Mesh(new THREE.CircleGeometry(height * 2, 48), new THREE.MeshStandardMaterial({ color: '#2a2f36', roughness: 0.85, metalness: 0.2 }));\n  deck.rotation.x = -Math.PI / 2;\n  deck.position.y = footY;\n  ground.add(deck);\n  const pilot = await model('lab_pilot' as ModelName, palette);\n  pilot.traverse((o) => { if (/^slot\\d+$/.test(o.name) && o.name !== 'slot0') o.visible = false; });\n  // lab slot 0 stands at x = -.55: bring the pilot beside the frame's foot, facing the camera\n  pilot.position.set(0.55 + height * 0.3, footY, height * 0.16);\n  pilot.rotation.y = 0.4;\n  ground.add(pilot);\n  scene.add(ground);\n\n  // the game's chase camera, read for its numbers: this view moves its own camera\n  const chase = new CameraRig();\n  const reading: ThrustReading = { x: 0, y: 0, z: 0, boosting: false };\n  const centre = new THREE.Vector3();\n  const offset = new THREE.Vector3();\n  const look_ = new THREE.Vector3();\n  const up = new THREE.Vector3(0, 1, 0);\n  const yawQ = new THREE.Quaternion();\n  const DT = 1 / 120;\n  let clock = 0;\n\n  const feed = (state: Parameters<typeof benchInput>[0], t: number, dt: number) => {\n    const f = benchInput(state, t);\n    reading.x = f.thrust.x;\n    reading.y = f.thrust.y;\n    reading.z = f.thrust.z;\n    reading.boosting = f.boosting;\n    reading.assault = f.assault;\n    reading.quick = f.quick;\n    rig.thrust(reading, clock, dt);\n    rig.lightExhaust(light);\n  };\n\n  const render = (i: number) => {\n    const f = frames[i];\n    const v = shotView(f);\n    // thrusters step at 120 Hz whatever the clip's frame rate, as a game would\n    const dt = f.cut ? 0 : 1 / fps;\n    if (f.cut) for (let k = 0; k < 120; k++) { clock += DT; feed('idle', k * DT, DT); }\n    for (let s = 0; s < dt - 1e-9; s += DT) {\n      clock += DT;\n      feed(f.state, Math.max(0, f.stateT - dt + s), DT);\n    }\n    if (dt === 0) feed(f.state, f.stateT, 0);\n\n    root.rotation.y = THREE.MathUtils.degToRad(v.mechYaw);\n    rig.apply(v.bend > 0 ? mixPose(POSES.stand, BEND_POSE, v.bend) : POSES[v.pose]);\n    root.updateMatrixWorld(true);\n    ground.visible = v.ground;\n    centre.set(0, footY + height * v.lookAt, 0);\n    const fov = v.chase ? chase.camera.fov : 35;\n    if (camera.fov !== fov) {\n      camera.fov = fov;\n      camera.updateProjectionMatrix();\n    }\n    if (v.chase) {\n      // where the game's chase camera sits (src/view/cameras.ts), over the shoulder, scaled to the frame\n      yawQ.setFromAxisAngle(up, THREE.MathUtils.degToRad(v.camYaw));\n      offset.set(chase.shoulder * size, chase.chaseOffset.y * size, chase.chaseOffset.z * size).applyQuaternion(yawQ);\n      camera.position.copy(centre).add(offset);\n      look_.set(chase.shoulder * size, (chase.chaseOffset.y - chase.lookDrop) * size, 400).applyQuaternion(yawQ).add(centre);\n      camera.up.copy(up);\n      camera.lookAt(look_);\n    } else {\n      const yaw = THREE.MathUtils.degToRad(v.camYaw), pitch = THREE.MathUtils.degToRad(v.pitch);\n      camera.position.set(Math.sin(yaw) * Math.cos(pitch), Math.sin(pitch), Math.cos(yaw) * Math.cos(pitch)).multiplyScalar(v.dist * height).add(centre);\n      if (v.ground) camera.position.y = Math.max(camera.position.y, footY + 1.6); // eye height, above the deck\n      camera.up.copy(up);\n      camera.lookAt(centre);\n    }\n    camera.updateMatrixWorld(true);\n    followSun(sun, centre);\n    pipe.render();\n    // read straight after the draw, in the same task, while the buffer still holds it\n    return canvas.toDataURL('image/jpeg', 0.93);\n  };\n\n  const win = window as unknown as { __clip: unknown; __ready: boolean };\n  win.__clip = { frames: frames.length, fps, render };\n  win.__ready = true;\n}\nimport * as THREE from 'three';\nimport { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';\nimport { mergeGeometries } from 'three/addons/utils/BufferGeometryUtils.js';\nimport { MeshoptDecoder } from 'three/addons/libs/meshopt_decoder.module.js';\nimport { PALETTES, type PaletteName } from './palette';\nimport { DETAIL_LAYER } from './pipeline';\nimport { BARE, isRole, material } from './materials';\n\nconst loader = new GLTFLoader();\nloader.setMeshoptDecoder(MeshoptDecoder);\nconst sources = new Map<string, Promise<THREE.Object3D>>();\n\n/** Every model the kit builds (kit/build.py). */\nexport type ModelName = 'alien_acicular' | 'alien_druse' | 'alien_druse_mimic' | 'alien_geode'\n  | 'striker' | 'striker_a' | 'striker_b' | 'light' | 'light_line' | 'light_lancer' | 'heavy' | 'heavy_B' | 'heavy_C'\n  | 'auto_tally' | 'auto_tick' | 'auto_ledger' | 'rifle' | 'cannon' | 'drone' | 'cockpit' | 'cockpit_light' | 'ship' | 'station'\n  | 'wreck_field' | 'salvage_pod' | 'escape_pod' | 'raider_grunt' | 'raider_brawler' | 'raider_boss';\n\n/**\n * Models ship as .glb. Artifact pages serve neither .glb nor fetches of data: URLs, so the artifact\n * build wraps each model as base64 in JSON (VITE_MODEL_EXT=glb.json) and the page decodes it here.\n * Those are squeezed (tools/squeeze.mjs): meshopt compressed, plus a quantized-only copy\n * (.q.glb.json) for a page that can't run the WebAssembly decoder.\n */\nconst EXT: string = import.meta.env.VITE_MODEL_EXT ?? 'glb';\nconst meshopt: Promise<boolean> = EXT === 'glb' ? Promise.resolve(true) : MeshoptDecoder.ready.then(() => true, () => false);\n\nasync function fetchGlb(url: string): Promise<ArrayBuffer> {\n  const res = await fetch(url);\n  if (!res.ok) throw new Error(`${url}: ${res.status}`);\n  if (!url.endsWith('.json')) return res.arrayBuffer();\n  const b64 = (await res.json()).glb as string;\n  const bin = atob(b64);\n  const out = new Uint8Array(bin.length);\n  for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);\n  return out.buffer;\n}\n\n/** Models loading now and loaded so far, for a loading indicator. */\nexport const loading = { pending: 0, done: 0, listeners: new Set<() => void>() };\nfunction track<T>(p: Promise<T>): Promise<T> {\n  loading.pending++;\n  const tell = () => {\n    for (const f of loading.listeners) f();\n  };\n  tell();\n  const end = () => {\n    loading.pending--;\n    loading.done++;\n    tell();\n  };\n  p.then(end, end);\n  return p;\n}\n\nfunction source(name: ModelName, merge = true): Promise<THREE.Object3D> {\n  const key = merge ? name : `${name}:parts`;\n  let p = sources.get(key);\n  if (!p) {\n    const url = (ok: boolean) => `${import.meta.env.BASE_URL}assets/${name}.${ok ? EXT : `q.${EXT}`}`;\n    p = track(meshopt.then((ok) => fetchGlb(url(ok))).then((glb) => parseModel(glb, merge)));\n    sources.set(key, p);\n  }\n  return p;\n}\n\n/** A model's scene from GLB bytes, plain or squeezed. `merge` false keeps every part its own mesh. */\nexport async function parseModel(glb: ArrayBuffer, merge = true): Promise<THREE.Object3D> {\n  const root = unquantize((await loader.parseAsync(glb, '')).scene);\n  return merge ? mergeParts(root) : root;\n}\n\n/** Start loading models now, side by side, so later awaits find them ready. */\nexport function preload(names: Iterable<ModelName>) {\n  for (const n of names) source(n).catch((e) => console.error(e));\n}\n\n/** A fresh copy of a model, painted with a palette and tagged for ink lines. `merge` false keeps every\n *  part its own mesh, for models whose parts move apart (the aliens). */\nexport async function model(name: ModelName, palette: PaletteName = 'merc', merge = true): Promise<THREE.Object3D> {\n  const root = (await source(name, merge)).clone(true);\n  paint(root, palette);\n  return root;\n}\n\nexport function paint(root: THREE.Object3D, palette: PaletteName) {\n  const pal = PALETTES[palette];\n  // the plumes (render/mech.ts) take their colour from the same palette\n  root.userData.palette = palette;\n  root.traverse((o) => {\n    const mesh = o as THREE.Mesh;\n    if (!mesh.isMesh) return;\n    const src = mesh.userData.role ?? (mesh.material as THREE.Material).name;\n    mesh.userData.role = src;\n    if (isRole(src)) mesh.material = material(pal, src, palette);\n    const glows = (mesh.material as THREE.MeshBasicMaterial).isMeshBasicMaterial;\n    mesh.castShadow = !glows;\n    mesh.receiveShadow = !glows;\n    if (glows || BARE.has(src)) mesh.layers.disable(DETAIL_LAYER);\n    else mesh.layers.enable(DETAIL_LAYER);\n  });\n}\n\n/** Named nodes of a model, for joints and markers. */\nexport function nodes(root: THREE.Object3D): Map<string, THREE.Object3D> {\n  const out = new Map<string, THREE.Object3D>();\n  root.traverse((o) => {\n    if (o.name) out.set(o.name, o);\n  });\n  return out;\n}\n\n/** glTF node names lose dots (three.js sanitises them to underscores); look up either form. */\nexport function find(map: Map<string, THREE.Object3D>, name: string): THREE.Object3D | undefined {\n  return map.get(name) ?? map.get(name.replace(/\\./g, '_')) ?? map.get(name.replace(/\\./g, ''));\n}\n\n/**\n * Rigid parts that share a joint and a material become one mesh: a frame is ~150 parts but only a\n * few dozen joint/material pairs, and every mesh is a draw call (twice, with shadows).\n */\nfunction mergeParts(root: THREE.Object3D): THREE.Object3D {\n  const groups = new Map<THREE.Object3D, Map<THREE.Material, THREE.Mesh[]>>();\n  root.traverse((o) => {\n    const m = o as THREE.Mesh;\n    if (!m.isMesh || m.children.length || !m.parent || Array.isArray(m.material)) return;\n    let byMat = groups.get(m.parent);\n    if (!byMat) groups.set(m.parent, (byMat = new Map()));\n    const list = byMat.get(m.material) ?? [];\n    list.push(m);\n    byMat.set(m.material, list);\n  });\n  for (const [parent, byMat] of groups) {\n    for (const [mat, meshes] of byMat) {\n      if (meshes.length < 2) continue;\n      const geoms = meshes.map((m) => {\n        m.updateMatrix();\n        const g = m.geometry.clone();\n        for (const k of Object.keys(g.attributes)) if (k !== 'position' && k !== 'normal') g.deleteAttribute(k);\n        return g.applyMatrix4(m.matrix);\n      });\n      const merged = mergeGeometries(geoms, false);\n      if (!merged) continue;\n      const mesh = new THREE.Mesh(merged, mat);\n      mesh.name = `${parent.name}:${mat.name}`;\n      mesh.userData = { ...meshes[0].userData };\n      for (const m of meshes) m.removeFromParent();\n      parent.add(mesh);\n    }\n  }\n  return root;\n}\n\n/** tools/squeeze.mjs puts each mesh on a child node of this name, holding its dequantizing transform. */\nconst QUANT_NODE = 'q__';\n\n/** A float copy of a (possibly quantized) vec3 attribute, as unit vectors if `unit`. */\nfunction toFloat(a: THREE.BufferAttribute | THREE.InterleavedBufferAttribute, unit = false) {\n  const out = new THREE.Float32BufferAttribute(a.count * 3, 3);\n  for (let i = 0; i < a.count; i++) {\n    _v.fromBufferAttribute(a, i);\n    if (unit) _v.normalize();\n    out.setXYZ(i, _v.x, _v.y, _v.z);\n  }\n  return out;\n}\nconst _v = new THREE.Vector3();\n\n/**\n * Fold squeezed meshes back into the nodes the kit built: bake each quantized mesh's transform into\n * float vertices and put the mesh where its node was, with the node's name, transform, extras and\n * children. A plain GLB passes through untouched.\n */\nfunction unquantize(root: THREE.Object3D): THREE.Object3D {\n  const found: THREE.Object3D[] = [];\n  root.traverse((o) => {\n    if (o.name.startsWith(QUANT_NODE)) found.push(o);\n  });\n  // a mesh used by several nodes shares its geometry: each gets its own before any is baked\n  const seen = new Set<THREE.BufferGeometry>();\n  for (const q of found) {\n    q.traverse((o) => {\n      const m = o as THREE.Mesh;\n      if (!m.isMesh) return;\n      if (seen.has(m.geometry)) m.geometry = m.geometry.clone();\n      seen.add(m.geometry);\n    });\n  }\n  const bake = (m: THREE.Mesh, matrix: THREE.Matrix4) => {\n    const g = m.geometry;\n    g.setAttribute('position', toFloat(g.attributes.position).applyMatrix4(matrix));\n    if (g.attributes.normal) g.setAttribute('normal', toFloat(g.attributes.normal, true));\n    g.boundingBox = null;\n    g.computeBoundingSphere();\n  };\n  for (const q of found) {\n    const node = q.parent!;\n    q.updateMatrix();\n    if (!(q as THREE.Mesh).isMesh) {\n      // a mesh of several primitives: its parts go straight under the node\n      for (const c of [...q.children] as THREE.Mesh[]) {\n        c.updateMatrix();\n        bake(c, q.matrix.clone().multiply(c.matrix));\n        c.position.set(0, 0, 0);\n        c.quaternion.identity();\n        c.scale.set(1, 1, 1);\n        node.add(c);\n      }\n      q.removeFromParent();\n      continue;\n    }\n    // the mesh takes its node's place\n    const mesh = q as THREE.Mesh;\n    bake(mesh, mesh.matrix);\n    mesh.name = node.name;\n    mesh.userData = { ...mesh.userData, ...node.userData };\n    mesh.position.copy(node.position);\n    mesh.quaternion.copy(node.quaternion);\n    mesh.scale.copy(node.scale);\n    mesh.visible = node.visible;\n    for (const c of [...node.children]) if (c !== mesh) mesh.add(c);\n    const parent = node.parent!;\n    parent.children[parent.children.indexOf(node)] = mesh;\n    mesh.parent = parent;\n    node.parent = null;\n  }\n  return root;\n}\ncat: src/render/poses.ts: No such file or directory\n"}{"chunk_id":"1b459e","wall_time_seconds":0.000008921,"exit_code":0,"original_token_count":3609,"output":"total 8.0K\ndrwx------ 2 runner runner 4.0K Nov 15 03:12 .\ndrwx------ 6 runner runner 4.0K Nov 15 03:12 ..\n\"\"\"The mercenary ship: every merc flies this medium class (about 235 m). Bow is -Y.\n\nInside the lower hull, a hangar (two mech bays) opens forward into the launch tube, which runs to a\ndoor at the bow. The hull is one solid with the hangar and tube cut out, so the cavity walls are the\ninterior walls. Markers for the game:\n  launch.start  where a mech stands on the shuttle      launch.end  where the shuttle stops\n  shuttle       the catapult sled (moves along -Y)      door.L/R    bow door halves (slide out along X)\n  bay.1, bay.2  hangar bays                             light.N     point lights (color, intensity)\n  signal.red/green  launch lamps                        nozzle.ship.N  engine exits\n\nBays and the shuttle fit every frame class (docs/sizes.md). Each bay carries three gantry fits and the\ngame shows one per bay (ShipRig.configure):\n  gantry.N.light  two cradles side by side with boarding platforms at the core block, decks parked high\n  gantry.N.std    the striker fit: work decks at 8 and 15.5 m\n  gantry.N.heavy  the reinforced bay: jacketed and braced posts, clamp arms, decks at 11 and 21 m\nStanding points: bay.N.light.a, bay.N.light.b, bay.N.std, bay.N.heavy (extras: cls, platforms).\nThe shuttle carries clamps.std, clamps.light (a raised sled) and clamps.heavy (outriggers), with a\nlaunch.start.<cls> marker for each (launch.start is the striker's).\n\"\"\"\nfrom mathutils import Matrix, Vector\n\nfrom lib import boolean, cylinder, empty, loft, merge, mirror_x, nozzle, octo, piston, prism, solid, transform\nfrom mech import gltf_dir, place\n\nTUBE_W, TUBE_H = 9.0, 26.0          # half width, height\nTUBE_Y0, TUBE_Y1 = -16.0, -122.0    # hangar end, bow end\nHANGAR = dict(x=24.0, y0=-16.0, y1=34.0, h=30.0)\n\n# lower hull stations: (y, width, height, chamfer, z centre)\nLOWER = [(-120, 24, 32, 6, 13), (-60, 30, 36, 7, 13), (-22, 58, 44, 8, 14), (60, 58, 44, 8, 14), (96, 48, 40, 9, 16)]\n\n\ndef section(stations, y, grow=0.0):\n    for (y0, *a), (y1, *b) in zip(stations, stations[1:]):\n        if y0 <= y <= y1:\n            t = (y - y0) / (y1 - y0)\n            w, h, c, z = (p + (q - p) * t for p, q in zip(a, b))\n            return octo(w + grow, h + grow, c, y=z)\n    raise ValueError(y)\n\n\ndef box(x0, x1, y0, y1, z0, z1):\n    return loft([(z0, [(x0, y0), (x1, y0), (x1, y1), (x0, y1)]), (z1, [(x0, y0), (x1, y0), (x1, y1), (x0, y1)])])\n\n\nBAYS = ((1, 16.0), (2, -16.0))\nBAY_Y, BAY_HW, BAY_Y0, BAY_Y1 = 10.0, 6.0, 3.0, 17.0   # bay centre, half width, front and back (12 by 14 m)\nGANTRY_H = 26.0\n# work platform heights per class, m: the striker's are the original decks\nDECKS = {\"light\": (4.4,), \"standard\": (8.0, 15.5), \"heavy\": (11.0, 21.0)}\nLIGHT_DX = 3.0     # light cradles either side of the bay centre\nHEAVY_Y = 9.2      # a heavy stands a little forward, clear of its deeper back deck\nSTOW = 22.5        # where the work decks park when the bay is fitted for light frames\n\n\ndef beam(p0, p1, w=.5, h=None):\n    \"\"\"A square beam from p0 to p1.\"\"\"\n    h = w if h is None else h\n    p0, p1 = Vector(p0), Vector(p1)\n    axis = p1 - p0\n    m = Matrix.Translation(p0) @ Vector((0, 0, 1)).rotation_difference(axis.normalized()).to_matrix().to_4x4()\n    r = [(-w / 2, -h / 2), (w / 2, -h / 2), (w / 2, h / 2), (-w / 2, h / 2)]\n    return transform(loft([(0, r), (axis.length, r)]), m)\n\n\ndef corners(bx):\n    return [(px, py) for px in (bx - BAY_HW, bx + BAY_HW) for py in (BAY_Y0, BAY_Y1)]\n\n\ndef racks(bx, r):\n    \"\"\"Lift racks on the posts' inner faces: the work decks ride them to the height a class needs.\"\"\"\n    out = []\n    for px, py in corners(bx):\n        sy = 1 if py == BAY_Y0 else -1\n        ys = sorted((py + r * sy, py + (r + .14) * sy))\n        out.append(box(px - .22, px + .22, ys[0], ys[1], .6, GANTRY_H - .4))\n    return out\n\n\ndef carriages(bx, r, zs):\n    \"\"\"The deck carriages, a collar round each post at each deck.\"\"\"\n    k = r + .22\n    return [box(px - k, px + k, py - k, py + k, z - .6, z + .5) for px, py in corners(bx) for z in zs]\n\n\ndef level(bx, z, back=2.4, side=1.6, out=.5, sides=True, wide=0.0):\n    \"\"\"One work level: a back deck behind the frame and a side deck along each post line, railed.\"\"\"\n    x0, x1, y0, y1 = bx - BAY_HW, bx + BAY_HW, BAY_Y0, BAY_Y1\n    decks = [box(x0 - wide, x1 + wide, y1 - back, y1, z, z + .4)]\n    rails = [box(x0, x1, y1 - back - .1, y1 - back + .1, z + 1.1, z + 1.25)]\n    if sides:\n        decks += [box(x0 - out, x0 + side, y0, y1, z, z + .4), box(x1 - side, x1 + out, y0, y1, z, z + .4)]\n        rails += [box(x0 + side - .1, x0 + side + .1, y0, y1, z + 1.1, z + 1.25),\n                  box(x1 - side - .1, x1 - side + .1, y0, y1, z + 1.1, z + 1.25)]\n    return decks, rails\n\n\ndef fit_std(root, b, bx):\n    g = empty(f\"gantry.{b}.std\", (bx, BAY_Y, 0), root, cls=\"standard\", platforms=list(DECKS[\"standard\"]))\n    decks, rails = [], []\n    for z in DECKS[\"standard\"]:\n        d, r = level(bx, z)\n        decks += d\n        rails += r\n    solid(f\"gantry_decks.{b}\", merge(*decks), \"hull_dark\", g, 0.05)\n    solid(f\"gantry_rails.{b}\", merge(*rails), \"hazard\", g)\n    solid(f\"gantry_lifts.{b}\", merge(*racks(bx, .5), *carriages(bx, .5, DECKS[\"standard\"])), \"metal\", g, 0.03)\n    empty(f\"bay.{b}.std\", (bx, BAY_Y, .2), root, cls=\"standard\", platforms=list(DECKS[\"standard\"]))\n\n\ndef fit_light(root, b, bx):\n    \"\"\"Two cradles side by side. A light frame's pilot boards the core block on its back, so each\n    cradle has a platform tongue at the block's underside, off a walkway along the back of the bay\n    with stairs down behind it. The striker decks park up under the gantry top.\"\"\"\n    g = empty(f\"gantry.{b}.light\", (bx, BAY_Y, 0), root, cls=\"light\", platforms=list(DECKS[\"light\"]))\n    x0, x1, y1 = bx - BAY_HW, bx + BAY_HW, BAY_Y1\n    z = DECKS[\"light\"][0]\n    decks, rails = level(bx, STOW)\n    walk = [box(x0 - .5, x1 + .5, y1 - 2.4, y1, z - .3, z)]\n    rails += [box(x0, bx - .9, y1 - .15, y1, z + 1.0, z + 1.15), box(bx + .9, x1, y1 - .15, y1, z + 1.0, z + 1.15)]\n    plates, metal, frame, hazard = [], [], [], []\n    for sx, tag in ((1, \"a\"), (-1, \"b\")):\n        cx = bx + LIGHT_DX * sx\n        # foot plate with heel stops\n        plates.append(box(cx - 1.8, cx + 1.8, 7.4, 12.6, .2, .5))\n        hazard.append(box(cx - 1.8, cx + 1.8, 7.3, 7.6, .2, .56))\n        metal += [box(cx + .6 * k - .35, cx + .6 * k + .35, BAY_Y + .75, BAY_Y + 1.15, .5, .85) for k in (1, -1)]\n        # back frame: two posts, a top bar and a back rest reaching under the core block\n        frame += [box(cx + 1.6 * k - .25, cx + 1.6 * k + .25, 12.9, 13.4, .5, 7.2) for k in (1, -1)]\n        frame += [box(cx - 1.85, cx + 1.85, 12.9, 13.4, 6.8, 7.3), box(cx - 1.85, cx + 1.85, 12.95, 13.35, 3.2, 3.7)]\n        metal += [box(cx - .2, cx + .2, 11.6, 12.95, 3.3, 3.6), box(cx - .7, cx + .7, 11.3, 11.6, 3.0, 3.9)]\n        # boarding tongue at the block, off the walkway\n        walk.append(box(cx - 1.1, cx + 1.1, 11.4, y1 - 2.4, z - .3, z))\n        hazard.append(box(cx - 1.1, cx + 1.1, 11.3, 11.5, z - .32, z + .02))\n        rails += [box(cx + 1.0 * k - .07, cx + 1.0 * k + .07, 11.6, y1 - 2.4, z + 1.0, z + 1.15) for k in (1, -1)]\n        frame += [box(cx + 1.0 * k - .06, cx + 1.0 * k + .06, 11.6 + .9 * i, 11.72 + .9 * i, z, z + 1.0) for k in (1, -1)\n                  for i in range(4)]\n        empty(f\"bay.{b}.light.{tag}\", (cx, BAY_Y, .5), root, cls=\"light\", platforms=[z], board=z)\n    # stairs down behind the walkway\n    steps = int(z / .4)\n    stairs = [box(bx - .8, bx + .8, y1 + i * .45, y1 + (i + 1) * .45, 0, z - (i + 1) * .4) for i in range(steps - 1)]\n    rails += [beam((bx + .8 * k, y1, z + 1.0), (bx + .8 * k, y1 + (steps - 1) * .45, 1.4), .1) for k in (1, -1)]\n    solid(f\"gantry_decks.{b}l\", merge(*decks, *walk, *stairs), \"hull_dark\", g, 0.05)\n    solid(f\"gantry_rails.{b}l\", merge(*rails), \"hazard\", g)\n    # carriages: the parked decks up top, and the walkway on the back posts\n    lifts = carriages(bx, .5, (STOW,)) + [c for c, (_, py) in zip(carriages(bx, .5, (z,)), corners(bx)) if py == y1]\n    solid(f\"gantry_lifts.{b}l\", merge(*racks(bx, .5), *lifts, *metal), \"metal\", g, 0.03)\n    solid(f\"cradle_frames.{b}\", merge(*frame), \"frame\", g, 0.04)\n    solid(f\"cradle_plates.{b}\", merge(*plates), \"deck\", g, 0.04)\n    solid(f\"cradle_hazard.{b}\", merge(*hazard), \"hazard\", g)\nimport * as THREE from 'three';\nimport { EffectComposer } from 'three/addons/postprocessing/EffectComposer.js';\nimport { GTAOPass } from 'three/addons/postprocessing/GTAOPass.js';\nimport { OutputPass } from 'three/addons/postprocessing/OutputPass.js';\nimport { Pass } from 'three/addons/postprocessing/Pass.js';\nimport { ShaderPass } from 'three/addons/postprocessing/ShaderPass.js';\nimport { UnrealBloomPass } from 'three/addons/postprocessing/UnrealBloomPass.js';\nimport { DetailShader, GradeShader, look, type Look } from './look';\n\n/** Meshes on this layer get surface detail (edge wear, grime, ink); glows, effects and sky stay off it. */\nexport const DETAIL_LAYER = 1;\n\n/**\n * Rendering tiers. high: everything. medium: no multisampling, a smaller shadow map. low, for weak\n * or software rendering: no multisampling, no shadows, no surface detail, bloom or grain, and at most\n * 0.6 resolution. Multisampling the half-float buffers is by far the dearest part on a weak GPU.\n */\nexport type Tier = 'high' | 'medium' | 'low';\nexport const TIERS: readonly Tier[] = ['high', 'medium', 'low'];\n\nexport interface Quality {\n  /** Render resolution relative to CSS pixels (1 ignores high-DPI scaling). */\n  scale: number;\n  ao: boolean;\n  shadows: boolean;\n  tier: Tier;\n}\n\nexport const DEFAULT_QUALITY: Quality = { scale: 1, ao: false, shadows: true, tier: 'high' };\n/** The low tier's resolution cap. */\nconst LOW_SCALE = 0.6;\n\n/** Clamp before the bloom: one infinite or NaN pixel would otherwise blur over the whole frame. */\nconst Sanitize = {\n  uniforms: { tDiffuse: { value: null } },\n  vertexShader: 'varying vec2 vUv; void main() { vUv = uv; gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0); }',\n  fragmentShader: `\n    uniform sampler2D tDiffuse; varying vec2 vUv;\n    void main() {\n      vec4 c = texture2D(tDiffuse, vUv);\n      if (any(isnan(c)) || any(isinf(c))) c = vec4(0.0, 0.0, 0.0, 1.0);\n      gl_FragColor = vec4(min(c.rgb, vec3(48.0)), c.a);\n    }`,\n};\n\n/**\n * Frame order: the backdrop at infinity (stars, nebula, planet), the world, ambient occlusion on the\n * world, then the cockpit in its own pass (it sits centimetres from the eye, the world runs to tens\n * of kilometres, so they don't share a depth range), then bloom and filmic tone mapping.\n */\nclass ScenePass extends Pass {\n  private bc = new THREE.PerspectiveCamera(60, 1, 1, 1e7);\n\n  constructor(\n    public scene: THREE.Scene,\n    public camera: THREE.PerspectiveCamera,\n    public backdrop: THREE.Scene | null,\n    private clearFirst: boolean,\n  ) {\n    super();\n    this.needsSwap = false;\n  }\n\n  render(renderer: THREE.WebGLRenderer, _write: THREE.WebGLRenderTarget, read: THREE.WebGLRenderTarget) {\n    renderer.setRenderTarget(read);\n    if (this.clearFirst) {\n      renderer.setClearColor(0x000000, 1);\n      renderer.clear();\n    } else renderer.clearDepth();\n    if (this.backdrop) {\n      const bc = this.bc;\n      bc.fov = this.camera.fov;\n      bc.aspect = this.camera.aspect;\n      bc.updateProjectionMatrix();\n      this.camera.getWorldQuaternion(bc.quaternion);\n      bc.updateMatrixWorld();\n      renderer.render(this.backdrop, bc);\n      renderer.clearDepth();\n    }\n    renderer.render(this.scene, this.camera);\n  }\n}\n\n/** Size the composer's buffers for `w` x `h` CSS pixels at the renderer's pixel ratio. The composer\n *  keeps its own copy of the ratio from construction, so a tier change has to hand it the new one. */\nexport function fitComposer(composer: Pick<EffectComposer, 'setPixelRatio' | 'setSize'>, w: number, h: number, pr: number) {\n  composer.setPixelRatio(pr);\n  composer.setSize(w, h);\n}\n\nexport class Pipeline {\n  readonly renderer: THREE.WebGLRenderer;\n  readonly composer: EffectComposer;\n  readonly bloom: UnrealBloomPass;\n  readonly ao: GTAOPass;\n  private detail: ShaderPass;\n  private grade: ShaderPass;\n  private sanitize: ShaderPass;\n  /** The look's own choice for the detail pass, before the tier. */\n  private detailWanted = true;\n  private sun: THREE.DirectionalLight | null = null;\n  private normals: THREE.WebGLRenderTarget;\n  private normalMat = new THREE.MeshNormalMaterial();\n  private world: ScenePass;\n  private overlay: ScenePass | null = null;\n\n  quality: Quality;\n\n  constructor(canvas: HTMLCanvasElement, world: THREE.Scene, camera: THREE.PerspectiveCamera, backdrop: THREE.Scene | null,\n    quality: Quality = DEFAULT_QUALITY) {\n    this.quality = { ...quality };\n    const renderer = new THREE.WebGLRenderer({ canvas, antialias: false, powerPreference: 'high-performance' });\n    renderer.setPixelRatio(this.quality.scale);\n    renderer.toneMapping = THREE.AgXToneMapping;\n    renderer.toneMappingExposure = 1.15;\n    renderer.shadowMap.enabled = true;\n    renderer.shadowMap.type = THREE.PCFShadowMap;\n    renderer.autoClear = false;\n    this.renderer = renderer;\n\n    const target = new THREE.WebGLRenderTarget(1, 1, { type: THREE.HalfFloatType, samples: 4 });\n    this.composer = new EffectComposer(renderer, target);\n    this.world = new ScenePass(world, camera, backdrop, true);\n    this.composer.addPass(this.world);\n    this.ao = new GTAOPass(world, camera, 1, 1);\n    this.ao.blendIntensity = 0.9;\n    this.ao.updateGtaoMaterial({ radius: 1.6, distanceExponent: 1.4, thickness: 2, scale: 1.2, samples: 8 });\n    this.composer.addPass(this.ao);\n    this.normals = new THREE.WebGLRenderTarget(1, 1, { type: THREE.HalfFloatType });\n    this.normals.depthTexture = new THREE.DepthTexture(1, 1, THREE.FloatType);\n    this.detail = new ShaderPass(DetailShader);\n    this.detail.uniforms.tNormal.value = this.normals.texture;\n    this.detail.uniforms.tDepth.value = this.normals.depthTexture;\n    this.composer.addPass(this.detail);\n    this.sanitize = new ShaderPass(Sanitize);\n    this.composer.addPass(this.sanitize);\n    this.bloom = new UnrealBloomPass(new THREE.Vector2(256, 256), 0.32, 0.22, 1.6);\n    this.composer.addPass(this.bloom);\n    this.composer.addPass(new OutputPass());\n    this.grade = new ShaderPass(GradeShader);\ncat: src/render/pilot.ts: No such file or directory\n"}