react-three-fiber
БесплатноБез исполняемых скриптовНе проверенBuilds 3D scenes in React with React Three Fiber (R3F), a React renderer for Three.js where meshes, lights and cameras are JSX components. Use when a user…
от TerminalSkills★ 221 звезда на GitHubОб этом скилле
React Three Fiber — Declarative Three.js for React
Overview
React Three Fiber (R3F) is a React renderer for Three.js. You write scenes as JSX (<mesh>, <boxGeometry>, <meshStandardMaterial>), and props map straight onto Three.js object properties. Hooks, state, Suspense and context work as in any React app, and everything in the Three.js ecosystem stays available. @react-three/drei adds ready-made helpers (controls, loaders, environment maps, text, HTML overlays).
Current versions: @react-three/fiber 9.8, @react-three/drei 10.7, three 0.186. R3F 9 requires React 19; with React 18 install @react-three/fiber@8 and @react-three/drei@9.
Instructions
Install
npm install three @react-three/fiber @react-three/drei
npm install -D @types/three # TypeScript
npm install @react-three/postprocessing # optional: bloom, depth of field, etc.
In Next.js, components that render a <Canvas> must be client components ('use client'). If a Three.js add-on ships untranspiled code, add transpilePackages: ['three'] to next.config.js.
Canvas and scene
'use client'
import { Canvas } from '@react-three/fiber'
import { OrbitControls, Environment } from '@react-three/drei'
export default function Scene() {
return (
<Canvas camera={{ position: [0, 2, 5], fov: 50 }} dpr={[1, 2]} shadows>
<ambientLight intensity={0.4} />
<directionalLight position={[5, 5, 5]} castShadow />
<mesh position={[0, 1, 0]} castShadow>
<boxGeometry args={[1, 1, 1]} />
<meshStandardMaterial color="orange" />
</mesh>
<mesh rotation={[-Math.PI / 2, 0, 0]} receiveShadow>
<planeGeometry args={[10, 10]} />
<meshStandardMaterial color="#444" />
</mesh>
<OrbitControls />
<Environment preset="city" />
</Canvas>
)
}
Canvas fills its parent, so give the parent a height. Defaults: dpr [1, 2], sRGB output and ACES filmic tone mapping, a translucent WebGL renderer with antialiasing. Pass fallback={<p>WebGL is not available</p>} for devices without WebGL.
Animation with useFrame
import { useRef } from 'react'
import { useFrame } from '@react-three/fiber'
import * as THREE from 'three'
function SpinningBox() {
const meshRef = useRef<THREE.Mesh>(null)
useFrame((state, delta) => {
if (!meshRef.current) return
meshRef.current.rotation.y += delta // frame-rate independent
meshRef.current.position.x = THREE.MathUtils.lerp(
meshRef.current.position.x, state.pointer.x * 2, 0.1, // pointer is -1..1; state.mouse is deprecated
)
})
return (
<mesh ref={meshRef}>
<boxGeometry />
<meshStandardMaterial color="hotpink" />
</mesh>
)
}
Mutate refs inside useFrame; never call setState there. useThree() returns the renderer, scene, camera, viewport and size.
Loading models
import { Suspense, useEffect } from 'react'
import { useGLTF, useAnimations } from '@react-three/drei'
function Character({ animation = 'idle' }: { animation?: string }) {
const { scene, animations } = useGLTF('/models/character.glb')
const { actions } = useAnimations(animations, scene)
useEffect(() => {
actions[animation]?.reset().fadeIn(0.3).play()
return () => { actions[animation]?.fadeOut(0.3) }
}, [animation, actions])
return <primitive object={scene} scale={1.5} />
}
useGLTF.preload('/models/character.glb')
// <Canvas><Suspense fallback={null}><Character /></Suspense></Canvas>
useGLTF decodes Draco-compressed files out of the box. To get a typed JSX component for a model and a compressed copy, run npx gltfjsx model.glb --transform --types; it writes model-transformed.glb (Draco, resized webp textures, pruned) and a component.
Events
import { useState } from 'react'
function InteractiveBox() {
const [hovered, setHovered] = useState(false)
const [active, setActive] = useState(false)
return (
<mesh
scale={active ? 1.5 : 1}
onClick={(e) => { e.stopPropagation(); setActive(!active) }}
onPointerOver={() => setHovered(true)}
onPointerOut={() => setHovered(false)}
>
<boxGeometry />
<meshStandardMaterial color={hovered ? 'hotpink' : 'orange'} />
</mesh>
)
}
R3F raycasts pointer events onto meshes. Use e.stopPropagation() so objects behind the hit do not also fire, and onPointerMissed on Canvas for clicks on empty space.
Rendering only when needed
<Canvas frameloop="demand">…</Canvas>
// elsewhere: const invalidate = useThree((s) => s.invalidate); invalidate()
With frameloop="demand" a frame is drawn only when props change or invalidate() is called; useful for static configurators on laptops and phones.
Examples
Example 1: Product viewer in a Next.js page
User prompt: "Show our sneaker.glb on the product page, let people rotate it, and keep the page fast."
Create a 'use client' compo
Установить react-three-fiber в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл react-three-fiber?
Builds 3D scenes in React with React Three Fiber (R3F), a React renderer for Three.js where meshes, lights and cameras are JSX components. Use when a user asks to add a 3D scene to a React or Next.js site, build a product configurator, load a GLTF model, animate with useFrame, handle click and hover on 3D objects, or speed up a slow R3F scene.
Как установить скилл react-three-fiber?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл react-three-fiber запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic