Skip to content

armgit / kiln

Public Imported from GitHub
0

Build and revise procedural 3D assets with your coding agent. Local MCP server, CLI and TypeScript engine with rendered review, editable source and GLB export.

19.5 KB
Raw Blame
// The scene's truth is data (owner direction D-21): every placement, lane, light, camera, flight,
// preset, tier and behaviour parameter lives in data/*.json, in metres and seconds, and is staged
// beside data/scene.json so another engine can read the same files. Layout is loaded from the verified
// pack by layout.ts, with generated layout-bootstrap.json supplying only the checked startup contract.
// This module supplies its types and the other bundled configuration tables.
import presetsJson from '../data/presets.json';
import tiersJson from '../data/tiers.json';
import trafficJson from '../data/traffic.json';
import waterJson from '../data/water.json';
import drivingJson from '../data/driving.json';

export type Vec3 = [number, number, number];
type Notes = { notes?: string };

export interface LayoutLane {
  id: string; index: number; direction: 'north' | 'south'; x: number;
  /** Cruising speed (m/s). */
  speed: number;
  /** Vehicle types that may use the lane. */
  classes: string[];
  /** Lane ends on the approach roads (scene metres) and their route stations (see SceneApproaches); generated by scripts/layout.ts. */
  entry: Vec3; exit: Vec3; stations: [number, number];
  /** Lane centre on the bridge Roadway, deck end to deck end in the lane's direction (generated by scripts/layout.ts). */
  polyline: Vec3[];
}
export type ApproachName = 'south' | 'north';
export type StructureKind = 'viaduct' | 'overpass';
/** A stretch of an approach: a structure with its bents (supports) and abutment centres, or an at-grade stretch in cut, on fill or at the terrain's grade. */
export interface ApproachSegment { kind: StructureKind | 'cut' | 'fill' | 'grade'; from: number; to: number; supports?: number[]; abutments?: number[] }
/** Cross-section and structure dimensions shared by both approach roads (m). */
export interface ApproachCrossSection extends Notes {
  pavedHalfWidth: number;
  /** Concrete barrier: inner and outer |d| and height above the road. */
  barrier: [number, number, number];
  medianHeight: number;
  /** Lane lines as |d| ranges; dashes `dash` long every `period` metres of route station, starting at station `phase` (the deck's pattern); lines sit `lift` above the road. */
  markings: { broken: [number, number][]; edge: [number, number]; dash: number; period: number; phase: number; lift: number };
  /** At-grade pavement depth: the terrain bed lies this far below the road surface. */
  pavement: number;
  /** Structure deck: slab depth, girder depth below the road surface and girder half width. */
  deck: { slab: number; girder: number; girderHalfWidth: number };
  /** Least terrain clearance under a structure's girders. */
  clearance: number;
  /** Terrain corridor beyond the bed (bed = paved width plus bedMargin): cut rise and fill fall per metre, full-effect and zero-effect reach beyond the bed. */
  envelope: { bedMargin: number; cut: number; fill: number; reach: [number, number] };
  /** Bents: target spacing, column offsets |d|, column size, cap beam depth and length; abutment length along the road; the elevation columns and abutment walls run down to (below the ground everywhere along the approaches). */
  supports: { spacing: number; columns: number[]; column: number; cap: [number, number]; abutment: number; footing: number };
  /** At the deck end: the walkways between |d| walk[0] and walk[1] end ramp[0] above the road and a ramp takes them to the shoulder over ramp[1] metres; barriers and median taper to the road over `taper` metres before the dissolve. */
  joint: { walk: [number, number]; ramp: [number, number]; taper: number };
}
/**
 * A benched cut slope beside an approach where the terrain rises steeply from the road (fix round 3, the Marin
 * climb), shaped from our own terrain and imagery. `side` is +1 on the southbound lanes' side (as for lane offsets
 * x), -1 on the northbound's; the cut holds over stations `s`, faded in and out over `fade` m. From the bed a low
 * concrete retaining wall (|x| from toe.x[0] to toe.x[1], its top toe.height above the road, along toe.s) holds the
 * toe; beyond it slope faces rise `face` m per m with a bench bench[0] m wide after every bench[1] m of rise, up to
 * where they meet the natural terrain (which stands where it is lower). The cut takes the envelope's place on its
 * side and fades out between |x| reach[0] and reach[1]. Where it cuts the terrain, the surface takes a scrub colour
 * varying between `dark` and `light` (sRGB), the imagery's colours over `scrub.region` (stations s, offsets x):
 * the mean colours of its 10 to 35 % and 65 to 90 % luma bands.
 */
