import type { BodyFrame } from './body.ts' import { lerp } from './curve.ts' import { circle, emitBeam, emitTube, roundedRect, type SinkSet, type Vec3 } from './mesh.ts' import type { LodLevel } from './spec.ts' /** * The interior HINT: enough that a window does not show an empty shell and an * open door shows somewhere to sit. Seats, a dash, a console, a floor, a * headliner and a steering wheel — no more. It is dark, it is behind tinted * glass, and it is cheap. */ export interface SteeringRig { /** Hub centre in vehicle space. */ readonly pivot: Vec3 /** Column tilt from vertical toward the driver, radians. */ readonly tilt: number } export function buildInterior(frame: BodyFrame, sinks: SinkSet, lod: LodLevel): SteeringRig | null { if (lod === 2) return null const sink = sinks.get('body|interior') const wheelSink = sinks.get('steering|interior') const front = Math.min(frame.cowlS - 0.12, frame.hood ? frame.hood.rearS - 0.2 : frame.cowlS - 0.12) const rear = Math.max(frame.roofRearS + 0.05, frame.deckS + 0.05) const mid = (front + rear) / 2 const floor = frame.sill(mid) + 0.1 const roof = frame.roofHeight const hasRoof = frame.cabin(mid) > 0.5 const halfW = frame.halfWidth(mid) * 0.8 const bevel = 0.04 // Floor pan and firewall: what you see past an open door instead of the road. emitBeam(sink, [0, floor, rear], [0, floor, front + 0.1], halfW * 2, 0.04, 0.01) const dashTop = Math.min(frame.belt(front) - 0.02, floor + 0.62) emitBeam(sink, [0, floor, front + 0.12], [0, dashTop, front + 0.18], halfW * 2, 0.08, 0.02) // Dash: a rounded slab under the windshield base. emitBeam(sink, [-halfW, dashTop - 0.1, front], [halfW, dashTop - 0.1, front], 0.34, 0.2, 0.06) if (hasRoof && lod === 0 && frame.roofFrontS - frame.roofRearS > 0.3) { // Headliner: only under the flat of the roof, or it pokes through the glass. const a = frame.roofRearS + 0.06 const b = frame.roofFrontS - 0.06 const y = Math.min(frame.top(a), frame.top(b)) - 0.05 emitBeam(sink, [0, y, a], [0, y, b], frame.topHalfWidth((a + b) / 2) * 1.7, 0.02, 0.01) } // Seats: cushion + backrest, front pair and a rear bench when there is room. // Seats shrink to fit a low roof instead of poking their headrests through it. const k = Math.min(1, Math.max(0.5, (Math.max(roof, frame.belt(mid) + 0.3) - floor - 0.08) / 1.02)) const seat = (x: number, s: number, width: number): void => { emitBeam(sink, [x, floor + 0.2 * k, s + 0.24], [x, floor + 0.2 * k, s - 0.18], width, 0.13, bevel) const back0: Vec3 = [x, floor + 0.24 * k, s - 0.2] const back1: Vec3 = [x, floor + 0.84 * k, s - 0.34] emitBeam(sink, back0, back1, width * 0.96, 0.12, bevel, { up: [0, 0, 1] }) if (lod === 0) emitBeam(sink, [x, floor + 0.86 * k, s - 0.35], [x, floor + 1.0 * k, s - 0.37], width * 0.5, 0.08, 0.03, { up: [0, 0, 1] }) } const driverS = lerp(front, rear, 0.18) - 0.55 const span = front - rear const seatX = halfW * 0.48 if (span > 0.7) { seat(seatX, Math.max(driverS, rear + 0.35), halfW * 0.72) seat(-seatX, Math.max(driverS, rear + 0.35), halfW * 0.72) } if (span > 1.7) { const benchS = Math.max(rear + 0.35, driverS - 0.95) seat(0, benchS, halfW * 1.7) } // Centre console between the front seats. if (span > 0.9) { emitBeam(sink, [0, floor + 0.12, Math.max(driverS, rear + 0.35) - 0.1], [0, floor + 0.12, front - 0.05], 0.18, 0.2, 0.03) } // Steering wheel: a rim swept round a circle, and two spokes. Left-hand // drive, because +X is the vehicle's left. const hub: Vec3 = [seatX, dashTop + 0.02, front - 0.28] const tilt = 0.42 const radius = 0.19 const ringPath: Vec3[] = [] const steps = lod === 0 ? 24 : 12 for (let k = 0; k <= steps; k += 1) { const a = (k / steps) * Math.PI * 2 ringPath.push(tilted(hub, tilt, Math.cos(a) * radius, Math.sin(a) * radius, 0)) } emitTube(wheelSink, circle(0.016, lod === 0 ? 8 : 5), ringPath, { caps: false, up: [0, 0, 1] }) for (const a of [0, Math.PI, Math.PI * 1.5]) { emitTube(wheelSink, roundedRect(0.045, 0.018, 0.006, 1), [ tilted(hub, tilt, 0, 0, 0), tilted(hub, tilt, Math.cos(a) * radius * 0.94, Math.sin(a) * radius * 0.94, 0), ], { up: [0, 0, 1] }) } // Column into the dash. emitTube(sink, circle(0.028, 6), [tilted(hub, tilt, 0, 0, -0.02), tilted(hub, tilt, 0, 0, -0.3)]) return { pivot: hub, tilt } } /** * A point in the steering wheel's own plane (u right, v up, w along the * column toward the driver), placed in vehicle space. */ function tilted(hub: Vec3, tilt: number, u: number, v: number, w: number): Vec3 { // The wheel plane is vertical, then leaned back by `tilt` about X. const c = Math.cos(tilt) const s = Math.sin(tilt) const y = v * c + w * s const z = -v * s + w * c return [hub[0] + u, hub[1] + y, hub[2] - z] }