{
  "name": "glass-wall",
  "title": "GlassWall",
  "type": "registry:component",
  "description": "A floor-to-ceiling glass partition: panes between slim mullions in a frame, with an optional doorway and a pane over it. A cuboid collider either side of the doorway.",
  "dependencies": [
    "@react-three/rapier@^2.2.0",
    "@runek/core@^0.18.0"
  ],
  "registryDependencies": [],
  "files": [
    {
      "path": "GlassWall.tsx",
      "content": "import { CuboidCollider, RigidBody } from '@react-three/rapier'\nimport { useMaterials, useWorld, type WorldComponentProps } from '@runek/core'\nimport { useMemo } from 'react'\n\n/** A doorway left open in a `GlassWall`, all in units. */\nexport interface GlassWallDoor {\n  /** From the middle of the wall along X. */\n  offset?: number\n  width?: number\n  height?: number\n}\n\nexport interface GlassWallProps extends WorldComponentProps {\n  /** Length along local X, in units, centred on the origin. */\n  width?: number\n  height?: number\n  /** A doorway left open in it, with a pane over it to the top. */\n  door?: GlassWallDoor\n  /** Widest a pane runs before a mullion, in units. */\n  pane?: number\n  /** Glass tint. */\n  glassColor?: string\n  /** How much the glass hides, 0 clear to 1 opaque. Dark and high makes a smoked partition. */\n  opacity?: number\n  /** Frame and mullions. Defaults to the world palette's `metal` slot. */\n  color?: string\n}\n\nconst FRAME = 0.05\n\n/**\n * A floor-to-ceiling glass wall for an office or a meeting room: panes between slim mullions in\n * a frame along local X, with a doorway left open where `door` says. The straight, indoor\n * sibling of `CurvedWall`'s glass. A cuboid collider either side of the doorway.\n */\nexport function GlassWall({\n  position = [0, 0, 0],\n  rotation = [0, 0, 0],\n  width = 4,\n  height = 3,\n  door,\n  pane = 1.2,\n  glassColor = '#b7d8e8',\n  opacity = 0.22,\n  color,\n}: GlassWallProps) {\n  const { unit, palette } = useWorld()\n  const m = useMaterials({\n    glass: { slot: 'glass', color: glassColor, transparent: true, opacity, roughness: 0.06 },\n    steel: { slot: 'metal.painted', color: color ?? palette.metal, roughness: 0.4, metalness: 0.5 },\n  })\n  const W = width * unit\n  const H = height * unit\n  const f = FRAME * unit\n  const doorW = door ? (door.width ?? 1) * unit : 0\n  const doorH = door ? (door.height ?? 2.2) * unit : 0\n  const doorX = door ? (door.offset ?? 0) * unit : 0\n\n  const { runs, mullions } = useMemo(() => {\n    // The solid stretches either side of the doorway, as [left, right] along X.\n    const spans: [number, number][] = doorW\n      ? [\n          [-W / 2, doorX - doorW / 2],\n          [doorX + doorW / 2, W / 2],\n        ]\n      : [[-W / 2, W / 2]]\n    const solid = spans.filter(([a, b]) => b - a > 1e-3)\n    const xs: number[] = []\n    for (const [a, b] of solid) {\n      const n = Math.max(1, Math.ceil((b - a) / (pane * unit)))\n      for (let i = 0; i <= n; i++) xs.push(a + ((b - a) * i) / n)\n    }\n    return { runs: solid, mullions: xs }\n  }, [W, doorW, doorX, pane, unit])\n\n  return (\n    <RigidBody type=\"fixed\" colliders={false} position={position} rotation={rotation}>\n      {runs.map(([a, b]) => (\n        <CuboidCollider\n          key={`c${a}`}\n          args={[(b - a) / 2, H / 2, 0.04 * unit]}\n          position={[(a + b) / 2, H / 2, 0]}\n        />\n      ))}\n      {runs.map(([a, b]) => (\n        <mesh key={`g${a}`} material={m.glass} position={[(a + b) / 2, H / 2, 0]}>\n          <boxGeometry args={[b - a, H - f * 2, 0.012 * unit]} />\n        </mesh>\n      ))}\n      {doorW > 0 && H - doorH > f * 2 && (\n        <mesh material={m.glass} position={[doorX, (doorH + H) / 2, 0]}>\n          <boxGeometry args={[doorW, H - doorH - f, 0.012 * unit]} />\n        </mesh>\n      )}\n      {doorW > 0 && (\n        <mesh material={m.steel} castShadow position={[doorX, doorH + f / 2, 0]}>\n          <boxGeometry args={[doorW, f, f]} />\n        </mesh>\n      )}\n      <mesh material={m.steel} castShadow position={[0, H - f / 2, 0]}>\n        <boxGeometry args={[W, f, f * 1.2]} />\n      </mesh>\n      {runs.map(([a, b]) => (\n        <mesh\n          key={`t${a}`}\n          material={m.steel}\n          castShadow\n          receiveShadow\n          position={[(a + b) / 2, f / 2, 0]}\n        >\n          <boxGeometry args={[b - a, f, f * 1.2]} />\n        </mesh>\n      ))}\n      {mullions.map((x) => (\n        <mesh key={`m${x}`} material={m.steel} castShadow position={[x, H / 2, 0]}>\n          <boxGeometry args={[f * 0.8, H, f]} />\n        </mesh>\n      ))}\n    </RigidBody>\n  )\n}\n\nGlassWall.groundSitting = true\n",
      "type": "registry:component"
    }
  ]
}
