{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "floating-shapes",
  "type": "registry:component",
  "title": "Floating Shapes",
  "description": "A few simple solids (icosahedron, torus, box, octahedron) floating and turning slowly, flat-shaded or wireframe, coloured from theme variables.",
  "categories": [
    "three"
  ],
  "dependencies": [
    "@react-three/fiber",
    "three"
  ],
  "devDependencies": [
    "@types/three"
  ],
  "registryDependencies": [
    "@rivier-ui/theme",
    "@rivier-ui/theme-color"
  ],
  "files": [
    {
      "path": "registry/three/floating-shapes.tsx",
      "type": "registry:component",
      "target": "components/three/floating-shapes.tsx",
      "content": "\"use client\";\n/**\n * @name floating-shapes\n * @category three\n * @description A few simple solids (icosahedron, torus, box, octahedron) floating and turning slowly, flat-shaded or wireframe, coloured from theme variables.\n * @when An abstract, geometric accent for a hero or a feature section. Use it inside scene. For a single soft object use orb; to show a real object use model-stage.\n * @example\n * <Scene aspect={16 / 9}>\n *   <FloatingShapes />\n * </Scene>\n *\n * <Scene aspect={2}>\n *   <FloatingShapes\n *     shapes={[\n *       { kind: \"torus\", position: [-1.5, 0, 0], color: \"--highlight\" },\n *       { kind: \"box\", position: [1.5, 0.4, -1], size: 0.8, color: \"--foreground\", wireframe: true },\n *     ]}\n *   />\n * </Scene>\n */\nimport { useFrame, useThree } from \"@react-three/fiber\";\nimport { useMemo, useRef } from \"react\";\nimport type { Group } from \"three\";\nimport { useThemeColors } from \"@/lib/theme-color\";\n\nexport type FloatingShape = {\n  kind: \"icosahedron\" | \"torus\" | \"box\" | \"octahedron\";\n  /** Where it rests, in scene units. The default camera sees about ±3.5 across and ±2 up at z = 0. */\n  position: [number, number, number];\n  /** Scale. 1 is about one unit in radius. */\n  size?: number;\n  /** The CSS variable it takes its colour from. */\n  color?: string;\n  /** Draw edges only. */\n  wireframe?: boolean;\n  /** Its own pace, multiplied by the component's `speed`. */\n  speed?: number;\n};\n\nexport type FloatingShapesProps = {\n  /** Which shapes, and where. */\n  shapes?: readonly FloatingShape[];\n  /** Overall pace of the floating and turning. 0 holds everything still. */\n  speed?: number;\n  /** Faceted faces (true) or smooth shading (false). */\n  flat?: boolean;\n};\n\nconst DEFAULT_SHAPES: readonly FloatingShape[] = [\n  { kind: \"icosahedron\", position: [-2.1, 0.5, 0], size: 1.05, color: \"--highlight\" },\n  { kind: \"torus\", position: [1.9, 0.8, -0.8], size: 0.95, color: \"--foreground\", wireframe: true },\n  { kind: \"box\", position: [1.1, -1.1, 0.5], size: 0.7, color: \"--muted-foreground\" },\n  { kind: \"octahedron\", position: [-0.5, -1.2, -1], size: 0.6, color: \"--chart-2\" },\n];\n\nfunction ShapeGeometry({ kind }: { kind: FloatingShape[\"kind\"] }) {\n  if (kind === \"torus\") return <torusGeometry args={[0.72, 0.26, 12, 36]} />;\n  if (kind === \"box\") return <boxGeometry args={[1.3, 1.3, 1.3]} />;\n  if (kind === \"octahedron\") return <octahedronGeometry args={[1, 0]} />;\n  return <icosahedronGeometry args={[1, 1]} />;\n}\n\nexport function FloatingShapes({ shapes = DEFAULT_SHAPES, speed = 1, flat = true }: FloatingShapesProps) {\n  const group = useRef<Group>(null);\n  const time = useRef(0);\n  const lean = useRef({ x: 0, y: 0 });\n  const canvas = useThree((state) => state.gl.domElement);\n  const names = useMemo(() => [...new Set(shapes.map((shape) => shape.color ?? \"--highlight\"))], [shapes]);\n  const colors: Record<string, string> = useThemeColors(names, canvas);\n\n  useFrame((state, delta) => {\n    const dt = Math.min(delta, 0.1);\n    time.current += dt * speed;\n    const ease = 1 - Math.exp(-dt * 2.5);\n    lean.current.x += (state.pointer.x - lean.current.x) * ease;\n    lean.current.y += (state.pointer.y - lean.current.y) * ease;\n    const root = group.current;\n    if (!root) return;\n    root.rotation.y = lean.current.x * 0.1;\n    root.rotation.x = -lean.current.y * 0.07;\n    const children = root.children;\n    for (let index = 0; index < children.length; index += 1) {\n      const child = children[index];\n      const shape = shapes[index];\n      if (!child || !shape) continue;\n      const pace = shape.speed ?? 1;\n      const phase = index * 1.7;\n      const t = time.current * pace;\n      child.position.y = shape.position[1] + Math.sin(t * 0.6 + phase) * 0.16;\n      child.rotation.x = t * 0.16 + phase;\n      child.rotation.y = t * 0.22 + phase * 0.5;\n    }\n  });\n\n  // Everything below is declared, so react-three-fiber disposes of the geometries and materials.\n  return (\n    <>\n      <ambientLight intensity={1.9} />\n      <directionalLight position={[3, 5, 4]} intensity={1.7} />\n      <group ref={group}>\n        {shapes.map((shape, index) => (\n          <mesh key={`${shape.kind}:${index}`} position={shape.position} scale={shape.size ?? 1}>\n            <ShapeGeometry kind={shape.kind} />\n            <meshLambertMaterial key={flat ? \"flat\" : \"smooth\"} color={colors[shape.color ?? \"--highlight\"]} flatShading={flat} wireframe={shape.wireframe === true} />\n          </mesh>\n        ))}\n      </group>\n    </>\n  );\n}\n"
    }
  ],
  "meta": {
    "category": "three",
    "when": "An abstract, geometric accent for a hero or a feature section. Use it inside scene. For a single soft object use orb; to show a real object use model-stage.",
    "example": "<Scene aspect={16 / 9}>\n  <FloatingShapes />\n</Scene>\n\n<Scene aspect={2}>\n  <FloatingShapes\n    shapes={[\n      { kind: \"torus\", position: [-1.5, 0, 0], color: \"--highlight\" },\n      { kind: \"box\", position: [1.5, 0.4, -1], size: 0.8, color: \"--foreground\", wireframe: true },\n    ]}\n  />\n</Scene>",
    "client": true
  }
}
