{
  "name": "coffee-gear",
  "title": "CoffeeGear",
  "type": "registry:component",
  "description": "What a cafe makes coffee with and shows off: an espresso machine, grinder, pour-over bar, siphon, cold drip tower, batch brewer, taps, a drum roaster, and beans in bags, jars and stocked shelves, one `kind` to a node. Only the roaster has a collider.",
  "dependencies": [
    "@react-three/rapier@^2.2.0",
    "@runek/core@^0.18.0",
    "three@^0.184.0"
  ],
  "registryDependencies": [],
  "files": [
    {
      "path": "CoffeeGear.tsx",
      "content": "import { CuboidCollider, RigidBody } from '@react-three/rapier'\nimport { rng, useMaterials, useWorld, type Vec3 } from '@runek/core'\nimport { useMemo } from 'react'\nimport { BoxGeometry, type BufferGeometry, CylinderGeometry, SphereGeometry } from 'three'\nimport { glowMaterial, mid, useLadder } from './city/glow'\n\n/** What a cafe keeps on its counters, by name. */\nexport type CoffeeGearKind =\n  /** A lever-less espresso machine: `length` sets how many groups (0.3 units each). */\n  | 'espresso'\n  | 'grinder'\n  /** A pour-over bar: a row of cone drippers over servers, one every 0.22 units of `length`. */\n  | 'pourover'\n  /** An hourglass brewer with a wooden collar. */\n  | 'chemex'\n  /** A French press. */\n  | 'press'\n  /** A stovetop moka pot. */\n  | 'moka'\n  /** A vacuum siphon over a burner. */\n  | 'siphon'\n  /** A cold drip tower. */\n  | 'coldbrew'\n  /** A gooseneck kettle. */\n  | 'kettle'\n  /** A batch brewer with a server under its basket. */\n  | 'batch'\n  /** A tray of hot sand with two long-handled pots in it. */\n  | 'ibrik'\n  /** A tap tower for cold brew and nitro. */\n  | 'taps'\n  /** Milk pitchers in a row along `length`. */\n  | 'pitchers'\n  /** Jars of beans in a row along `length`, from dark roast to light. */\n  | 'jars'\n  /** Bags of beans in a row along `length`. */\n  | 'bags'\n  /** Stacks of cups in a row along `length`. */\n  | 'cups'\n  /** Wall shelves `length` long, `rows` of them, stocked with bags and jars. */\n  | 'shelf'\n  /** A drum roaster that stands on the floor. The one kind with a collider. */\n  | 'roaster'\n\nexport interface CoffeeGearProps {\n  /** The middle of its foot: on the counter it stands on. A shelf's is the middle of its lowest board. */\n  position?: Vec3\n  /** The working side is the kind's own +Z. */\n  rotation?: Vec3\n  /** Picks the bag colors and how high each stack of cups is. */\n  seed?: number\n  /** Which piece of gear it is. */\n  kind?: CoffeeGearKind\n  /** How long a row is, or how wide an espresso machine, in units. */\n  length?: number\n  /** How many boards a shelf has. */\n  rows?: number\n  /** The color of its pilot lights and flames, lit at the world's `screen` luminance level. */\n  glow?: string\n}\n\ntype Paint =\n  | 'steel'\n  | 'dark'\n  | 'black'\n  | 'coffee'\n  | 'roast'\n  | 'blonde'\n  | 'wood'\n  | 'cream'\n  | 'glass'\n  | 'copper'\n  | 'sand'\n  | 'bagA'\n  | 'bagB'\n  | 'bagC'\n  | 'bagD'\n  | 'glow'\ninterface Part {\n  g: BufferGeometry\n  m: Paint\n  p: Vec3\n  r?: Vec3\n}\n\n// Geometry is shared by every piece of the same size, across every piece of gear.\nconst cache = new Map<string, BufferGeometry>()\nfunction shape<T extends BufferGeometry>(key: string, make: () => T): T {\n  let g = cache.get(key) as T | undefined\n  if (!g) {\n    g = make()\n    cache.set(key, g)\n  }\n  return g\n}\nconst n = (v: number) => v.toFixed(4)\n\nconst BAGS: Paint[] = ['bagA', 'bagB', 'bagC', 'bagD', 'black', 'cream']\nconst ROASTS: Paint[] = ['coffee', 'roast', 'blonde']\n\n/** The parts of one piece of gear, in units scaled by `u`, with its foot at the origin. */\nfunction build(\n  kind: CoffeeGearKind,\n  length: number,\n  rows: number,\n  seed: number,\n  u: number,\n): Part[] {\n  const out: Part[] = []\n  const box = (w: number, h: number, d: number) =>\n    shape(`b:${n(w * u)}:${n(h * u)}:${n(d * u)}`, () => new BoxGeometry(w * u, h * u, d * u))\n  const cyl = (top: number, bottom: number, h: number, seg = 14) =>\n    shape(\n      `c:${n(top * u)}:${n(bottom * u)}:${n(h * u)}:${seg}`,\n      () => new CylinderGeometry(top * u, bottom * u, h * u, seg),\n    )\n  const ball = (r: number) => shape(`s:${n(r * u)}`, () => new SphereGeometry(r * u, 14, 10))\n  /** Add a part at (x, y, z) units, shifted by the offset in force. */\n  let ox = 0\n  let oy = 0\n  const add = (g: BufferGeometry, m: Paint, x: number, y: number, z: number, r?: Vec3) =>\n    out.push({ g, m, p: [(x + ox) * u, (y + oy) * u, z * u], r })\n  const random = rng(seed)\n\n  const jars = (len: number) => {\n    const count = Math.max(1, Math.floor(len / 0.16))\n    for (let i = 0; i < count; i++) {\n      const x = (i - (count - 1) / 2) * 0.16\n      add(cyl(0.055, 0.055, 0.16), ROASTS[i % ROASTS.length], x, 0.08, 0)\n      add(cyl(0.058, 0.058, 0.02), 'steel', x, 0.17, 0)\n      add(box(0.06, 0.04, 0.004), 'cream', x, 0.09, 0.055)\n    }\n  }\n  const bags = (len: number) => {\n    const count = Math.max(1, Math.floor(len / 0.17))\n    for (let i = 0; i < count; i++) {\n      const x = (i - (count - 1) / 2) * 0.17\n      const paint = BAGS[Math.floor(random() * BAGS.length)]\n      add(box(0.12, 0.2, 0.07), paint, x, 0.1, 0)\n      add(box(0.12, 0.03, 0.02), paint, x, 0.215, 0)\n      add(box(0.08, 0.07, 0.004), paint === 'cream' ? 'black' : 'cream', x, 0.1, 0.037)\n    }\n  }\n\n  switch (kind) {\n    case 'espresso': {\n      const groups = Math.max(1, Math.round(length / 0.3))\n      const W = groups * 0.3 + 0.15\n      add(box(W, 0.1, 0.5), 'dark', 0, 0.05, 0)\n      add(box(W - 0.04, 0.3, 0.22), 'steel', 0, 0.25, -0.14)\n      add(box(W, 0.07, 0.5), 'steel', 0, 0.405, 0)\n      for (const side of [-1, 1]) {\n        add(box(0.02, 0.44, 0.5), 'black', side * (W / 2 + 0.01), 0.22, 0)\n        // A steam wand at each end, leaning out over the tray.\n        add(cyl(0.006, 0.006, 0.22, 8), 'steel', side * (W / 2 - 0.05), 0.24, 0.13, [\n          0.35,\n          0,\n          side * 0.25,\n        ])\n      }\n      add(box(W - 0.06, 0.012, 0.24), 'steel', 0, 0.106, 0.11)\n      for (let i = 0; i < groups; i++) {\n        const x = (i - (groups - 1) / 2) * 0.3\n        add(cyl(0.04, 0.04, 0.06), 'steel', x, 0.34, 0.08)\n        add(cyl(0.036, 0.03, 0.03), 'black', x, 0.295, 0.08)\n        add(box(0.024, 0.024, 0.15), 'black', x, 0.295, 0.2)\n        add(cyl(0.028, 0.028, 0.01), 'cream', x - 0.08, 0.26, -0.025, [Math.PI / 2, 0, 0])\n        add(box(0.03, 0.014, 0.006), 'glow', x + 0.07, 0.26, -0.027)\n      }\n      // Cups warming on top, mouth down.\n      for (let i = 0; i < groups * 3; i++)\n        add(cyl(0.03, 0.038, 0.06), 'cream', (i - (groups * 3 - 1) / 2) * 0.095, 0.47, -0.08)\n      break\n    }\n    case 'grinder':\n      add(box(0.16, 0.24, 0.22), 'black', 0, 0.12, 0)\n      add(box(0.1, 0.06, 0.1), 'steel', 0, 0.27, 0)\n      add(cyl(0.085, 0.045, 0.2), 'roast', 0, 0.4, 0)\n      add(cyl(0.088, 0.088, 0.014), 'black', 0, 0.507, 0)\n      add(box(0.04, 0.05, 0.07), 'steel', 0, 0.19, 0.13)\n      add(box(0.09, 0.008, 0.06), 'steel', 0, 0.09, 0.14)\n      add(box(0.03, 0.012, 0.006), 'glow', 0, 0.06, 0.112)\n      break\n    case 'pourover': {\n      const count = Math.max(1, Math.floor(length / 0.22))\n      const W = count * 0.22 + 0.04\n      add(box(W, 0.02, 0.2), 'wood', 0, 0.01, 0)\n      add(box(W, 0.014, 0.11), 'wood', 0, 0.26, 0)\n      for (const side of [-1, 1])\n        add(cyl(0.008, 0.008, 0.25, 8), 'steel', side * (W / 2 - 0.02), 0.135, -0.04)\n      for (let i = 0; i < count; i++) {\n        const x = (i - (count - 1) / 2) * 0.22\n        add(cyl(0.058, 0.02, 0.075), 'cream', x, 0.3, 0)\n        add(cyl(0.04, 0.052, 0.09), 'coffee', x, 0.065, 0)\n        add(cyl(0.03, 0.04, 0.035), 'glass', x, 0.127, 0)\n      }\n      break\n    }\n    case 'chemex':\n      add(cyl(0.025, 0.065, 0.12), 'coffee', 0, 0.06, 0)\n      add(cyl(0.062, 0.025, 0.1), 'glass', 0, 0.17, 0)\n      add(cyl(0.031, 0.031, 0.036), 'wood', 0, 0.12, 0)\n      break\n    case 'press':\n      add(cyl(0.05, 0.05, 0.015), 'steel', 0, 0.0075, 0)\n      add(cyl(0.045, 0.045, 0.15), 'coffee', 0, 0.09, 0)\n      add(cyl(0.048, 0.048, 0.012), 'steel', 0, 0.165, 0)\n      add(cyl(0.045, 0.05, 0.016), 'steel', 0, 0.18, 0)\n      add(cyl(0.004, 0.004, 0.07, 6), 'steel', 0, 0.22, 0)\n      add(ball(0.014), 'black', 0, 0.26, 0)\n      add(box(0.014, 0.11, 0.028), 'black', 0.06, 0.1, 0)\n      break\n    case 'moka':\n      add(cyl(0.035, 0.05, 0.07, 8), 'steel', 0, 0.035, 0)\n      add(cyl(0.038, 0.038, 0.012, 8), 'dark', 0, 0.076, 0)\n      add(cyl(0.05, 0.036, 0.08, 8), 'steel', 0, 0.122, 0)\n      add(cyl(0.018, 0.05, 0.014, 8), 'steel', 0, 0.169, 0)\n      add(ball(0.011), 'black', 0, 0.185, 0)\n      add(box(0.014, 0.07, 0.028), 'black', 0.066, 0.125, 0)\n      break\n    case 'siphon':\n      add(box(0.16, 0.016, 0.14), 'wood', 0, 0.008, 0)\n      add(cyl(0.006, 0.006, 0.36, 8), 'steel', -0.065, 0.19, 0)\n      add(box(0.06, 0.008, 0.012), 'steel', -0.04, 0.2, 0)\n      add(cyl(0.02, 0.026, 0.03), 'steel', 0, 0.031, 0)\n      add(cyl(0.005, 0.012, 0.028, 8), 'glow', 0, 0.06, 0)\n      add(ball(0.05), 'glass', 0, 0.13, 0)\n      add(cyl(0.012, 0.012, 0.04, 8), 'glass', 0, 0.19, 0)\n      add(cyl(0.046, 0.034, 0.11), 'coffee', 0, 0.255, 0)\n      add(cyl(0.048, 0.048, 0.008), 'black', 0, 0.314, 0)\n      break\n    case 'coldbrew':\n      add(box(0.28, 0.02, 0.2), 'wood', 0, 0.01, 0)\n      for (const side of [-1, 1]) add(box(0.02, 0.86, 0.02), 'wood', side * 0.12, 0.45, -0.06)\n      for (const y of [0.34, 0.62, 0.87]) add(box(0.26, 0.014, 0.15), 'wood', 0, y, 0)\n      add(ball(0.075), 'glass', 0, 0.72, 0.01)\n      add(cyl(0.006, 0.006, 0.05, 6), 'steel', 0, 0.645, 0.01)\n      add(cyl(0.04, 0.04, 0.2), 'roast', 0, 0.455, 0.01)\n      add(cyl(0.004, 0.004, 0.16, 6), 'steel', 0, 0.26, 0.01)\n      add(cyl(0.045, 0.06, 0.13), 'coffee', 0, 0.085, 0.01)\n      add(cyl(0.022, 0.032, 0.04), 'glass', 0, 0.17, 0.01)\n      break\n    case 'kettle':\n      add(cyl(0.04, 0.06, 0.1), 'steel', 0, 0.05, 0)\n      add(cyl(0.034, 0.04, 0.012), 'steel', 0, 0.106, 0)\n      add(ball(0.01), 'black', 0, 0.121, 0)\n      add(box(0.012, 0.09, 0.02), 'black', -0.078, 0.07, 0)\n      add(box(0.04, 0.012, 0.02), 'black', -0.058, 0.112, 0)\n      add(cyl(0.005, 0.008, 0.14, 8), 'steel', 0.085, 0.075, 0, [0, 0, -0.65])\n      break\n    case 'batch':\n      add(box(0.26, 0.03, 0.36), 'black', 0, 0.015, 0)\n      add(box(0.26, 0.4, 0.12), 'black', 0, 0.23, -0.12)\n      add(box(0.26, 0.09, 0.36), 'steel', 0, 0.445, 0)\n      add(cyl(0.06, 0.045, 0.07), 'black', 0, 0.365, 0.05)\n      add(cyl(0.065, 0.075, 0.16), 'coffee', 0, 0.11, 0.05)\n      add(cyl(0.05, 0.065, 0.02), 'black', 0, 0.2, 0.05)\n      add(box(0.014, 0.1, 0.03), 'black', 0.09, 0.11, 0.05)\n      add(box(0.03, 0.014, 0.006), 'glow', 0.08, 0.445, 0.182)\n      break\n    case 'ibrik':\n      add(box(0.34, 0.05, 0.24), 'dark', 0, 0.025, 0)\n      add(box(0.31, 0.012, 0.21), 'sand', 0, 0.052, 0)\n      for (const side of [-1, 1]) {\n        add(cyl(0.026, 0.038, 0.065, 10), 'copper', side * 0.075, 0.09, 0)\n        add(box(0.012, 0.008, 0.13), 'copper', side * 0.075, 0.112, 0.09)\n      }\n      break\n    case 'taps':\n      add(box(0.36, 0.015, 0.18), 'steel', 0, 0.0075, 0.05)\n      add(cyl(0.035, 0.035, 0.3), 'steel', 0, 0.165, -0.02)\n      add(box(0.32, 0.055, 0.07), 'steel', 0, 0.34, -0.02)\n      for (const x of [-0.11, 0, 0.11]) {\n        add(cyl(0.008, 0.008, 0.05, 8), 'steel', x, 0.29, 0.03)\n        add(box(0.02, 0.11, 0.02), 'black', x, 0.42, 0.02)\n      }\n      add(box(0.03, 0.014, 0.006), 'glow', 0, 0.34, 0.017)\n      break\n    case 'pitchers': {\n      const count = Math.max(1, Math.floor(length / 0.12))\n      for (let i = 0; i < count; i++) {\n        const x = (i - (count - 1) / 2) * 0.12\n        const s = 1 - 0.18 * (i % 3)\n        add(cyl(0.036 * s, 0.042 * s, 0.1 * s), 'steel', x, 0.05 * s, 0)\n        add(box(0.012, 0.07 * s, 0.022), 'steel', x, 0.055 * s, -0.05 * s)\n      }\n      break\n    }\n    case 'jars':\n      jars(length)\n      break\n    case 'bags':\n      bags(length)\n      break\n    case 'cups': {\n      const count = Math.max(1, Math.floor(length / 0.11))\n      for (let i = 0; i < count; i++) {\n        const stack = 2 + Math.floor(random() * 4)\n        for (let j = 0; j < stack; j++)\n          add(cyl(0.04, 0.03, 0.07), 'cream', (i - (count - 1) / 2) * 0.11, 0.035 + j * 0.028, 0)\n      }\n      break\n    }\n    case 'shelf':\n      for (let row = 0; row < Math.max(1, rows); row++) {\n        oy = row * 0.42\n        add(box(length, 0.03, 0.26), 'wood', 0, -0.015, 0)\n        for (const side of [-1, 1])\n          add(box(0.03, 0.14, 0.2), 'dark', side * (length / 2 - 0.12), -0.1, -0.03)\n        // Bags and jars turn about along each board, half a board of each.\n        const half = length / 2 - 0.1\n        for (const side of [-1, 1]) {\n          ox = (side * length) / 4\n          if ((row + (side + 1) / 2) % 2 === 0) bags(half)\n          else jars(half)\n        }\n        ox = 0\n      }\n      break\n    case 'roaster':\n      // Legs, the firebox, the drum on its side, a hopper over it and a cooling tray in front.\n      for (const x of [-0.3, 0.3])\n        for (const z of [-0.3, 0.3]) add(box(0.05, 0.5, 0.05), 'black', x, 0.25, z)\n      add(box(0.72, 0.5, 0.7), 'dark', 0, 0.75, -0.02)\n      add(cyl(0.3, 0.3, 0.62, 20), 'steel', 0, 1.02, 0, [Math.PI / 2, 0, 0])\n      add(cyl(0.31, 0.31, 0.03, 20), 'black', 0, 1.02, 0.32, [Math.PI / 2, 0, 0])\n      add(cyl(0.07, 0.07, 0.012, 14), 'glow', 0, 1.02, 0.338, [Math.PI / 2, 0, 0])\n      add(cyl(0.2, 0.06, 0.26), 'steel', 0, 1.45, 0.05)\n      add(cyl(0.06, 0.06, 1.5, 10), 'black', 0.2, 1.9, -0.25)\n      add(cyl(0.34, 0.34, 0.1, 20), 'steel', 0, 0.62, 0.62)\n      add(cyl(0.32, 0.32, 0.012, 20), 'roast', 0, 0.672, 0.62)\n      add(box(0.06, 0.6, 0.06), 'black', 0, 0.3, 0.62)\n      add(box(0.03, 0.03, 0.2), 'black', 0.33, 1.02, 0.4)\n      break\n  }\n  return out\n}\n\n/**\n * What a cafe makes coffee with and shows it off in: machines, brewers, a roaster, and the beans\n * in bags and jars. One `kind` to a node, standing on whatever is under its `position`. Scenery:\n * nothing here is glass, so the whole bar merges into the building's static batch, and only the\n * roaster, which stands on the floor, has a collider.\n */\nexport function CoffeeGear({\n  position,\n  rotation = [0, 0, 0],\n  seed = 0,\n  kind = 'espresso',\n  length = 0.6,\n  rows = 3,\n  glow = '#ffa64d',\n}: CoffeeGearProps) {\n  const { unit, palette, ground } = useWorld()\n  const lum = useLadder()\n  const paints = useMaterials({\n    steel: { slot: 'metal.bare', color: '#9a9ea3', roughness: 0.35, metalness: 0.55 },\n    dark: { slot: 'metal.painted', color: palette.metal, roughness: 0.6, metalness: 0.3 },\n    black: { color: '#17181b', roughness: 0.7 },\n    coffee: { color: '#2a1e18', roughness: 0.4 },\n    roast: { color: '#4a3528', roughness: 0.8 },\n    blonde: { color: '#7d6248', roughness: 0.8 },\n    wood: { slot: 'wood', color: '#5c4636', roughness: 0.85 },\n    cream: { slot: 'ceramic', color: '#d6cfc2', roughness: 0.6 },\n    glass: { slot: 'glass', color: '#8c9aa0', roughness: 0.15, metalness: 0.2 },\n    copper: { slot: 'metal.bare', color: '#9a6a4c', roughness: 0.4, metalness: 0.6 },\n    sand: { color: '#a3927a', roughness: 1 },\n    bagA: { slot: 'fabric', color: '#7a6450', roughness: 0.9 },\n    bagB: { slot: 'fabric', color: '#4d3b36', roughness: 0.9 },\n    bagC: { slot: 'fabric', color: '#3d4642', roughness: 0.9 },\n    bagD: { slot: 'fabric', color: '#56505c', roughness: 0.9 },\n  })\n  const lit = glowMaterial(glow, mid(lum.shopGlass))\n  const parts = useMemo(\n    () => build(kind, Math.abs(length), rows, seed, unit),\n    [kind, length, rows, seed, unit],\n  )\n  return (\n    <group position={position ?? [0, ground, 0]} rotation={rotation}>\n      {kind === 'roaster' && (\n        <RigidBody type=\"fixed\" colliders={false}>\n          <CuboidCollider\n            args={[0.4 * unit, 0.7 * unit, 0.65 * unit]}\n            position={[0, 0.7 * unit, 0.15 * unit]}\n          />\n        </RigidBody>\n      )}\n      {parts.map((part, i) => (\n        <mesh\n          key={i}\n          position={part.p}\n          rotation={part.r}\n          geometry={part.g}\n          material={part.m === 'glow' ? lit : paints[part.m]}\n        />\n      ))}\n    </group>\n  )\n}\n",
      "type": "registry:component"
    },
    {
      "path": "city/glow.ts",
      "content": "// How bright each kind of city emitter is, as a ladder of rungs, each the lowest and highest\n// luminance that kind may have, so a sign face is a sign face whatever its hue and a lamp lens\n// always outshines it. The rungs are face values scaled by the world's luminance levels\n// (`useLuminance()`): sign faces by `sign`, tube cores by `tube`, lamp lenses by `lamp`, and lit\n// glass (windows, shopfronts, ad boards, and the light they leave on the pavement) by `screen`.\n// At every level's default of 1 the brightest rungs sit around 1, so they read without bloom; a\n// world with bloom raises `sign`, `tube` and `lamp` to make them bloom.\n//\n// Emissive colors are normalized to unit luminance and then scaled onto a rung, so the hue of a\n// color never changes how bright it reads.\n\nimport {\n  DEFAULT_LUMINANCE,\n  glowLook,\n  type MaterialLook,\n  materialKey,\n  retainMaterial,\n  sharedMaterial,\n  useLuminance,\n  type WorldLuminance,\n} from '@runek/core'\nimport { useMemo } from 'react'\nimport { Color, type Material } from 'three'\n\n/** A rung of the ladder: the lowest and highest luminance that kind of emitter may have. */\nexport type Rung = readonly [number, number]\n\nexport interface Ladder {\n  /** A night sky dome lit from below by a city. Face value. */\n  skyDome: Rung\n  /** A wall with no lamp on it. Face value. */\n  unlitWall: Rung\n  /** Pavement lit by the glass and signs above it. */\n  streetUnderSign: Rung\n  /** A lit room seen through its window from the street. */\n  windowLit: Rung\n  /** Lit shopfront glass, and the white of an ad board. */\n  shopGlass: Rung\n  /** Sign faces and lit letters. */\n  signFace: Rung\n  /** The core of a neon tube. */\n  tubeCore: Rung\n  /** A street lamp's lens seen from below. */\n  lampLens: Rung\n}\n\nconst scale = (r: Rung, k: number): Rung => [r[0] * k, r[1] * k]\n\n/** The rungs at every luminance level's face value (1). */\nexport const FACE_LADDER: Ladder = {\n  skyDome: [0.018, 0.055],\n  unlitWall: [0.02, 0.05],\n  streetUnderSign: [0.1, 0.5],\n  windowLit: [0.15, 0.6],\n  shopGlass: [0.4, 1.2],\n  signFace: [0.6, 1.6],\n  tubeCore: [0.6, 1.7],\n  lampLens: [0.67, 1.5],\n}\n\n/** The ladder for a world's luminance levels. */\nexport function ladderFor(l: WorldLuminance): Ladder {\n  const f = FACE_LADDER\n  return {\n    skyDome: f.skyDome,\n    unlitWall: f.unlitWall,\n    streetUnderSign: scale(f.streetUnderSign, l.screen),\n    windowLit: scale(f.windowLit, l.screen),\n    shopGlass: scale(f.shopGlass, l.screen),\n    signFace: scale(f.signFace, l.sign),\n    tubeCore: scale(f.tubeCore, l.tube),\n    lampLens: scale(f.lampLens, l.lamp),\n  }\n}\n\n/** The ladder at the default levels. */\nexport const DEFAULT_LADDER: Ladder = ladderFor(DEFAULT_LUMINANCE)\n\n/** The world's ladder, from its luminance levels. */\nexport function useLadder(): Ladder {\n  const { screen, sign, tube, lamp, flame } = useLuminance()\n  return useMemo(\n    () => ladderFor({ screen, sign, tube, lamp, flame }),\n    [screen, sign, tube, lamp, flame],\n  )\n}\n\n/** The typical value of a rung: the geometric middle, since luminance is perceived on a log scale. */\nexport function mid(rung: Rung): number {\n  return Math.sqrt(rung[0] * rung[1])\n}\n\n/** A point along a rung, 0 at its bottom and 1 at its top, spaced evenly on a log scale. */\nexport function along(rung: Rung, t: number): number {\n  return rung[0] * (rung[1] / rung[0]) ** t\n}\n\n/** Relative luminance (Rec. 709) of a linear color. */\nexport function luminanceOf(c: Color): number {\n  return 0.2126 * c.r + 0.7152 * c.g + 0.0722 * c.b\n}\n\n/** `hex` at unit luminance times `luminance`, as a linear (HDR) color. */\nexport function emissiveColor(hex: string, luminance: number): Color {\n  const c = new Color(hex)\n  return c.multiplyScalar(luminance / Math.max(1e-4, luminanceOf(c)))\n}\n\n/** A shared look's material, kept for the life of the page: city emitters come back often. */\nfunction kept(look: MaterialLook): Material {\n  const key = materialKey(look)\n  const material = sharedMaterial(look, key)\n  if (!material.userData.kept) {\n    material.userData.kept = true\n    retainMaterial(key)\n  }\n  return material\n}\n\n/**\n * The shared unlit material for an emitter of color `hex` at `luminance`, through core's\n * `glowLook`, so it batches with every other part of that look. Read-only.\n */\nexport function glowMaterial(hex: string, luminance: number, opacity = 1): Material {\n  return kept(\n    glowLook(\n      emissiveColor(hex, 1),\n      luminance,\n      opacity < 1 ? { transparent: true, opacity, depthWrite: false } : undefined,\n    ),\n  )\n}\n\n/**\n * The shared unlit material for picture content on a lit board: `hex` keeps its own value and\n * is scaled so that white would shine at `white`. Dark backgrounds stay dark, bright text and\n * shapes glow.\n */\nexport function screenMaterial(hex: string, white: number): Material {\n  return kept(glowLook(hex, white))\n}\n",
      "type": "registry:component"
    }
  ]
}
