{
  "name": "mic-stand",
  "title": "MicStand",
  "type": "registry:component",
  "description": "A vocal mic on a tripod stand, straight up at a singer's mouth or on a boom arm reaching toward +Z over a seated player. Decorative.",
  "dependencies": [
    "@runek/core@^0.18.0",
    "three@^0.184.0"
  ],
  "registryDependencies": [],
  "files": [
    {
      "path": "MicStand.tsx",
      "content": "import { useMaterials, useWorld, type WorldComponentProps } from '@runek/core'\nimport { useMemo } from 'react'\nimport { Quaternion, Vector3 } from 'three'\n\nexport interface MicStandProps extends WorldComponentProps {\n  /** To the middle of the mic's grille, in units. Defaults to 1.6, a standing singer's mouth,\n   *  or 1.25 on a boom, a seated player's. */\n  height?: number\n  /** Hold the mic on a boom arm reaching toward local +Z, instead of straight up. */\n  boom?: boolean\n}\n\nconst UP = new Vector3(0, 1, 0)\nconst FRONT = new Vector3(0, 0, 1)\nconst HANDLE = 0.17\n\n/** A cylinder's centre, turn and length to run from `a` to `b`. */\nfunction strut(a: Vector3, b: Vector3) {\n  const d = b.clone().sub(a)\n  return {\n    position: a.clone().add(b).multiplyScalar(0.5).toArray(),\n    quaternion: new Quaternion().setFromUnitVectors(UP, d.clone().normalize()),\n    length: d.length(),\n  }\n}\n\n/**\n * A vocal microphone on a tripod stand: three splayed legs, a pole, and a mic with a round\n * grille, held straight up and tipped toward local +Z, or on a `boom` arm with a counterweight\n * that reaches out over a seated player. Decorative: no collider.\n */\nexport function MicStand({\n  position = [0, 0, 0],\n  rotation = [0, 0, 0],\n  height,\n  boom = false,\n}: MicStandProps) {\n  const { unit: u } = useWorld()\n  const m = useMaterials({\n    dark: { color: '#1d1d1f', roughness: 0.5 },\n    chrome: { slot: 'metal.bare', color: '#c9ccd1', roughness: 0.3, metalness: 0.8 },\n  })\n  const H = height ?? (boom ? 1.25 : 1.6)\n\n  const parts = useMemo(() => {\n    const v = (x: number, y: number, z: number) => new Vector3(x * u, y * u, z * u)\n    const hub = v(0, 0.28, 0)\n    const legs = [0, 1, 2].map((i) => {\n      const a = (i * 2 * Math.PI) / 3 + Math.PI\n      return strut(hub, v(Math.sin(a) * 0.32, 0.01, Math.cos(a) * 0.32))\n    })\n    let top: Vector3\n    let arm: ReturnType<typeof strut> | null = null\n    let weight: Vector3 | null = null\n    let mic: Vector3\n    let aim: Vector3\n    if (boom) {\n      top = v(0, Math.max(0.6, H - 0.35), 0)\n      const tip = top.clone().add(v(0, H - top.y / u + 0.06, 0.7))\n      const dir = tip.clone().sub(top).normalize()\n      weight = top.clone().addScaledVector(dir, -0.3 * u)\n      arm = strut(weight, tip)\n      mic = tip\n      aim = new Vector3(0, -0.4, 1).normalize()\n    } else {\n      aim = new Vector3(0, Math.cos(0.35), Math.sin(0.35))\n      top = v(0, H - HANDLE * aim.y - 0.02, 0)\n      mic = top.clone().add(v(0, 0.02, 0))\n    }\n    const grille = mic.clone().addScaledVector(aim, HANDLE * u)\n    return {\n      legs,\n      pole: strut(v(0, 0.2, 0), top),\n      top,\n      arm,\n      weight,\n      handle: strut(mic, grille.clone().addScaledVector(aim, -0.02 * u)),\n      grille: grille.toArray(),\n      band: grille\n        .clone()\n        .addScaledVector(aim, -0.012 * u)\n        .toArray(),\n      aim: new Quaternion().setFromUnitVectors(FRONT, aim),\n    }\n  }, [H, boom, u])\n\n  return (\n    <group position={position} rotation={rotation}>\n      {parts.legs.map((leg) => (\n        <mesh\n          key={leg.position.join()}\n          material={m.dark}\n          position={leg.position}\n          quaternion={leg.quaternion}\n          castShadow\n        >\n          <cylinderGeometry args={[0.009 * u, 0.009 * u, leg.length, 6]} />\n        </mesh>\n      ))}\n      <mesh\n        material={m.dark}\n        position={parts.pole.position}\n        quaternion={parts.pole.quaternion}\n        castShadow\n      >\n        <cylinderGeometry args={[0.013 * u, 0.016 * u, parts.pole.length, 8]} />\n      </mesh>\n      <mesh material={m.chrome} position={parts.top.toArray()}>\n        <sphereGeometry args={[0.024 * u, 10, 8]} />\n      </mesh>\n      {parts.arm && parts.weight && (\n        <>\n          <mesh\n            material={m.dark}\n            position={parts.arm.position}\n            quaternion={parts.arm.quaternion}\n            castShadow\n          >\n            <cylinderGeometry args={[0.01 * u, 0.01 * u, parts.arm.length, 6]} />\n          </mesh>\n          <mesh\n            material={m.chrome}\n            position={parts.weight.toArray()}\n            quaternion={parts.arm.quaternion}\n          >\n            <cylinderGeometry args={[0.03 * u, 0.03 * u, 0.09 * u, 12]} />\n          </mesh>\n        </>\n      )}\n      <mesh\n        material={m.dark}\n        position={parts.handle.position}\n        quaternion={parts.handle.quaternion}\n        castShadow\n      >\n        <cylinderGeometry args={[0.019 * u, 0.013 * u, parts.handle.length, 12]} />\n      </mesh>\n      <mesh material={m.chrome} position={parts.grille} castShadow>\n        <sphereGeometry args={[0.028 * u, 14, 10]} />\n      </mesh>\n      <mesh material={m.dark} position={parts.band} quaternion={parts.aim}>\n        <torusGeometry args={[0.026 * u, 0.003 * u, 6, 20]} />\n      </mesh>\n    </group>\n  )\n}\n\nMicStand.groundSitting = true\n",
      "type": "registry:component"
    }
  ]
}