export interface ApproachCut extends Notes {
  side: 1 | -1; s: [number, number]; fade: number;
  toe: { x: [number, number]; height: number; s: [number, number] };
  face: number; bench: [number, number]; reach: [number, number];
  scrub: { dark: [number, number, number]; light: [number, number, number]; region: { s: [number, number]; x: [number, number] } };
}
export interface ApproachData extends Notes {
  /** Horizontal alignment from the bridge's road end: points of intersection with curve radii, and the end point of the last tangent. */
  alignment: { pis: [number, number][]; radii: number[]; end: [number, number] };
  /** Modelled length (station of the road's end, m from the bridge's road end); the traffic lanes run to it. */
  length: number;
  /** The structure profile leaves the deck end and meets the at-grade profile at `station`, through vertical curves of these lengths. */
  join: { station: number; curves: [number, number] };
  structures: { kind: StructureKind; from: number; to: number; note?: string }[];
  /** At-grade profile: PVIs every `spacing` metres fitted to the terrain along the centreline. */
  ground: { spacing: number };
  /** The player's car turns at station `car`; markings and barriers end and the surface fades into the terrain over `dissolve`. */
  ends: { car: number; dissolve: [number, number] };
  /** Benched cut slopes beside the road (fix round 3). */
  cuts?: ApproachCut[];
  /** Imagery road centre points (NAIP), the tolerance and the relief-displacement factor for elevated sections (m per m above ground, toward -X). */
  imagery: Notes & { tolerance: number; displacement: number; reference: [number, number][] };
  /** Derived by scripts/layout.ts: the deck end (elevation, grade away from the bridge), the full profile as PVIs [station, elevation, curve length], segments with supports, the centreline and the imagery deviation. */
  start: { elevation: number; grade: number };
  profile: [number, number, number][];
  segments: ApproachSegment[];
  centreline: Vec3[];
  /** Largest lateral distance of the imagery references from the centreline: at grade, and on structures after the relief-displacement correction (and before it). */
  deviation: { atGrade: number; elevated: number; elevatedRaw: number; references: number };
}
export interface SceneApproaches extends Notes { crossSection: ApproachCrossSection; south: ApproachData; north: ApproachData }
/** The toll plaza (fix round 3): stations s and lane offsets x (+ is the southbound lanes' side), heights above the road. */
export interface PlazaData extends Notes {
  approach: ApproachName;
  /** Lane side (+1 or -1) of the extra paved width. */
  side: 1 | -1;
  /** Stations where the paved edge starts to widen, reaches pavedTo, starts back and is back at the approach's width. */
  fan: [number, number, number, number];
  pavedTo: number;
  /** Stations between which the approach's median barrier is absent (the centre toll island takes over); it slopes down before and back up after. */
  medianGap: [number, number];
  canopy: { s: [number, number]; x: [number, number]; top: number; depth: number };
  columns: { size: number; s: number[] };
  islands: { s: [number, number]; nose: number; height: number; x: number[]; halfWidth: number[] };
  imagery: Notes & { roof: { s: [number, number]; x: [number, number] } };
}
/** A kerb polyline range for stall lines: outline or planter vertices `from` forward (wrapping) to `to`. */
export interface StallRow { edge: 'outline' | 'planter'; from: number; to: number }
/** Vista Point (fix round 3): a flat lot at `level`, outlines as [station, lane offset x] on its approach. */
export interface VistaData extends Notes {
  approach: ApproachName;
  level: number;
  outline: [number, number][];
  planter: [number, number][];
  throat: Notes & { edge: number };
  kerb: { height: number; width: number };
  wall: Notes & { from: number; to: number; height: number; width: number };
  stalls: Notes & { width: number; depth: number; line: number; rows: StallRow[] };
  cars: { row: number; stall: number; type: string; paint: string }[];
}
/** layout.json dressing (fix round 3): the approaches' plaza, Vista Point, cut, light standards and vegetation. */
/**
 * Highway light standards on both approaches (fix round 3 item 4): plain cobra-head standards on the edge barriers,
 * in pairs `spacing` m apart from station `start`. Each has a pole (foot and top diameter) from the barrier's top at
 * |x| `x` (out with a widening), an arm of square section `arm` reaching `reach` m inward to the centre of a cobra
 * head (length, width, depth at its back) whose lens is `mount` m above the road. None stands within `clear` m
 * (along the road) of a barrier opening on its side, of the plaza canopy or of where the barriers begin to taper
 * before the dissolve; the far representation carries those up to station `far`.
 */
