{
  "name": "plant",
  "title": "Plant",
  "type": "registry:component",
  "description": "Potted plant: a tapered planter and a seeded cluster of foliage.",
  "dependencies": [
    "@react-three/rapier@^2.2.0",
    "@runek/core@^0.12.0",
    "three@^0.184.0"
  ],
  "registryDependencies": [],
  "files": [
    {
      "path": "Plant.tsx",
      "content": "import { CuboidCollider, RigidBody } from '@react-three/rapier'\nimport { rng, useWorld, type Vec3 } from '@runek/core'\nimport { useMemo } from 'react'\nimport * as THREE from 'three'\n\nexport interface PlantProps {\n  position?: Vec3\n  rotation?: Vec3\n  height?: number\n  /** Planter color; defaults to the world palette's `wood` slot. */\n  potColor?: string\n  /** Foliage color; defaults to the world palette's `foliage` slot. */\n  foliageColor?: string\n  seed?: number\n}\n\ninterface Leaf {\n  pos: Vec3\n  r: number\n  color: string\n}\n\n/** A potted plant: a tapered planter, soil, and a seeded cluster of foliage. Indoor\n *  life. The planter owns a small collider. */\nexport function Plant({\n  position = [0, 0, 0],\n  rotation = [0, 0, 0],\n  height = 0.7,\n  potColor,\n  foliageColor,\n  seed = 1,\n}: PlantProps) {\n  const { unit, palette } = useWorld()\n  const pot = potColor ?? palette.wood\n  const foliage = foliageColor ?? palette.foliage\n  const H = height * unit\n  const potH = H * 0.4\n  const potR = 0.18 * unit\n\n  const leaves = useMemo<Leaf[]>(() => {\n    const next = rng(seed)\n    const base = new THREE.Color(foliage)\n    const tint = new THREE.Color()\n    return Array.from({ length: 6 }, () => {\n      const a = next() * Math.PI * 2\n      const rad = next() * potR * 0.8\n      return {\n        pos: [Math.cos(a) * rad, potH + 0.1 * unit + next() * H * 0.4, Math.sin(a) * rad] as Vec3,\n        r: (0.1 + next() * 0.1) * unit,\n        color: tint\n          .copy(base)\n          .multiplyScalar(0.8 + next() * 0.4)\n          .getStyle(),\n      }\n    })\n  }, [potR, potH, H, foliage, seed, unit])\n\n  return (\n    <RigidBody type=\"fixed\" colliders={false} position={position} rotation={rotation}>\n      <CuboidCollider args={[potR, potH / 2, potR]} position={[0, potH / 2, 0]} />\n      <mesh castShadow receiveShadow position={[0, potH / 2, 0]}>\n        <cylinderGeometry args={[potR, potR * 0.78, potH, 16]} />\n        <meshStandardMaterial color={pot} roughness={0.9} />\n      </mesh>\n      <mesh position={[0, potH - 0.01 * unit, 0]} rotation={[-Math.PI / 2, 0, 0]}>\n        <circleGeometry args={[potR * 0.92, 16]} />\n        <meshStandardMaterial color=\"#3a2a1a\" roughness={1} />\n      </mesh>\n      {leaves.map((l) => (\n        <mesh\n          key={`leaf-${l.pos[0].toFixed(3)}:${l.pos[1].toFixed(3)}`}\n          castShadow\n          position={l.pos}\n        >\n          <icosahedronGeometry args={[l.r, 0]} />\n          <meshStandardMaterial color={l.color} flatShading roughness={0.9} />\n        </mesh>\n      ))}\n    </RigidBody>\n  )\n}\n",
      "type": "registry:component"
    }
  ]
}
