A mech game prototype, pushed by Gemini 4 Argon
agent
+37:37reasoning
The line mesh.add(decal) suggests decals are being directly added to the mesh. The call to applyDecals indicates decal application occurs in a rest pose, parenting the decal directly to the hit mesh. This approach might not account for subsequent mesh transformations or animations, potentially misplacing the decals.
The placement of emblems appears to be linked to the posed limbs, suggesting the decals will move with them. Examining the decal function, it iterates through visible objects with names starting with "bearing," calculating world-to-local positions to generate decal specifications. The raycasting offset in the original code, however, might cause decal misses due to the initial position calculation.
The raycast direction seems correct for the shield, pointing inward from outside. The code will be edited to include the 'guard' pose, add new frames, and apply bearing decals before posing for bearings or estoc mechs. Sole grounding will be implemented when the 'guard' or 'stand' poses are applied, adjusting for their different sole positions.
The rig.soles(p) function seems to ground the mech's feet on the y=0 plane. Adding support for ?pilot=1 loads a pilot model, positioning it at a specific offset and rotation. Support for ?wingman=1 loads a mech, applies bearing decals, positions and rotates it for flight, poses it, triggers thruster effects, and adds a point light for exhaust glow.
The rendering will be triggered on demand after a specific condition is met, unless a 'play' query is present, with control changes also triggering render.
Now editing mech render.
edit_file{"Path":"~/work/sortie/src/render/mech.ts","Replacement":" stand: {\n 'upperarm.L': [0, 0, 6], 'upperarm.R': [0, 0, -6], 'forearm.L': [-12, 0, 0], 'forearm.R': [-12, 0, 0],\n },\n /** Heroic asymmetric knight guard: planted wide stance, shield presented forward-left, Estoc lance poised. */\n guard: {\n pelvis: [3, -10, 0], waist: [0, 6, 0], torso: [-4, 14, 0], neck: [2, -6, 0], head: [-5, -14, 0],\n 'thigh.L': [-14, 6, 7], 'shin.L': [20, 0, 0], 'foot.L': [-6, 4, -5],\n 'thigh.R': [8, -8, -7], 'shin.R': [10, 0, 0], 'foot.R': [-16, -6, 5],\n 'shoulder.L': [0, 0, 6], 'upperarm.L': [-22, 18, 16], 'forearm.L': [-34, 8, 0], 'hand.L': [0, 0, 0],\n 'shoulder.R': [0, 0, -6], 'upperarm.R': [-18, -10, -14], 'forearm.R': [-46, 0, 0], 'hand.R': [-10, 0, 0],\n 'binder.L': [-10, -8, 6], 'binder.R': [-10, 8, -6],\n },","Target":" stand: {\n 'upperarm.L': [0, 0, 6], 'upperarm.R': [0, 0, -6], 'forearm.L': [-12, 0, 0], 'forearm.R': [-12, 0, 0],\n },"}
input
{ "Path": "~/work/sortie/src/render/mech.ts", "Replacement": " stand: {\n 'upperarm.L': [0, 0, 6], 'upperarm.R': [0, 0, -6], 'forearm.L': [-12, 0, 0], 'forearm.R': [-12, 0, 0],\n },\n /** Heroic asymmetric knight guard: planted wide stance, shield presented forward-left, Estoc lance poised. */\n guard: {\n pelvis: [3, -10, 0], waist: [0, 6, 0], torso: [-4, 14, 0], neck: [2, -6, 0], head: [-5, -14, 0],\n 'thigh.L': [-14, 6, 7], 'shin.L': [20, 0, 0], 'foot.L': [-6, 4, -5],\n 'thigh.R': [8, -8, -7], 'shin.R': [10, 0, 0], 'foot.R': [-16, -6, 5],\n 'shoulder.L': [0, 0, 6], 'upperarm.L': [-22, 18, 16], 'forearm.L': [-34, 8, 0], 'hand.L': [0, 0, 0],\n 'shoulder.R': [0, 0, -6], 'upperarm.R': [-18, -10, -14], 'forearm.R': [-46, 0, 0], 'hand.R': [-10, 0, 0],\n 'binder.L': [-10, -8, 6], 'binder.R': [-10, 8, -6],\n },", "Target": " stand: {\n 'upperarm.L': [0, 0, 6], 'upperarm.R': [0, 0, -6], 'forearm.L': [-12, 0, 0], 'forearm.R': [-12, 0, 0],\n }," }result, 1 line
Made 1 replacement in ~/work/sortie/src/render/mech.ts starting at line 19 (+9/-0 lines).
edit_file{"Path":"~/work/sortie/src/view/viewer.ts","Replacement":"const FRAMES: string[] = ['striker_a', 'striker_b', 'light', 'light_line', 'light_lancer', 'heavy', 'heavy_B', 'heavy_C', 'pattern_m', 'estoc'];","Target":"const FRAMES: string[] = ['striker_a', 'striker_b', 'light', 'light_line', 'light_lancer', 'heavy', 'heavy_B', 'heavy_C'];"}
input
{ "Path": "~/work/sortie/src/view/viewer.ts", "Replacement": "const FRAMES: string[] = ['striker_a', 'striker_b', 'light', 'light_line', 'light_lancer', 'heavy', 'heavy_B', 'heavy_C', 'pattern_m', 'estoc'];", "Target": "const FRAMES: string[] = ['striker_a', 'striker_b', 'light', 'light_line', 'light_lancer', 'heavy', 'heavy_B', 'heavy_C'];" }result, 1 line
Made 1 replacement in ~/work/sortie/src/view/viewer.ts starting at line 23 (+1/-1 lines).
edit_file{"Path":"~/work/sortie/src/view/viewer.ts","Replacement":" async function frame(palette: PaletteName, x: number, mech: ModelName = 'striker') {\n const root = await model(mech, palette);\n root.position.x = x;\n scene.add(root);\n if (mech === 'striker') applyDecals(root, STRIKER_DECALS);\n if (q.has('bearings') || mech === 'estoc') applyDecals(root, bearingDecals(root, PALETTES[palette].trim.color));\n treatEyes(root, (q.get('eye') ?? 'spill') as EyeMode);\n const rig = new MechRig(root);\n const p = POSES[pose] ?? POSES.stand;\n if (pose !== 'flight') root.position.y = -rig.soles(p);\n else rig.apply(p);\n if (weapon) {\n rig.hold(await model(weapon, palette));\n // weapons are striker sized: scale to the frame's height\n const h = root.getObjectByName('frame')?.userData.height as number | undefined;\n if (h) rig.held!.scale.setScalar(h / 17.6);\n }\n if (q.has('pilot')) {\n const pModel = await model('pilot', palette);\n pModel.position.set(x - 2.35, 0, 1.85);\n pModel.rotation.y = 0.28;\n scene.add(pModel);\n }\n if (q.has('wingman')) {\n const wRoot = await model(mech, palette);\n scene.add(wRoot);\n if (q.has('bearings') || mech === 'estoc') applyDecals(wRoot, bearingDecals(wRoot, PALETTES[palette].trim.color));\n treatEyes(wRoot, (q.get('eye') ?? 'spill') as EyeMode);\n const wRig = new MechRig(wRoot);\n wRig.apply(POSES.flight);\n wRoot.position.set(x + 9.2, 4.2, -10.5);\n wRoot.rotation.set(0.24, Math.PI * 0.82, -0.14);\n for (let i = 0; i < 12; i++) wRig.thrust({ thrust: 1, brake: false, boost: true, heavy: 1 }, 0.6, 0.05);\n wRoot.updateMatrixWorld(true);\n const exLight = new THREE.PointLight(0xffffff, 0, 22, 1.5);\n scene.add(exLight);\n wRig.lightExhaust(exLight, 1.2);\n }\n return root;\n }","Target":" async function frame(palette: PaletteName, x: number, mech: ModelName = 'striker') {\n const root = await model(mech, palette);\n root.position.x = x;\n scene.add(root);\n if (mech === 'striker') applyDecals(root, STRIKER_DECALS);\n treatEyes(root, (q.get('eye') ?? 'spill') as EyeMode);\n const rig = new MechRig(root);\n rig.apply(POSES[pose] ?? POSES.stand);\n if (weapon) {\n rig.hold(await model(weapon, palette));\n // weapons are striker sized: scale to the frame's height\n const h = root.getObjectByName('frame')?.userData.height as number | undefined;\n if (h) rig.held!.scale.setScalar(h / 17.6);\n }\n return root;\n }"}
input
{ "Path": "~/work/sortie/src/view/viewer.ts", "Replacement": " async function frame(palette: PaletteName, x: number, mech: ModelName = 'striker') {\n const root = await model(mech, palette);\n root.position.x = x;\n scene.add(root);\n if (mech === 'striker') applyDecals(root, STRIKER_DECALS);\n if (q.has('bearings') || mech === 'estoc') applyDecals(root, bearingDecals(root, PALETTES[palette].trim.color));\n treatEyes(root, (q.get('eye') ?? 'spill') as EyeMode);\n const rig = new MechRig(root);\n const p = POSES[pose] ?? POSES.stand;\n if (pose !== 'flight') root.position.y = -rig.soles(p);\n else rig.apply(p);\n if (weapon) {\n rig.hold(await model(weapon, palette));\n // weapons are striker sized: scale to the frame's height\n const h = root.getObjectByName('frame')?.userData.height as number | undefined;\n if (h) rig.held!.scale.setScalar(h / 17.6);\n }\n if (q.has('pilot')) {\n const pModel = await model('pilot', palette);\n pModel.position.set(x - 2.35, 0, 1.85);\n pModel.rotation.y = 0.28;\n scene.add(pModel);\n }\n if (q.has('wingman')) {\n const wRoot = await model(mech, palette);\n scene.add(wRoot);\n if (q.has('bearings') || mech === 'estoc') applyDecals(wRoot, bearingDecals(wRoot, PALETTES[palette].trim.color));\n treatEyes(wRoot, (q.get('eye') ?? 'spill') as EyeMode);\n const wRig = new MechRig(wRoot);\n wRig.apply(POSES.flight);\n wRoot.position.set(x + 9.2, 4.2, -10.5);\n wRoot.rotation.set(0.24, Math.PI * 0.82, -0.14);\n for (let i = 0; i < 12; i++) wRig.thrust({ thrust: 1, brake: false, boost: true, heavy: 1 }, 0.6, 0.05);\n wRoot.updateMatrixWorld(true);\n const exLight = new THREE.PointLight(0xffffff, 0, 22, 1.5);\n scene.add(exLight);\n wRig.lightExhaust(exLight, 1.2);\n }\n return root;\n }", "Target": " async function frame(palette: PaletteName, x: number, mech: ModelName = 'striker') {\n const root = await model(mech, palette);\n root.position.x = x;\n scene.add(root);\n if (mech === 'striker') applyDecals(root, STRIKER_DECALS);\n treatEyes(root, (q.get('eye') ?? 'spill') as EyeMode);\n const rig = new MechRig(root);\n rig.apply(POSES[pose] ?? POSES.stand);\n if (weapon) {\n rig.hold(await model(weapon, palette));\n // weapons are striker sized: scale to the frame's height\n const h = root.getObjectByName('frame')?.userData.height as number | undefined;\n if (h) rig.held!.scale.setScalar(h / 17.6);\n }\n return root;\n }" }result, 1 line
Made 1 replacement in ~/work/sortie/src/view/viewer.ts starting at line 61 (+25/-1 lines).
edit_file{"Path":"~/work/sortie/src/view/viewer.ts","Replacement":" const controls = new OrbitControls(camera, canvas);\n controls.target.copy(target);\n controls.update();\n controls.addEventListener('change', () => pipe.render());\n window.addEventListener('resize', () => {\n pipe.resize();\n pipe.render();\n });\n const play = q.has('play');\n const loop = () => {\n pipe.render();\n if (play) requestAnimationFrame(loop);\n };\n loop();\n (window as unknown as { __ready: boolean }).__ready = true;","Target":" const controls = new OrbitControls(camera, canvas);\n controls.target.copy(target);\n controls.update();\n window.addEventListener('resize', () => pipe.resize());\n const loop = () => {\n pipe.render();\n requestAnimationFrame(loop);\n };\n loop();\n (window as unknown as { __ready: boolean }).__ready = true;"}
input
{ "Path": "~/work/sortie/src/view/viewer.ts", "Replacement": " const controls = new OrbitControls(camera, canvas);\n controls.target.copy(target);\n controls.update();\n controls.addEventListener('change', () => pipe.render());\n window.addEventListener('resize', () => {\n pipe.resize();\n pipe.render();\n });\n const play = q.has('play');\n const loop = () => {\n pipe.render();\n if (play) requestAnimationFrame(loop);\n };\n loop();\n (window as unknown as { __ready: boolean }).__ready = true;", "Target": " const controls = new OrbitControls(camera, canvas);\n controls.target.copy(target);\n controls.update();\n window.addEventListener('resize', () => pipe.resize());\n const loop = () => {\n pipe.render();\n requestAnimationFrame(loop);\n };\n loop();\n (window as unknown as { __ready: boolean }).__ready = true;" }result, 1 line
Made 1 replacement in ~/work/sortie/src/view/viewer.ts starting at line 157 (+7/-2 lines).
agent
+38:17reasoning
The fix in src/view/viewer.ts potentially eliminates the need for a timeout in tools/shoot.mjs, as rendering is now triggered only once at startup unless specific conditions are met. This suggests tools/shoot.mjs might now function correctly without the timeout. Proceeding to verify this hypothesis.
read_file{"EndLine":60,"Path":"~/work/sortie/tools/shoot.mjs","StartLine":1}
input
{ "EndLine": 60, "Path": "~/work/sortie/tools/shoot.mjs", "StartLine": 1 }result, 49 lines
Showing lines 1-48 of 48 1: // Screenshots of the running dev server for review. 2: // node tools/shoot.mjs out/dir name=/?view=striker name2=/?view=ship ... 3: // Waits for window.__ready, then a few frames. Needs `npm run dev` on :5199. 4: // SORTIE_GPU=1 uses the GPU (see below). 5: import { chromium } from 'playwright'; 6: import { mkdirSync } from 'node:fs'; 7: import { join } from 'node:path'; 8: 9: const [out, ...shots] = process.argv.slice(2); 10: const base = process.env.SORTIE_URL ?? 'http://localhost:5199'; 11: const W = Number(process.env.W ?? 1280), H = Number(process.env.H ?? 720); 12: mkdirSync(out, { recursive: true }); 13: // SORTIE_GPU=1 renders on the GPU through a headed window on the WSLg display. WSLg ignores the 14: // off-screen position, so the window shows on that machine's Windows desktop: on the workstation only 15: // when nobody minds, on C1 (tools/c1-render.sh with C1_GPU=1) it shows on C1's own display. 16: // Headless Chromium only gets SwiftShader, which is slow and loads the CPU. 17: const gpu = process.env.SORTIE_GPU === '1'; 18: const browser = await chromium.launch(gpu 19: ? { headless: false, args: ['--use-angle=gl', '--ignore-gpu-blocklist', '--window-position=-4000,0'], 20: env: { ...process.env, DISPLAY: ':0', WAYLAND_DISPLAY: 'wayland-0', XDG_RUNTIME_DIR: '/mnt/wslg/runtime-dir', 21: // Mesa may fall back to llvmpipe unless told to use its D3D12 driver (C1's Radeon needs this) 22: GALLIUM_DRIVER: 'd3d12', LD_LIBRARY_PATH: '/usr/lib/wsl/lib' } } 23: : { args: ['--use-angle=swiftshader', '--enable-unsafe-swiftshader', '--ignore-gpu-blocklist'] }); 24: const page = await browser.newPage({ viewport: { width: W, height: H } }); 25: // SHOOT_TIMEOUT (ms) for page loads and screenshots: software rendering under load needs more than the default 26: page.setDefaultTimeout(Number(process.env.SHOOT_TIMEOUT ?? 30000)); 27: let failed = 0; 28: page.on('console', (m) => { if (m.type() === 'error' || m.type() === 'warning') console.log(`[${m.type()}]`, m.text().slice(0, 300)); }); 29: page.on('pageerror', (e) => console.log('[pageerror]', e.message)); 30: for (const s of shots) { 31: const i = s.indexOf('='); 32: const name = s.slice(0, i), url = s.slice(i + 1); 33: const t = Date.now(); 34: // one slow or broken shot is reported and skipped, the rest of the batch still runs 35: try { 36: await page.goto(base + url); 37: await page.waitForFunction(() => window.__ready === true, null, { timeout: 300000 }); 38: const frames = Number(new URL(base + url).searchParams.get('frames') ?? 1); 39: await page.evaluate((n) => new Promise((r) => { let k = 0; const f = () => (++k >= n ? r() : requestAnimationFrame(f)); requestAnimationFrame(f); }), frames); 40: await page.screenshot({ path: join(out, `${name}.png`) }); 41: console.log(`${name}: ${Date.now() - t} ms`); 42: } catch (e) { 43: failed++; 44: console.log(`${name}: FAILED ${e.message.split('\n')[0]}`); 45: } 46: } 47: await browser.close(); 48: process.exitCode = failed ? 1 : 0;
agent
+38:25reasoning
The timeout in tools/shoot.mjs stemmed from startViewer, an asynchronous function that initiated an infinite animation loop. This loop, coupled with the previous rendering context, caused each frame to take approximately 800ms, effectively blocking the page.screenshot() call within the automated testing environment. The core issue appears to be related to the synchronous blocking caused by the infinite rendering loop.
run_command{"CommandLine":"mkdir -p ~/out && npx vite --port 5199 --strictPort >/tmp/vite.log 2>&1 &\nVPID=$!\nfor i in $(seq 1 30); do curl -s http://localhost:5199 >/dev/null && break; sleep 0.2; done\nW=1920 H=1080 node tools/shoot.mjs ~/out 'estoc-sortie=/?view=estoc&pose=guard&palette=houses&look=kit&bearings=1&pilot=1&wingman=1&yaw=-16&pitch=5&dist=24&tx=1.6&ty=9.0'\nkill $VPID 2>/dev/null || true","WaitMsBeforeAsync":10000,"toolSummary":"Render estoc-sortie.png via tools/shoot.mjs"}
input
{ "CommandLine": "mkdir -p ~/out && npx vite --port 5199 --strictPort >/tmp/vite.log 2>&1 &\nVPID=$!\nfor i in $(seq 1 30); do curl -s http://localhost:5199 >/dev/null && break; sleep 0.2; done\nW=1920 H=1080 node tools/shoot.mjs ~/out 'estoc-sortie=/?view=estoc&pose=guard&palette=houses&look=kit&bearings=1&pilot=1&wingman=1&yaw=-16&pitch=5&dist=24&tx=1.6&ty=9.0'\nkill $VPID 2>/dev/null || true", "WaitMsBeforeAsync": 10000, "toolSummary": "Render estoc-sortie.png via tools/shoot.mjs" }result, 4 lines
Command exited with code 0. Command output: estoc-sortie: 5634 ms
read_file{"Path":"~/out/estoc-sortie.png"}
input
{ "Path": "~/out/estoc-sortie.png" }result, 1 line
Showing binary file of type image/png
agent
+38:50reasoning
The new image clearly depicts a crisper, more detailed Estoc knight. Observed improvements include the rendering of the breastplate, lower breast section, and V-plate with gold piping. These elements show increased clarity and sculptural definition compared to the previous images.
The new image features remarkably sharp specular highlights on the central keel ridge of the armor, with precisely rendered leaf pauldrons and clean groin armor. The sabatons are sleek and tapered. Investigating the camera target in the viewing code, the target was set to the center of the root object after the frame generation which, combined with the camera rotation, resulted in poor framing.
The wingman's forward facing orientation and the bright highlights indicate an issue with the camera target and world root rotation. The rotation values suggest the wingman should be facing away from the camera, yet the image shows otherwise. Examination of the asset merging process may reveal why the expected rotations are not being applied to the meshes.
read_file{"EndLine":228,"Path":"~/work/sortie/src/render/assets.ts","StartLine":140}
input
{ "EndLine": 228, "Path": "~/work/sortie/src/render/assets.ts", "StartLine": 140 }result, 90 lines
Showing lines 140-228 of 229 140: for (const k of Object.keys(g.attributes)) if (k !== 'position' && k !== 'normal') g.deleteAttribute(k); 141: return g.applyMatrix4(m.matrix); 142: }); 143: const merged = mergeGeometries(geoms, false); 144: if (!merged) continue; 145: const mesh = new THREE.Mesh(merged, mat); 146: mesh.name = `${parent.name}:${mat.name}`; 147: mesh.userData = { ...meshes[0].userData }; 148: for (const m of meshes) m.removeFromParent(); 149: parent.add(mesh); 150: } 151: } 152: return root; 153: } 154: 155: /** tools/squeeze.mjs puts each mesh on a child node of this name, holding its dequantizing transform. */ 156: const QUANT_NODE = 'q__'; 157: 158: /** A float copy of a (possibly quantized) vec3 attribute, as unit vectors if `unit`. */ 159: function toFloat(a: THREE.BufferAttribute | THREE.InterleavedBufferAttribute, unit = false) { 160: const out = new THREE.Float32BufferAttribute(a.count * 3, 3); 161: for (let i = 0; i < a.count; i++) { 162: _v.fromBufferAttribute(a, i); 163: if (unit) _v.normalize(); 164: out.setXYZ(i, _v.x, _v.y, _v.z); 165: } 166: return out; 167: } 168: const _v = new THREE.Vector3(); 169: 170: /** 171: * Fold squeezed meshes back into the nodes the kit built: bake each quantized mesh's transform into 172: * float vertices and put the mesh where its node was, with the node's name, transform, extras and 173: * children. A plain GLB passes through untouched. 174: */ 175: function unquantize(root: THREE.Object3D): THREE.Object3D { 176: const found: THREE.Object3D[] = []; 177: root.traverse((o) => { 178: if (o.name.startsWith(QUANT_NODE)) found.push(o); 179: }); 180: // a mesh used by several nodes shares its geometry: each gets its own before any is baked 181: const seen = new Set<THREE.BufferGeometry>(); 182: for (const q of found) { 183: q.traverse((o) => { 184: const m = o as THREE.Mesh; 185: if (!m.isMesh) return; 186: if (seen.has(m.geometry)) m.geometry = m.geometry.clone(); 187: seen.add(m.geometry); 188: }); 189: } 190: const bake = (m: THREE.Mesh, matrix: THREE.Matrix4) => { 191: const g = m.geometry; 192: g.setAttribute('position', toFloat(g.attributes.position).applyMatrix4(matrix)); 193: if (g.attributes.normal) g.setAttribute('normal', toFloat(g.attributes.normal, true)); 194: g.boundingBox = null; 195: g.computeBoundingSphere(); 196: }; 197: for (const q of found) { 198: const node = q.parent!; 199: q.updateMatrix(); 200: if (!(q as THREE.Mesh).isMesh) { 201: // a mesh of several primitives: its parts go straight under the node 202: for (const c of [...q.children] as THREE.Mesh[]) { 203: c.updateMatrix(); 204: bake(c, q.matrix.clone().multiply(c.matrix)); 205: c.position.set(0, 0, 0); 206: c.quaternion.identity(); 207: c.scale.set(1, 1, 1); 208: node.add(c); 209: } 210: q.removeFromParent(); 211: continue; 212: } 213: // the mesh takes its node's place 214: const mesh = q as THREE.Mesh; 215: bake(mesh, mesh.matrix); 216: mesh.name = node.name; 217: mesh.userData = { ...mesh.userData, ...node.userData }; 218: mesh.position.copy(node.position); 219: mesh.quaternion.copy(node.quaternion); 220: mesh.scale.copy(node.scale); 221: mesh.visible = node.visible; 222: for (const c of [...node.children]) if (c !== mesh) mesh.add(c); 223: const parent = node.parent!; 224: parent.children[parent.children.indexOf(node)] = mesh; 225: mesh.parent = parent; 226: node.parent = null; 227: } 228: return root;
agent
+39:08reasoning
Initial hypothesis: rotation of wRoot is missing in one image. However, the root cause is likely the initial orientation in the pose data. Reviewing the pose data reveals that wRoot is excluded from the applied joints in the problematic frame.
read_file{"EndLine":90,"Path":"~/work/sortie/src/view/thrusters.ts","StartLine":1}
input
{ "EndLine": 90, "Path": "~/work/sortie/src/view/thrusters.ts", "StartLine": 1 }result, 91 lines
Showing lines 1-90 of 166 1: import * as THREE from 'three'; 2: import { model, type ModelName } from '../render/assets'; 3: import { MechRig, POSES } from '../render/mech'; 4: import type { PaletteName } from '../render/palette'; 5: import { Pipeline } from '../render/pipeline'; 6: import { addSpaceLight, createBackdrop, followSun, spaceEnvironment } from '../render/space'; 7: import { STRIKER_DECALS, applyDecals } from '../render/decals'; 8: import { treatEyes } from '../render/eyes'; 9: import type { ThrustReading } from '../render/exhaust'; 10: 11: /** 12: * Thruster bench: one frame in a fixed thruster state at a fixed time, for judging plumes as stills. 13: * /?view=thrusters&state=quick&t=0.06 a quick boost 60 ms after onset 14: * /?view=thrusters&state=boost&close=main close on one main nozzle 15: * /?view=thrusters&state=cycle&play=1 every state in turn, live 16: * /?view=thrusters&cells=quick:0,quick:0.05,boost:0.5:main&cols=4&cw=480&ch=300 a sheet of stills 17: * &frame=heavy_C &palette=raider &yaw=150 &pitch=12 &dist=40 &light=0 &tier=low 18: * States: idle, cruise, boost, quick, assault, brake, strafe. `t` is seconds since the state began. 19: */ 20: export const BENCH_STATES = ['idle', 'cruise', 'boost', 'quick', 'assault', 'brake', 'strafe'] as const; 21: export type BenchState = (typeof BENCH_STATES)[number]; 22: 23: /** A scripted flight reading for a bench state `t` seconds in: local thrust (left, up, forward as a 24: * fraction of boosted forward thrust) and the boost flags, as the sim would report them. */ 25: export function benchInput(state: BenchState, t: number) { 26: const thrust = new THREE.Vector3(); 27: let boosting = false, assault = false, quick = Infinity; 28: if (state === 'cruise') thrust.set(0, 0, 0.35); 29: else if (state === 'boost') (thrust.set(0, 0, 1), (boosting = true)); 30: else if (state === 'quick') (thrust.set(0, 0, 0.05), (quick = t)); 31: else if (state === 'assault') (thrust.set(0, 0, 1), (boosting = true), (assault = true)); 32: else if (state === 'brake') thrust.set(0, 0.15, -0.6); 33: else if (state === 'strafe') thrust.set(0.55, 0, 0.1); 34: return { thrust, boosting, assault, quick }; 35: } 36: 37: export async function startThrusterBench(canvas: HTMLCanvasElement, q: URLSearchParams) { 38: await document.fonts.ready; 39: const scene = new THREE.Scene(); 40: const camera = new THREE.PerspectiveCamera(Number(q.get('fov') ?? 35), 1, 0.3, 2e5); 41: const backdrop = createBackdrop(); 42: const pipe = new Pipeline(canvas, scene, camera, backdrop); 43: // ?tier=low: the software and weak GPU tier, no bloom 44: const tier = q.get('tier'); 45: if (tier === 'low' || tier === 'medium') pipe.setQuality({ tier }); 46: const sun = addSpaceLight(scene); 47: scene.environment = spaceEnvironment(pipe.renderer, backdrop); 48: scene.environmentIntensity = Number(q.get('env') ?? 0.8); 49: 50: const name = (q.get('frame') ?? 'striker') as ModelName; 51: const root = await model(name, (q.get('palette') ?? 'merc') as PaletteName); 52: if (name === 'striker') applyDecals(root, STRIKER_DECALS); 53: treatEyes(root, 'spill'); 54: scene.add(root); 55: const rig = new MechRig(root); 56: rig.apply(POSES.flight); 57: root.updateMatrixWorld(true); 58: 59: const box = new THREE.Box3().setFromObject(root); 60: const height = box.getSize(new THREE.Vector3()).y; 61: const target = new THREE.Vector3(); 62: /** Aim the camera at the frame, or close on its first nozzle of a kind. */ 63: const aim = (close: string | null, yawAt?: string, pitchAt?: string) => { 64: box.getCenter(target); 65: const nozzle = close ? rig.nozzles.find((n) => n.kind === close) : undefined; 66: if (nozzle) nozzle.node.getWorldPosition(target); 67: const dist = Number(q.get('dist') ?? (nozzle ? height * 0.6 : height * 2.6)); 68: const yaw = THREE.MathUtils.degToRad(Number(yawAt || q.get('yaw') || (nozzle ? 125 : 132))); 69: const pitch = THREE.MathUtils.degToRad(Number(pitchAt || q.get('pitch') || 10)); 70: if (q.has('ty')) target.y += Number(q.get('ty')); 71: if (q.has('tz')) target.z += Number(q.get('tz')); 72: camera.position.set(Math.sin(yaw) * Math.cos(pitch), Math.sin(pitch), Math.cos(yaw) * Math.cos(pitch)).multiplyScalar(dist).add(target); 73: camera.lookAt(target); 74: followSun(sun, target); 75: }; 76: 77: const light = new THREE.PointLight('#ffffff', 0, 0, 2); 78: scene.add(light); 79: const lit = q.get('light') !== '0'; 80: const reading: ThrustReading = { x: 0, y: 0, z: 0, boosting: false }; 81: const DT = 1 / 120; 82: const feed = (state: BenchState, t: number, dt: number) => { 83: const f = benchInput(state, t); 84: reading.x = f.thrust.x; 85: reading.y = f.thrust.y; 86: reading.z = f.thrust.z; 87: reading.boosting = f.boosting; 88: reading.assault = f.assault; 89: reading.quick = f.quick; 90: rig.thrust(reading, t, dt);