export interface LightsData extends Notes {
  start: number; spacing: number; x: number; mount: number; reach: number;
  pole: [number, number]; arm: number; head: [number, number, number]; clear: number; far: number;
}
export type VegetationKindName = 'tree' | 'scrub';
/** One kind of vegetation impostor: grid spacing (m), card height and width ranges (m), and the share of its height it sinks below its root. */
export interface VegetationKind { spacing: number; height: [number, number]; width: [number, number]; sink: number }
/**
 * Vegetation impostors near the approaches (fix round 3 item 5): cross cards where our own terrain imagery shows
 * canopy within `reach` m of an approach's centreline, near representation only. Candidates lie on a world grid per
 * kind, jittered, kept at the feature level's density (FeatureData vegetation); none nearer the road than the edge
 * barrier's outer face (out with a widening) plus `clear` m plus its half width, short of the deck end by as much,
 * in Vista Point's lot outside its planted island, over a benched cut or on ground below `ground` m. The GPU keeps a
 * candidate where its canopy score exceeds its seed: the imagery's colour at its root over `footprint` m (sRGB 0 to
 * 255) through each class's ramps (from, to; smoothstep): trees by green over red and luma, scrub by green over blue,
 * luma and green over red where trees do not score. The card takes that colour. `approaches` names each approach's kinds.
 */
export interface VegetationData extends Notes {
  reach: number; clear: number; footprint: number; ground: number;
  kinds: Record<VegetationKindName, VegetationKind>;
  classes: {
    tree: { greenOverRed: [number, number]; luma: [number, number] };
    scrub: { greenOverBlue: [number, number]; luma: [number, number]; greenOverRed: [number, number] };
  };
  approaches: Record<ApproachName, VegetationKindName[]>;
}
export interface SceneDressing extends Notes {
  paint: Notes & { color: string; roughness: number };
  plaza: PlazaData;
  vista: VistaData;
  lights: LightsData;
  vegetation: VegetationData;
}
export interface CameraPose extends Notes { position: Vec3; target: Vec3; fov: number }
export interface FlightKey { position: Vec3; target: Vec3; fov: number; seconds?: number }
export type FlightEasing = 'ease-in-out' | 'smoothstep';
export interface FlightData extends Notes { name: string; label: string; seconds: number; requiresPreset?: string; easing?: FlightEasing; keys: FlightKey[] }
export interface Box2 { x0: number; x1: number; z0: number; z1: number }
export interface FogBankData { x: number; y: number; z: number; spread: [number, number]; puffs: number }
export interface Placement extends Notes { id: string; kind: string; [key: string]: unknown }

