A mech game prototype, pushed by Gemini 4 Argon
agent (cont.)
+1:14read_file{"Path":"~/work/sortie/src/render/decals.ts"}
input
{ "Path": "~/work/sortie/src/render/decals.ts" }result, 139 lines
Showing lines 1-138 of 138 1: import * as THREE from 'three'; 2: import { DecalGeometry } from 'three/addons/geometries/DecalGeometry.js'; 3: 4: // Markings projected onto armour: unit numbers, designations, caution stencils, hazard bands and the 5: // company emblem. Each decal is found by casting a ray at the rest pose, projected onto the mesh it 6: // hits, and parented to that mesh so it moves with its joint. 7: 8: export type DecalKind = 'number' | 'stencil' | 'hazard' | 'emblem'; 9: 10: export interface DecalSpec { 11: kind: DecalKind; 12: text?: string; 13: /** A point just off the surface, model space (three.js axes: +X the frame's left, +Z forward). */ 14: at: [number, number, number]; 15: /** Direction into the surface. */ 16: dir: [number, number, number]; 17: /** Width and height in metres. */ 18: size: [number, number]; 19: /** Roll around the surface normal, degrees. */ 20: roll?: number; 21: color?: string; 22: } 23: 24: const textures = new Map<string, THREE.CanvasTexture>(); 25: 26: function texture(spec: DecalSpec): THREE.CanvasTexture { 27: const key = `${spec.kind}:${spec.text ?? ''}:${spec.color ?? ''}:${spec.size.join('x')}`; 28: const hit = textures.get(key); 29: if (hit) return hit; 30: const W = 512, H = Math.max(32, Math.round((512 * spec.size[1]) / spec.size[0])); 31: const c = document.createElement('canvas'); 32: c.width = W; 33: c.height = H; 34: const g = c.getContext('2d')!; 35: const ink = spec.color ?? '#20242a'; 36: g.fillStyle = ink; 37: g.strokeStyle = ink; 38: g.textAlign = 'center'; 39: g.textBaseline = 'middle'; 40: if (spec.kind === 'hazard') { 41: g.fillStyle = '#e2b42a'; 42: g.fillRect(0, 0, W, H); 43: g.fillStyle = '#15171a'; 44: for (let x = -H; x < W + H; x += H * 1.4) { 45: g.beginPath(); 46: g.moveTo(x, H); g.lineTo(x + H * 0.7, H); g.lineTo(x + H * 1.4, 0); g.lineTo(x + H * 0.7, 0); 47: g.fill(); 48: } 49: } else if (spec.kind === 'emblem') { 50: const r = Math.min(W, H) * 0.42; 51: g.lineWidth = r * 0.12; 52: g.beginPath(); 53: g.arc(W / 2, H / 2, r, 0, Math.PI * 2); 54: g.stroke(); 55: g.beginPath(); 56: g.moveTo(W / 2 - r * 0.55, H / 2 - r * 0.25); 57: g.lineTo(W / 2, H / 2 + r * 0.45); 58: g.lineTo(W / 2 + r * 0.55, H / 2 - r * 0.25); 59: g.lineTo(W / 2 + r * 0.3, H / 2 - r * 0.25); 60: g.lineTo(W / 2, H / 2 + r * 0.05); 61: g.lineTo(W / 2 - r * 0.3, H / 2 - r * 0.25); 62: g.closePath(); 63: g.fill(); 64: } else { 65: const size = spec.kind === 'number' ? H * 0.92 : H * 0.62; 66: g.font = `600 ${size}px "Chakra Petch", "Arial Narrow", sans-serif`; 67: g.fillText(spec.text ?? '', W / 2, H / 2 + size * 0.04, W * 0.96); 68: if (spec.kind === 'stencil') { 69: // stencil bridges: thin vertical breaks through the letters 70: g.globalCompositeOperation = 'destination-out'; 71: for (let x = W * 0.08; x < W; x += W / Math.max(4, (spec.text ?? '').length)) g.fillRect(x, 0, W * 0.006, H); 72: g.globalCompositeOperation = 'source-over'; 73: } 74: } 75: // wear: knock speckles out of the paint 76: g.globalCompositeOperation = 'destination-out'; 77: let s = key.length * 9973; 78: const rnd = () => ((s = (s * 16807) % 2147483647) / 2147483647); 79: for (let i = 0; i < (W * H) / 900; i++) { 80: g.globalAlpha = 0.3 + rnd() * 0.7; 81: g.fillRect(rnd() * W, rnd() * H, 1 + rnd() * 3, 1 + rnd() * 2); 82: } 83: g.globalAlpha = 1; 84: g.globalCompositeOperation = 'source-over'; 85: const t = new THREE.CanvasTexture(c); 86: t.colorSpace = THREE.SRGBColorSpace; 87: t.anisotropy = 8; 88: textures.set(key, t); 89: return t; 90: } 91: 92: const ray = new THREE.Raycaster(); 93: const helper = new THREE.Object3D(); 94: 95: export function applyDecals(root: THREE.Object3D, specs: DecalSpec[]) { 96: root.updateMatrixWorld(true); 97: const meshes: THREE.Mesh[] = []; 98: root.traverse((o) => { 99: const m = o as THREE.Mesh; 100: if (m.isMesh && !(m.material as THREE.MeshBasicMaterial).isMeshBasicMaterial && !m.userData.decal) meshes.push(m); 101: }); 102: for (const spec of specs) { 103: const dir = new THREE.Vector3(...spec.dir).normalize(); 104: const at = new THREE.Vector3(...spec.at).applyMatrix4(root.matrixWorld); 105: ray.set(at.clone().addScaledVector(dir, -3), dir.clone().transformDirection(root.matrixWorld)); 106: const hit = ray.intersectObjects(meshes, false)[0]; 107: if (!hit?.face) continue; 108: const mesh = hit.object as THREE.Mesh; 109: const normal = hit.face.normal.clone().transformDirection(mesh.matrixWorld); 110: helper.position.copy(hit.point); 111: helper.lookAt(hit.point.clone().add(normal)); 112: helper.rotateZ(THREE.MathUtils.degToRad(spec.roll ?? 0)); 113: const geo = new DecalGeometry(mesh, hit.point, helper.rotation, new THREE.Vector3(spec.size[0], spec.size[1], 0.6)); 114: geo.applyMatrix4(mesh.matrixWorld.clone().invert()); 115: const mat = new THREE.MeshStandardMaterial({ 116: map: texture(spec), transparent: true, depthWrite: false, polygonOffset: true, polygonOffsetFactor: -4, 117: roughness: 0.55, metalness: 0, 118: }); 119: const decal = new THREE.Mesh(geo, mat); 120: decal.userData.decal = true; 121: decal.receiveShadow = true; 122: mesh.add(decal); 123: } 124: } 125: 126: /** The striker's markings: unit number on the shoulders and leg, designation, stencils, hazard bands. */ 127: export const STRIKER_DECALS: DecalSpec[] = [ 128: { kind: 'number', text: '07', at: [4.8, 15.15, 0], dir: [-1, 0, 0], size: [0.95, 0.7], color: '#e9edf0' }, 129: { kind: 'emblem', at: [-4.8, 15.15, 0], dir: [1, 0, 0], size: [0.8, 0.8], color: '#e9edf0' }, 130: { kind: 'number', text: '07', at: [2.6, 3.6, 0.15], dir: [-1, 0, 0], size: [0.55, 0.42], color: '#e9edf0' }, 131: { kind: 'stencil', text: 'MF-07', at: [1.15, 9.25, 3], dir: [0, 0, -1], size: [0.7, 0.2] }, 132: { kind: 'stencil', text: 'NO STEP', at: [1.3, 10.05, 3], dir: [0, 0, -1], size: [0.6, 0.15], roll: -20 }, 133: { kind: 'stencil', text: 'NO STEP', at: [-1.3, 10.05, 3], dir: [0, 0, -1], size: [0.6, 0.15], roll: 20 }, 134: { kind: 'hazard', at: [1.2, 6.55, 3], dir: [0, 0, -1], size: [0.6, 0.12] }, 135: { kind: 'hazard', at: [-1.2, 6.55, 3], dir: [0, 0, -1], size: [0.6, 0.12] }, 136: { kind: 'stencil', text: 'DANGER EXHAUST', at: [0, 12.9, -4], dir: [0, 0, 1], size: [1.1, 0.16] }, 137: { kind: 'stencil', text: 'STRIKER', at: [-2.6, 3.4, 0.15], dir: [1, 0, 0], size: [0.9, 0.2], roll: 90, color: '#e9edf0' }, 138: ];read_file{"Path":"~/work/sortie/src/render/assets.ts"}
input
{ "Path": "~/work/sortie/src/render/assets.ts" }result, 229 lines
Showing lines 1-228 of 228 1: import * as THREE from 'three'; 2: import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js'; 3: import { mergeGeometries } from 'three/addons/utils/BufferGeometryUtils.js'; 4: import { MeshoptDecoder } from 'three/addons/libs/meshopt_decoder.module.js'; 5: import { PALETTES, type PaletteName } from './palette'; 6: import { DETAIL_LAYER } from './pipeline'; 7: import { BARE, isRole, material } from './materials'; 8: 9: const loader = new GLTFLoader(); 10: loader.setMeshoptDecoder(MeshoptDecoder); 11: const sources = new Map<string, Promise<THREE.Object3D>>(); 12: 13: /** Every model the kit builds (kit/build.py). */ 14: export type ModelName = 'alien_acicular' | 'alien_druse' | 'alien_druse_mimic' | 'alien_geode' 15: | 'striker' | 'striker_a' | 'striker_b' | 'light' | 'light_line' | 'light_lancer' | 'heavy' | 'heavy_B' | 'heavy_C' 16: | 'auto_tally' | 'auto_tick' | 'auto_ledger' | 'rifle' | 'cannon' | 'drone' | 'cockpit' | 'cockpit_light' | 'ship' | 'station' 17: | 'wreck_field' | 'salvage_pod' | 'escape_pod' | 'raider_grunt' | 'raider_brawler' | 'raider_boss'; 18: 19: /** 20: * Models ship as .glb. Artifact pages serve neither .glb nor fetches of data: URLs, so the artifact 21: * build wraps each model as base64 in JSON (VITE_MODEL_EXT=glb.json) and the page decodes it here. 22: * Those are squeezed (tools/squeeze.mjs): meshopt compressed, plus a quantized-only copy 23: * (.q.glb.json) for a page that can't run the WebAssembly decoder. 24: */ 25: const EXT: string = import.meta.env.VITE_MODEL_EXT ?? 'glb'; 26: const meshopt: Promise<boolean> = EXT === 'glb' ? Promise.resolve(true) : MeshoptDecoder.ready.then(() => true, () => false); 27: 28: async function fetchGlb(url: string): Promise<ArrayBuffer> { 29: const res = await fetch(url); 30: if (!res.ok) throw new Error(`${url}: ${res.status}`); 31: if (!url.endsWith('.json')) return res.arrayBuffer(); 32: const b64 = (await res.json()).glb as string; 33: const bin = atob(b64); 34: const out = new Uint8Array(bin.length); 35: for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i); 36: return out.buffer; 37: } 38: 39: /** Models loading now and loaded so far, for a loading indicator. */ 40: export const loading = { pending: 0, done: 0, listeners: new Set<() => void>() }; 41: function track<T>(p: Promise<T>): Promise<T> { 42: loading.pending++; 43: const tell = () => { 44: for (const f of loading.listeners) f(); 45: }; 46: tell(); 47: const end = () => { 48: loading.pending--; 49: loading.done++; 50: tell(); 51: }; 52: p.then(end, end); 53: return p; 54: } 55: 56: function source(name: ModelName, merge = true): Promise<THREE.Object3D> { 57: const key = merge ? name : `${name}:parts`; 58: let p = sources.get(key); 59: if (!p) { 60: const url = (ok: boolean) => `${import.meta.env.BASE_URL}assets/${name}.${ok ? EXT : `q.${EXT}`}`; 61: p = track(meshopt.then((ok) => fetchGlb(url(ok))).then((glb) => parseModel(glb, merge))); 62: sources.set(key, p); 63: } 64: return p; 65: } 66: 67: /** A model's scene from GLB bytes, plain or squeezed. `merge` false keeps every part its own mesh. */ 68: export async function parseModel(glb: ArrayBuffer, merge = true): Promise<THREE.Object3D> { 69: const root = unquantize((await loader.parseAsync(glb, '')).scene); 70: return merge ? mergeParts(root) : root; 71: } 72: 73: /** Start loading models now, side by side, so later awaits find them ready. */ 74: export function preload(names: Iterable<ModelName>) { 75: for (const n of names) source(n).catch((e) => console.error(e)); 76: } 77: 78: /** A fresh copy of a model, painted with a palette and tagged for ink lines. `merge` false keeps every 79: * part its own mesh, for models whose parts move apart (the aliens). */ 80: export async function model(name: ModelName, palette: PaletteName = 'merc', merge = true): Promise<THREE.Object3D> { 81: const root = (await source(name, merge)).clone(true); 82: paint(root, palette); 83: return root; 84: } 85: 86: export function paint(root: THREE.Object3D, palette: PaletteName) { 87: const pal = PALETTES[palette]; 88: // the plumes (render/mech.ts) take their colour from the same palette 89: root.userData.palette = palette; 90: root.traverse((o) => { 91: const mesh = o as THREE.Mesh; 92: if (!mesh.isMesh) return; 93: const src = mesh.userData.role ?? (mesh.material as THREE.Material).name; 94: mesh.userData.role = src; 95: if (isRole(src)) mesh.material = material(pal, src, palette); 96: const glows = (mesh.material as THREE.MeshBasicMaterial).isMeshBasicMaterial; 97: mesh.castShadow = !glows; 98: mesh.receiveShadow = !glows; 99: if (glows || BARE.has(src)) mesh.layers.disable(DETAIL_LAYER); 100: else mesh.layers.enable(DETAIL_LAYER); 101: }); 102: } 103: 104: /** Named nodes of a model, for joints and markers. */ 105: export function nodes(root: THREE.Object3D): Map<string, THREE.Object3D> { 106: const out = new Map<string, THREE.Object3D>(); 107: root.traverse((o) => { 108: if (o.name) out.set(o.name, o); 109: }); 110: return out; 111: } 112: 113: /** glTF node names lose dots (three.js sanitises them to underscores); look up either form. */ 114: export function find(map: Map<string, THREE.Object3D>, name: string): THREE.Object3D | undefined { 115: return map.get(name) ?? map.get(name.replace(/\./g, '_')) ?? map.get(name.replace(/\./g, '')); 116: } 117: 118: /** 119: * Rigid parts that share a joint and a material become one mesh: a frame is ~150 parts but only a 120: * few dozen joint/material pairs, and every mesh is a draw call (twice, with shadows). 121: */ 122: function mergeParts(root: THREE.Object3D): THREE.Object3D { 123: const groups = new Map<THREE.Object3D, Map<THREE.Material, THREE.Mesh[]>>(); 124: root.traverse((o) => { 125: const m = o as THREE.Mesh; 126: if (!m.isMesh || m.children.length || !m.parent || Array.isArray(m.material)) return; 127: let byMat = groups.get(m.parent); 128: if (!byMat) groups.set(m.parent, (byMat = new Map())); 129: const list = byMat.get(m.material) ?? []; 130: list.push(m); 131: byMat.set(m.material, list); 132: }); 133: for (const [parent, byMat] of groups) { 134: for (const [mat, meshes] of byMat) { 135: if (meshes.length < 2) continue; 136: const geoms = meshes.map((m) => { 137: m.updateMatrix(); 138: const g = m.geometry.clone(); 139: for (const k of Object.keys(g.attributes)) if (k !== 'position' && k !== 'normal') g.deleteAttribute(k); 140: return g.applyMatrix4(m.matrix); 141: }); 142: const merged = mergeGeometries(geoms, false); 143: if (!merged) continue; 144: const mesh = new THREE.Mesh(merged, mat); 145: mesh.name = `${parent.name}:${mat.name}`; 146: mesh.userData = { ...meshes[0].userData }; 147: for (const m of meshes) m.removeFromParent(); 148: parent.add(mesh); 149: } 150: } 151: return root; 152: } 153: 154: /** tools/squeeze.mjs puts each mesh on a child node of this name, holding its dequantizing transform. */ 155: const QUANT_NODE = 'q__'; 156: 157: /** A float copy of a (possibly quantized) vec3 attribute, as unit vectors if `unit`. */ 158: function toFloat(a: THREE.BufferAttribute | THREE.InterleavedBufferAttribute, unit = false) { 159: const out = new THREE.Float32BufferAttribute(a.count * 3, 3); 160: for (let i = 0; i < a.count; i++) { 161: _v.fromBufferAttribute(a, i); 162: if (unit) _v.normalize(); 163: out.setXYZ(i, _v.x, _v.y, _v.z); 164: } 165: return out; 166: } 167: const _v = new THREE.Vector3(); 168: 169: /** 170: * Fold squeezed meshes back into the nodes the kit built: bake each quantized mesh's transform into 171: * float vertices and put the mesh where its node was, with the node's name, transform, extras and 172: * children. A plain GLB passes through untouched. 173: */ 174: function unquantize(root: THREE.Object3D): THREE.Object3D { 175: const found: THREE.Object3D[] = []; 176: root.traverse((o) => { 177: if (o.name.startsWith(QUANT_NODE)) found.push(o); 178: }); 179: // a mesh used by several nodes shares its geometry: each gets its own before any is baked 180: const seen = new Set<THREE.BufferGeometry>(); 181: for (const q of found) { 182: q.traverse((o) => { 183: const m = o as THREE.Mesh; 184: if (!m.isMesh) return; 185: if (seen.has(m.geometry)) m.geometry = m.geometry.clone(); 186: seen.add(m.geometry); 187: }); 188: } 189: const bake = (m: THREE.Mesh, matrix: THREE.Matrix4) => { 190: const g = m.geometry; 191: g.setAttribute('position', toFloat(g.attributes.position).applyMatrix4(matrix)); 192: if (g.attributes.normal) g.setAttribute('normal', toFloat(g.attributes.normal, true)); 193: g.boundingBox = null; 194: g.computeBoundingSphere(); 195: }; 196: for (const q of found) { 197: const node = q.parent!; 198: q.updateMatrix(); 199: if (!(q as THREE.Mesh).isMesh) { 200: // a mesh of several primitives: its parts go straight under the node 201: for (const c of [...q.children] as THREE.Mesh[]) { 202: c.updateMatrix(); 203: bake(c, q.matrix.clone().multiply(c.matrix)); 204: c.position.set(0, 0, 0); 205: c.quaternion.identity(); 206: c.scale.set(1, 1, 1); 207: node.add(c); 208: } 209: q.removeFromParent(); 210: continue; 211: } 212: // the mesh takes its node's place 213: const mesh = q as THREE.Mesh; 214: bake(mesh, mesh.matrix); 215: mesh.name = node.name; 216: mesh.userData = { ...mesh.userData, ...node.userData }; 217: mesh.position.copy(node.position); 218: mesh.quaternion.copy(node.quaternion); 219: mesh.scale.copy(node.scale); 220: mesh.visible = node.visible; 221: for (const c of [...node.children]) if (c !== mesh) mesh.add(c); 222: const parent = node.parent!; 223: parent.children[parent.children.indexOf(node)] = mesh; 224: mesh.parent = parent; 225: node.parent = null; 226: } 227: return root; 228: }read_file{"Path":"~/work/sortie/src/render/mech.ts"}
input
{ "Path": "~/work/sortie/src/render/mech.ts" }result, 210 lines
Showing lines 1-209 of 209 1: import * as THREE from 'three'; 2: import { find, nodes } from './assets'; 3: import { Exhaust, KINDS, type NozzleKind, type ThrustReading } from './exhaust'; 4: import { PALETTES, type PaletteName } from './palette'; 5: import { PLUME_HULL, plumeMaterial, plumeVisible, setPlume } from './plume'; 6: 7: /** Joint rotations in degrees, glTF axes: X pitches a limb (negative swings it forward), Z swings it 8: * sideways (positive moves a left limb outward), Y twists. */ 9: export type Pose = Partial<Record<Joint, [number, number, number]>>; 10: 11: export const JOINTS = [ 12: 'pelvis', 'waist', 'torso', 'neck', 'head', 'backpack', 13: 'shoulder.L', 'upperarm.L', 'forearm.L', 'hand.L', 'shoulder.R', 'upperarm.R', 'forearm.R', 'hand.R', 14: 'thigh.L', 'shin.L', 'foot.L', 'thigh.R', 'shin.R', 'foot.R', 'binder.L', 'binder.R', 15: ] as const; 16: export type Joint = (typeof JOINTS)[number]; 17: 18: export const POSES = { 19: stand: { 20: 'upperarm.L': [0, 0, 6], 'upperarm.R': [0, 0, -6], 'forearm.L': [-12, 0, 0], 'forearm.R': [-12, 0, 0], 21: }, 22: /** Standing on the catapult: knees bent, leaning into the launch. */ 23: launch: { 24: pelvis: [8, 0, 0], torso: [10, 0, 0], head: [-14, 0, 0], 25: 'thigh.L': [-38, 0, 2], 'thigh.R': [-38, 0, -2], 'shin.L': [58, 0, 0], 'shin.R': [58, 0, 0], 26: 'foot.L': [-20, 0, 0], 'foot.R': [-20, 0, 0], 27: 'upperarm.L': [-18, 0, 14], 'forearm.L': [-40, 0, 0], 'upperarm.R': [-30, 0, -8], 'forearm.R': [-50, 0, 0], 28: 'binder.L': [18, 0, 0], 'binder.R': [18, 0, 0], 29: }, 30: /** The launch crouch for a heavy: 24 m in a 26 m tube, so knees deep, head down and binders folded, 31: * which brings it under the tube's signal box. */ 32: launch_heavy: { 33: pelvis: [12, 0, 0], torso: [12, 0, 0], head: [-20, 0, 0], 34: 'thigh.L': [-58, 0, 3], 'thigh.R': [-58, 0, -3], 'shin.L': [106, 0, 0], 'shin.R': [106, 0, 0], 35: 'foot.L': [-48, 0, 0], 'foot.R': [-48, 0, 0], 36: 'upperarm.L': [-18, 0, 14], 'forearm.L': [-40, 0, 0], 'upperarm.R': [-30, 0, -8], 'forearm.R': [-50, 0, 0], 37: 'binder.L': [40, 0, 0], 'binder.R': [40, 0, 0], 38: }, 39: /** Free flight, rifle up. */ 40: flight: { 41: pelvis: [6, 0, 0], torso: [-4, 0, 0], head: [-2, 0, 0], 42: 'thigh.L': [-22, 0, 4], 'thigh.R': [6, 0, -3], 'shin.L': [42, 0, 0], 'shin.R': [30, 0, 0], 43: 'foot.L': [8, 0, 0], 'foot.R': [18, 0, 0], 44: 'upperarm.L': [-22, 0, 16], 'forearm.L': [-46, 0, 0], 45: 'upperarm.R': [-62, -8, -6], 'forearm.R': [-26, 0, 0], 'hand.R': [0, 0, 0], 46: 'binder.L': [-6, 0, 0], 'binder.R': [-6, 0, 0], 47: }, 48: } satisfies Record<string, Pose>; 49: export type PoseName = keyof typeof POSES; 50: 51: /** The catapult pose for a size class: the striker's, with a deeper crouch for heavies. */ 52: export const launchPose = (cls: string): Pose => (cls === 'heavy' ? POSES.launch_heavy : POSES.launch); 53: 54: export interface Nozzle { 55: node: THREE.Object3D; 56: dir: THREE.Vector3; // exhaust direction in the node's parent space 57: radius: number; 58: kind: NozzleKind; 59: plume: THREE.Mesh; 60: } 61: 62: const tmpQ = new THREE.Quaternion(); 63: const _sum = new THREE.Vector3(); 64: const _at = new THREE.Vector3(); 65: const _white = new THREE.Color(1, 1, 1); 66: const tmpE = new THREE.Euler(); 67: const D = THREE.MathUtils.DEG2RAD; 68: 69: /** A frame model's joints, posed by rotation, with weapons held at grip.R and thruster plumes. */ 70: export class MechRig { 71: readonly joints = new Map<Joint, THREE.Object3D>(); 72: readonly nozzles: Nozzle[] = []; 73: readonly cockpit: THREE.Object3D; 74: readonly grip: THREE.Object3D; 75: held: THREE.Object3D | null = null; 76: /** Plume state, stepped by thrust(). */ 77: readonly exhaust = new Exhaust(); 78: /** One plume material per nozzle kind: a kind fires together. */ 79: private plumeMats: Record<NozzleKind, THREE.ShaderMaterial>; 80: private exhaustColor: THREE.Color; 81: private targets = new Map<Joint, THREE.Quaternion>(); 82: 83: constructor(readonly root: THREE.Object3D) { 84: const map = nodes(root); 85: for (const j of JOINTS) { 86: const n = find(map, j); 87: if (n) this.joints.set(j, n); 88: } 89: this.cockpit = find(map, 'cockpit') ?? root; 90: this.grip = find(map, 'grip.R') ?? root; 91: const paint = PALETTES[(root.userData.palette as PaletteName | undefined) ?? 'merc'].glow_exhaust; 92: this.exhaustColor = new THREE.Color(paint.color); 93: this.plumeMats = { 94: main: plumeMaterial(this.exhaustColor, paint.glow ?? 1, 0), 95: binder: plumeMaterial(this.exhaustColor, paint.glow ?? 1, 17.3), 96: calf: plumeMaterial(this.exhaustColor, paint.glow ?? 1, 41.7), 97: }; 98: root.traverse((o) => { 99: const dir = o.userData.dir as number[] | undefined; 100: if (!dir || !/^nozzle/.test(o.name)) return; 101: const kind: NozzleKind = /main/.test(o.name) ? 'main' : /binder/.test(o.name) ? 'binder' : 'calf'; 102: const radius = (o.userData.radius as number) ?? 0.5; 103: // the plume's own space is in nozzle radii (render/plume.ts) 104: const plume = new THREE.Mesh(PLUME_HULL, this.plumeMats[kind]); 105: const d = new THREE.Vector3(...(dir as [number, number, number])); 106: plume.quaternion.setFromUnitVectors(new THREE.Vector3(0, 0, 1), d); 107: plume.scale.setScalar(radius); 108: plume.visible = false; 109: plume.renderOrder = 2; 110: o.add(plume); 111: this.nozzles.push({ node: o, dir: d, radius, kind, plume }); 112: }); 113: } 114: 115: /** Any named node of the model (extras like harken.L), or null. */ 116: node(name: string): THREE.Object3D | null { 117: return find(nodes(this.root), name) ?? null; 118: } 119: 120: /** Snap to a pose. */ 121: apply(pose: Pose) { 122: for (const [j, node] of this.joints) { 123: const r = pose[j] ?? [0, 0, 0]; 124: node.quaternion.setFromEuler(tmpE.set(r[0] * D, r[1] * D, r[2] * D)); 125: } 126: } 127: 128: /** Snap to a pose and measure how high its soles sit above the root, in world metres (root 129: * upright). A crouch lifts the feet, so the frame drops by this much to stand on its clamps. */ 130: soles(pose: Pose): number { 131: this.apply(pose); 132: this.root.updateMatrixWorld(true); 133: const v = new THREE.Vector3(); 134: let min = Infinity; 135: for (const j of ['foot.L', 'foot.R'] as const) { 136: this.joints.get(j)?.traverse((o) => { 137: const p = (o as THREE.Mesh).isMesh ? (o as THREE.Mesh).geometry.attributes.position : null; 138: if (!p) return; 139: for (let i = 0; i < p.count; i++) min = Math.min(min, v.fromBufferAttribute(p, i).applyMatrix4(o.matrixWorld).y); 140: }); 141: } 142: return Number.isFinite(min) ? min - this.root.getWorldPosition(v).y : 0; 143: } 144: 145: /** Ease toward a blend of poses; weights need not sum to 1 (the rest is the rest pose). */ 146: blend(poses: [Pose, number][], rate: number, dt: number) { 147: const k = 1 - Math.exp(-rate * dt); 148: for (const [j, node] of this.joints) { 149: let x = 0, y = 0, z = 0; 150: for (const [p, w] of poses) { 151: const r = p[j]; 152: if (r) { 153: x += r[0] * w; 154: y += r[1] * w; 155: z += r[2] * w; 156: } 157: } 158: let t = this.targets.get(j); 159: if (!t) this.targets.set(j, (t = new THREE.Quaternion())); 160: t.setFromEuler(tmpE.set(x * D, y * D, z * D)); 161: node.quaternion.slerp(t, k); 162: } 163: } 164: 165: /** Turn one joint by an extra rotation on top of its current pose (aim, lean). */ 166: add(j: Joint, x: number, y: number, z: number) { 167: const n = this.joints.get(j); 168: if (n) n.quaternion.multiply(tmpQ.setFromEuler(tmpE.set(x * D, y * D, z * D))); 169: } 170: 171: /** Put a weapon in the right hand: barrel along the forearm, handle in the fist. */ 172: hold(weapon: THREE.Object3D | null) { 173: if (this.held && this.held !== weapon) this.held.removeFromParent(); 174: this.held = weapon; 175: if (!weapon) return; 176: this.grip.add(weapon); 177: weapon.position.set(0, 0, 0); 178: weapon.quaternion.setFromEuler(tmpE.set(Math.PI / 2, 0, 0)); 179: } 180: 181: /** Step the plumes from this frame's flight reading and draw them. `time` drives the turbulence. */ 182: thrust(r: ThrustReading, time: number, dt: number) { 183: this.exhaust.step(r, dt); 184: for (const k of KINDS) setPlume(this.plumeMats[k], this.exhaust.plumes[k], time); 185: for (const n of this.nozzles) n.plume.visible = plumeVisible(this.exhaust.plumes[n.kind]); 186: } 187: 188: /** Put `light` at the burning plumes' weighted centre, as bright as they burn: the glow the 189: * exhaust throws on the frame. A light costs every lit pixel, so a scene gives one to the player 190: * and the nearest few frames at most, and keeps the count fixed (a change recompiles shaders). */ 191: lightExhaust(light: THREE.PointLight, strength = 1) { 192: let w = 0; 193: _sum.set(0, 0, 0); 194: const s = this.root.scale.x; 195: for (const n of this.nozzles) { 196: const p = this.exhaust.plumes[n.kind]; 197: const k = (Math.min(1, p.level) * (1 + 0.5 * p.heavy) + 0.4 * p.flash) * (n.radius * s) ** 2; 198: if (k <= 0 || !n.plume.visible) continue; 199: // a little way downstream, where the plume is brightest 200: n.plume.localToWorld(_at.set(0, 0, 2.5)); 201: _sum.addScaledVector(_at, k); 202: w += k; 203: } 204: light.visible = true; 205: light.color.copy(this.exhaustColor).lerp(_white, 0.4); 206: light.intensity = w > 0 ? w * 35 * strength : 0; 207: if (w > 0) light.position.copy(_sum).divideScalar(w); 208: } 209: }
agent
+2:13reasoning
Inspecting the environment. Checking relevant directories and processes to understand the current state. Will assess the existence and performance of key rendering tools and model components to gain insight into resource availability and execution speed.
run_command{"CommandLine":"git status -sb && ls -la ~/out 2>/dev/null || true && ls -lh public/models/","WaitMsBeforeAsync":5000,"toolSummary":"Check git status and existing models"}error
input
{ "CommandLine": "git status -sb && ls -la ~/out 2>/dev/null || true && ls -lh public/models/", "WaitMsBeforeAsync": 5000, "toolSummary": "Check git status and existing models" }result, error, 8 lines
Command exited with code 2. Command output: ## argon total 8 drwx------ 2 runner runner 4096 Nov 15 01:36 . drwx------ 7 runner runner 4096 Nov 15 01:52 .. ls: cannot access 'public/models/': No such file or directory
agent
+2:22reasoning
The directory public/models/ is missing, confirming it's generated by the build process. Investigating the build script, it seems kit/build.py handles model creation. Need to assess the speed of building a model in Blender and rendering it with Playwright; the speed check will reveal if the current approach is viable.
run_command{"CommandLine":"ls -la && ~/.local/bin/blender --version && ffmpeg -version | head -n 2","WaitMsBeforeAsync":5000,"toolSummary":"Check directory contents, Blender, and ffmpeg"}
input
{ "CommandLine": "ls -la && ~/.local/bin/blender --version && ffmpeg -version | head -n 2", "WaitMsBeforeAsync": 5000, "toolSummary": "Check directory contents, Blender, and ffmpeg" }result, 37 lines
Command exited with code 0. Command output: total 144 drwx------ 9 runner runner 4096 Nov 15 01:36 . drwx------ 3 runner runner 4096 Nov 15 01:36 .. -rw------- 1 runner runner 49 Nov 15 01:36 .envrc drwx------ 7 runner runner 4096 Nov 15 01:55 .git -rw------- 1 runner runner 211 Nov 15 01:36 .gitignore -rw------- 1 runner runner 1161 Nov 15 01:36 CLAUDE.md -rw------- 1 runner runner 3937 Nov 15 01:36 README.md drwx------ 3 runner runner 4096 Nov 15 01:36 docs -rw------- 1 runner runner 321 Nov 15 01:36 index.html drwx------ 5 runner runner 4096 Nov 15 01:36 kit drwx------ 61 runner runner 4096 Oct 24 21:58 node_modules -rw------- 1 runner runner 77755 Nov 15 01:36 package-lock.json -rw------- 1 runner runner 965 Nov 15 01:36 package.json drwx------ 3 runner runner 4096 Nov 15 01:36 public drwx------ 8 runner runner 4096 Nov 15 01:36 src drwx------ 4 runner runner 4096 Nov 15 01:36 tools -rw------- 1 runner runner 400 Nov 15 01:36 tsconfig.json -rw------- 1 runner runner 296 Nov 15 01:36 vite.config.ts Blender 5.2.3 LTS build date: 2026-10-22 build time: 01:35:05 build commit date: 2026-10-21 build commit time: 09:21 build hash: e13b728c6880 build branch: blender-v5.2-release build platform: Linux build type: Release build c flags: -Wall -Werror=implicit-function-declaration -Wstrict-prototypes -Werror=return-type -Werror=vla -Wmissing-prototypes -Wno-char-subscripts -Wno-unknown-pragmas -Wpointer-arith -Wunused-parameter -Wwrite-strings -Wlogical-op -Wundef -Winit-self -Wmissing-include-dirs -Wno-div-by-zero -Wtype-limits -Wformat-signedness -Wrestrict -Wno-stringop-overread -Wno-stringop-overflow -Wnonnull -Wabsolute-value -Wuninitialized -Wredundant-decls -Wshadow -Wimplicit-fallthrough=5 -Wno-error=unused-but-set-variable -march=x86-64-v2 -std=gnu11 -pipe -fPIC -funsigned-char -fno-strict-aliasing -ffp-contract=off build c++ flags: -Wuninitialized -Wredundant-decls -Wall -Wno-invalid-offsetof -Wno-sign-compare -Wlogical-op -Winit-self -Wmissing-include-dirs -Wno-div-by-zero -Wtype-limits -Werror=return-type -Wno-char-subscripts -Wno-unknown-pragmas -Wpointer-arith -Wunused-parameter -Wwrite-strings -Wundef -Wcomma-subscript -Wformat-signedness -Wrestrict -Wno-suggest-override -Wuninitialized -Wno-stringop-overread -Wno-stringop-overflow -Wimplicit-fallthrough=5 -Wundef -Wmissing-declarations -march=x86-64-v2 -pipe -fPIC -funsigned-char -fno-strict-aliasing -ffp-contract=off build link flags: build system: CMake ffmpeg version 4.4.2-0ubuntu0.22.04.1 Copyright (c) 2000-2021 the FFmpeg developers built with gcc 11 (Ubuntu 11.2.0-19ubuntu1)
run_command{"CommandLine":"ls -la public/ && ls -la ~/context/reflect/","WaitMsBeforeAsync":5000,"toolSummary":"Check public and reflect directories"}
input
{ "CommandLine": "ls -la public/ && ls -la ~/context/reflect/", "WaitMsBeforeAsync": 5000, "toolSummary": "Check public and reflect directories" }result, 11 lines
Command exited with code 0. Command output: total 12 drwx------ 3 runner runner 4096 Nov 15 01:36 . drwx------ 9 runner runner 4096 Nov 15 01:36 .. drwx------ 2 runner runner 4096 Nov 15 01:36 assets total 204 drwx------ 2 runner runner 4096 Nov 15 01:36 . drwx------ 3 runner runner 4096 Nov 15 01:36 .. -rw------- 1 runner runner 198067 Nov 15 01:36 sortie.html
run_command{"CommandLine":"ls -la public/assets/","WaitMsBeforeAsync":5000,"toolSummary":"Check public/assets directory"}
input
{ "CommandLine": "ls -la public/assets/", "WaitMsBeforeAsync": 5000, "toolSummary": "Check public/assets directory" }result, 68 lines
Command exited with code 0. Command output: total 173240 drwx------ 2 runner runner 4096 Nov 15 01:36 . drwx------ 3 runner runner 4096 Nov 15 01:36 .. -rw------- 1 runner runner 97212 Nov 15 01:36 alien_acicular.glb -rw------- 1 runner runner 120312 Nov 15 01:36 alien_druse.glb -rw------- 1 runner runner 282936 Nov 15 01:36 alien_druse_mimic.glb -rw------- 1 runner runner 710368 Nov 15 01:36 alien_geode.glb -rw------- 1 runner runner 1484272 Nov 15 01:36 auto_ledger.glb -rw------- 1 runner runner 1179792 Nov 15 01:36 auto_tally.glb -rw------- 1 runner runner 852852 Nov 15 01:36 auto_tick.glb -rw------- 1 runner runner 25452 Nov 15 01:36 cannon.glb -rw------- 1 runner runner 245152 Nov 15 01:36 cockpit.glb -rw------- 1 runner runner 1438116 Nov 15 01:36 cockpit_light.glb -rw------- 1 runner runner 69016 Nov 15 01:36 drone.glb -rw------- 1 runner runner 55596 Nov 15 01:36 escape_pod.glb -rw------- 1 runner runner 1532780 Nov 15 01:36 heavy.glb -rw------- 1 runner runner 1596768 Nov 15 01:36 heavy_B.glb -rw------- 1 runner runner 1512944 Nov 15 01:36 heavy_C.glb -rw------- 1 runner runner 6729808 Nov 15 01:36 lab_alien.glb -rw------- 1 runner runner 6134544 Nov 15 01:36 lab_atelier.glb -rw------- 1 runner runner 14187700 Nov 15 01:36 lab_atelier_a.glb -rw------- 1 runner runner 10801072 Nov 15 01:36 lab_atelier_b.glb -rw------- 1 runner runner 11706000 Nov 15 01:36 lab_atelier_c.glb -rw------- 1 runner runner 11717484 Nov 15 01:36 lab_atelier_d.glb -rw------- 1 runner runner 6307036 Nov 15 01:36 lab_auto.glb -rw------- 1 runner runner 8216648 Nov 15 01:36 lab_backs.glb -rw------- 1 runner runner 283132 Nov 15 01:36 lab_chests.glb -rw------- 1 runner runner 277820 Nov 15 01:36 lab_chests2.glb -rw------- 1 runner runner 529028 Nov 15 01:36 lab_chests3.glb -rw------- 1 runner runner 6951676 Nov 15 01:36 lab_chests4.glb -rw------- 1 runner runner 155308 Nov 15 01:36 lab_feet.glb -rw------- 1 runner runner 148000 Nov 15 01:36 lab_feet2.glb -rw------- 1 runner runner 430680 Nov 15 01:36 lab_feet3.glb -rw------- 1 runner runner 6416784 Nov 15 01:36 lab_frames.glb -rw------- 1 runner runner 163260 Nov 15 01:36 lab_heads.glb -rw------- 1 runner runner 471472 Nov 15 01:36 lab_heads2.glb -rw------- 1 runner runner 1033232 Nov 15 01:36 lab_heads3.glb -rw------- 1 runner runner 714520 Nov 15 01:36 lab_heads4.glb -rw------- 1 runner runner 697628 Nov 15 01:36 lab_heads5.glb -rw------- 1 runner runner 900656 Nov 15 01:36 lab_heads6.glb -rw------- 1 runner runner 979832 Nov 15 01:36 lab_heads7.glb -rw------- 1 runner runner 1119580 Nov 15 01:36 lab_heads8.glb -rw------- 1 runner runner 5656964 Nov 15 01:36 lab_heavy.glb -rw------- 1 runner runner 6683852 Nov 15 01:36 lab_light.glb -rw------- 1 runner runner 6240172 Nov 15 01:36 lab_pattern.glb -rw------- 1 runner runner 2391752 Nov 15 01:36 lab_pilot.glb -rw------- 1 runner runner 8038888 Nov 15 01:36 lab_raider.glb -rw------- 1 runner runner 7861896 Nov 15 01:36 lab_show.glb -rw------- 1 runner runner 7868532 Nov 15 01:36 lab_show_v.glb -rw------- 1 runner runner 6919124 Nov 15 01:36 lab_sizes.glb -rw------- 1 runner runner 1592796 Nov 15 01:36 light.glb -rw------- 1 runner runner 1419452 Nov 15 01:36 light_lancer.glb -rw------- 1 runner runner 1477908 Nov 15 01:36 light_line.glb -rw------- 1 runner runner 1435856 Nov 15 01:36 pattern_m.glb -rw------- 1 runner runner 1671740 Nov 15 01:36 raider_boss.glb -rw------- 1 runner runner 1880608 Nov 15 01:36 raider_brawler.glb -rw------- 1 runner runner 1634808 Nov 15 01:36 raider_grunt.glb -rw------- 1 runner runner 45456 Nov 15 01:36 rifle.glb -rw------- 1 runner runner 106456 Nov 15 01:36 salvage_pod.glb -rw------- 1 runner runner 1303976 Nov 15 01:36 ship.glb -rw------- 1 runner runner 738340 Nov 15 01:36 station.glb -rw------- 1 runner runner 1008336 Nov 15 01:36 striker.glb -rw------- 1 runner runner 1325664 Nov 15 01:36 striker_a.glb -rw------- 1 runner runner 1210224 Nov 15 01:36 striker_b.glb -rw------- 1 runner runner 462204 Nov 15 01:36 wreck_field.glb