agentleFS
manish1803manish1803/nextjs-fullstack-skills/skills/01-frontend-engineering/react-three-fiber-3d/SKILL.md

react-three-fiber-3d

Skill2 starsChanged 4 months agoMITView on GitHub

Build performant 3D web experiences with React Three Fiber (R3F), drei, and Three.js — scenes, models, materials, lighting, camera controls, and post-processing, integrated cleanly into a Next.js/React app. Use whenever the user mentions "3D", "Three.js", "React Three Fiber", "R3F", "WebGL", 3D product viewers, 3D hero sections, GLTF/GLB models, or wants an immersive/interactive 3D web experience. Always check performance implications (draw calls, bundle size, mobile fallback) as part of this skill.

  • Installs packages

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 2 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Limit real-time shadows: prefer baked lighting or a single shadow-casting light.

    line 43
  2. Very specific:

    Frameloop: use frameloop="demand" on the Canvas for static/product-viewer scenes that only need to re-render on interaction, not always …

    line 44
  3. Distinctive:

    No loading state / fallback while the model streams in

    line 56
  4. Distinctive:

    No reduced-motion / low-power fallback

    line 57

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

React Three Fiber (R3F) 3D Experience Skill

Guides building production 3D web experiences that are performant, SSR-safe (Next.js), and don't tank Core Web Vitals or mobile framerate.

Setup essentials

npm i three @react-three/fiber @react-three/drei
npm i -D @types/three

R3F components are client-only — the Canvas and everything inside it must live in a "use client" boundary. In Next.js, dynamically import the whole 3D scene with ssr: false to avoid hydration mismatches:

const Scene = dynamic(() => import('@/components/three/Scene'), { ssr: false });

Baseline scene structure

<Canvas camera={{ position: [0, 1.5, 5], fov: 45 }} dpr={[1, 2]} gl={{ antialias: true, powerPreference: 'high-performance' }}>
  <Suspense fallback={<Loader />}>
    <Environment preset="city" />
    <ambientLight intensity={0.4} />
    <directionalLight position={[5, 5, 5]} intensity={1} castShadow />
    <Model url="/models/product.glb" />
    <OrbitControls enableZoom={false} enablePan={false} />
  </Suspense>
</Canvas>
  • dpr={[1, 2]} caps device pixel ratio — never let it run uncapped on high-DPI mobile screens (kills framerate).
  • Wrap async assets (useGLTF, useTexture) in <Suspense> with a real loading UI, not a blank canvas.

Loading models

  • Compress with gltf-transform/Draco before shipping (useGLTF.preload, use -draco variants).
  • Load via useGLTF(url) (drei) — never useLoader(GLTFLoader, url) directly unless you need custom loader config.
  • Preload critical models: useGLTF.preload('/models/product.glb') outside the component.

Performance rules (check every time)

  1. Instance repeated geometry (<Instances>/InstancedMesh) instead of mapping many <mesh> — one draw call vs. hundreds.
  2. Dispose properly: R3F auto-disposes on unmount for most cases, but custom geometries/materials created imperatively need manual .dispose().
  3. Limit real-time shadows: prefer baked lighting or a single shadow-casting light; castShadow on many lights is expensive.
  4. Frameloop: use frameloop="demand" on the Canvas for static/product-viewer scenes that only need to re-render on interaction, not always (60fps loop) when nothing is animating.
  5. Mobile fallback: for low-end devices, detect via a capability check (WebGL2 support, navigator.hardwareConcurrency) and serve a static image/video poster instead of the full 3D scene — never assume every visitor can run a heavy scene smoothly.
  6. Bundle size: three.js is large — dynamically import the 3D module so it doesn't block the initial page load/LCP for content that isn't 3D.

Reference files (load when relevant)

  • references/animation-and-interaction.md — useFrame patterns, GSAP/R3F integration, scroll-linked 3D, drei helpers (Html, Text3D, Scroll)
  • references/postprocessing-and-materials.md — @react-three/postprocessing effects, custom shaders/materials, physically-based lighting recipes

Anti-patterns to flag

  • Rendering <Canvas> without SSR guard in a Next.js Server Component tree
  • Uncompressed multi-MB GLTF models shipped directly
  • frameloop="always" on a scene with no continuous animation
  • No loading state / fallback while the model streams in
  • No reduced-motion / low-power fallback

Example prompt this skill should trigger on

"Add an interactive 3D product viewer to the hero section of our Next.js landing page."

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.