export interface SceneLayout {
  schema: 'golden-gate-layout/1';
  conventions: Record<string, string>;
  origin: { lon: number; lat: number; heightReference: string; source: string };
  files: Record<string, string>;
  bridge: Notes & {
    towerZ: number; towerTop: number; roadHalfWidth: number; roadEndZ: number; medianHalfWidth: number; medianTop: number;
    curbOuter: number; suspenderInner: number; railOuter: number;
    southFender: { x: number; z: number; rx: number; rz: number; top: number };
    pierFootings: Box2[]; anchorages: Box2[];
    jointPlates: Notes & { material: string; polygonOffset: { factor: number; units: number } };
    obstructionNodes: string[];
  };
  placements: Placement[];
  lanes: LayoutLane[];
  approaches: SceneApproaches;
  dressing: SceneDressing;
  cameras: {
    clip: { near: number; far: number };
    default: string;
    orbit: Notes & { minDistance: number; maxDistance: number; clearance: number; targetBounds: number; targetMinY: number; targetMaxY: number; maxPolarDeg: number };
    chase: Notes & { distance: number; height: number; targetHeight: number; lookAhead: number; fov: number; fovAtTopSpeed: number; positionLag: number; yawLag: number; castRadius: number; pad: number; minDistance: number; relax: number; maxAbsX: number; zoom: [number, number]; zoomRate: number };
    named: Record<string, CameraPose>;
    waterReview: string[];
  };
  flights: { clearance: { terrain: number; terrainMinimum: number; bridge: number }; interpolation: string; easing: string; timing: string; paths: FlightData[] };
  fogBanks: Notes & { seed: number; random: string; driftSpeed: number; wrap: { west: number; east: number }; puff: { sizeMin: number; sizeRange: number; heightJitter: number; heightPerSize: number; aspect: number }; banks: FogBankData[] };
  lights: {
    sun: { type: string; presetKeys: string[]; shadows: string };
    sky: { model: string; presetKeys: string[] };
    environment: { source: string; presetKeys: string[]; size: string };
    bridgeLamps: { materials: string[]; presetKey: string; rule: string };
    vehicleLamps: { materials: Record<string, 'head' | 'tail' | 'brake'>; presetKey: string; gain: Record<'head' | 'tail' | 'brake', [number, number]>; brakeOff: number; taillightPeak: number; rule: string };
  };
  referenceColours: Record<string, string>;
}

export interface PresetData {
  label: string;
  sunAzimuthDeg: number; sunElevationDeg: number; sunColor: Vec3; sunIntensity: number;
  envIntensity: number; envSaturation: number;
  turbidity: number; rayleigh: number; mie: number; mieG: number; sunDisc: number;
  overcast: number; overcastColor: Vec3;
  fogColor: Vec3; fogSun: Vec3; fogPower: number;
  hazeDensity: number; hazeHeight: number; marineDensity: number; marineHeight: number;
  exposure: number; skyGain: number; wind: number; banks: number; lights: number; lamps: number;
}
export interface ScenePresets { schema: 'golden-gate-presets/1'; conventions: Record<string, string>; order: string[]; default: string; presets: Record<string, PresetData> }

export type FeatureLevel = 'high' | 'medium' | 'low';
export type TrafficDensity = 'low' | 'medium' | 'high';
export interface FeatureData {
  terrainSet: FeatureLevel;
  water: {
    displaceRadius: number; displacedWaves: number; fragmentWaves: number; detailLayers: 2 | 3;
    reflection: 'planar' | 'environment'; reflectionScale: number;
    grid: 2 | 4 | 8; tile0: number; levels: number; anisotropy: number; depthContact: boolean;
    /** Low only: view-distance range (m) over which the per-pixel waves fade into roughness. */
    waveFade?: [number, number];
  };
  fogBanks: number;
  traffic: { density: TrafficDensity; perLaneMax: number; lod: [number, number, number]; contactShadow: number };
  bridgeFarSwitch: number;
  /** Vegetation impostors (layout.json dressing.vegetation): the share of candidates kept and the camera distances (m) over which they shrink away. */
  vegetation: { density: number; fade: [number, number] };
  envSize: number;
  shadows: { enabled: boolean; filter: 'pcf'; mapSize: number; cascades: number };
  shadowExtent: [number, number];
}
export interface TierData { features: FeatureLevel; pixelRatioCap: number; pixelRatioMin: number; phone?: { features: FeatureLevel } }
export interface SceneTiers {
  schema: 'golden-gate-tiers/1'; conventions: Record<string, string>;
  features: Record<FeatureLevel, FeatureData>;
  tiers: { order: ['minimal', 'economy', 'balanced', 'high']; minimal: TierData; economy: TierData; balanced: TierData; high: TierData };
}

export interface PaletteData { name: string; weight: number; srgb: [number, number, number] }
export interface SceneTraffic {
  schema: 'golden-gate-traffic/1'; conventions: Record<string, string>;
  seed: number; random: string; stepsPerSecond: number;
  vehicles: Record<string, { model: string; weight: number }>;
  palette: PaletteData[];
  paint: { material: string; untinted: string[]; brightnessJitter: number; avoidRadius: number; attempts: number };
  densityHeadway: Record<TrafficDensity, number>;
  minHeadway: number; fade: number;
  speed: { personal: number; oscillation: number; oscillationPeriod: [number, number] };
  idm: { accel: number; brake: number; headway: number; gap: number; emergency: number };
  brakeLights: { decel: number; rate: number };
}

export interface WaveData { wavelength: number; amplitude: number; direction: number; steepness: number }
export interface DetailLayerData { tile: number; rotation: number; slope: number; drift: number }
export interface SceneWater {
  schema: 'golden-gate-water/1'; conventions: Record<string, string>;
  waves: WaveData[]; detailLayers: DetailLayerData[]; macroTiles: [number, number];
  flow: { size: number; peakSpeed: number; gateWidth: number; flowPeriod: number };
  shoreBandPeriod: number; originSnap: number;
}

// JSON imports widen tuples and literals, so the files are typed by assertion here and checked field by field in tests/unit/data.test.ts.
export interface SceneDriving {
  schema: 'golden-gate-driving/1'; conventions: Record<string, string>;
  vehicle: string; paint: string;
  start: { lane: string; z: number; window: [number, number]; speed: number };
  topSpeed: number; accel: number;
  boost: { topSpeed: number; accel: number };
  reverse: { accel: number; maxSpeed: number; afterStopSeconds: number };
  brake: number; handbrake: number;
  coast: { constant: number; quadratic: number };
  steer: { headingDeg: [number, number]; rateDegPerSecond: number; fullRateSpeed: number; wheelDeg: [number, number] };
  curb: { clearance: number; speedKept: number; cooldown: number; bumpDeg: number };
  traffic: { minGap: number; followGain: number; lateralMargin: number; longitudinalMargin: number };
  roadEnd: { promptDistance: number; stopDistance: number; fadeSeconds: number; holdSeconds: number };
  controls: Record<'throttle' | 'reverse' | 'left' | 'right' | 'brake' | 'handbrake' | 'boost' | 'turnAround' | 'enterOrLeave' | 'leave', string[]>;
}

export const PRESET_DATA = presetsJson as unknown as ScenePresets;
export const TIER_DATA = tiersJson as unknown as SceneTiers;
export const TRAFFIC_DATA = trafficJson as unknown as SceneTraffic;
export const WATER_DATA = waterJson as unknown as SceneWater;
export const DRIVING_DATA = drivingJson as unknown as SceneDriving;

/** The data files staged beside data/scene.json, by pack path. */
export const DATA_FILES = { layout: 'data/layout.json', presets: 'data/presets.json', tiers: 'data/tiers.json', traffic: 'data/traffic.json', water: 'data/water.json', driving: 'data/driving.json' } as const;