agentleFS
jwuthri-cloudjwuthri-cloud/Tracely-ai/.agents/skills/threejs-r3f/SKILL.md

threejs-r3f

Skill1.2k starsChanged 20 days agoMITView on GitHub

Three.js and React Three Fiber sub-skill - 3D scenes, shaders, postprocessing.

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    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:

    Always wrap scene content in <Suspense> -- loaders (GLTF, textures, HDRI) need it

    line 42
  2. Distinctive:

    Keep the Canvas parent component minimal -- re-renders propagate into the scene

    line 44
  3. Very specific:

    Use stats-gl or r3f-perf to monitor.

    line 129

≈ “Common” is an estimate: at least 1 in 5 of the 308,232 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

Three.js & React Three Fiber

3D on the web. Three.js is the engine, R3F is the React renderer. Concise rules here. Deep-dive in references/.


When to Use What

NeedToolWhy
Full 3D scene (models, lights, physics)R3F + dreiDeclarative, React-friendly, ecosystem
Vanilla 3D (no React)Three.js directLighter, no React overhead
Simple 3D transforms on UICSS transform3dGPU-composited, no WebGL context
2D particles / generativeCanvas 2DSimpler API, less GPU overhead
Shader-only visuals (no scene graph)Raw WebGL / ShaderMaterialMaximum control, minimal abstraction

Scene Setup Patterns

import { Canvas } from '@react-three/fiber'
import { Environment, OrbitControls } from '@react-three/drei'
import { Suspense } from 'react'

<Canvas camera={{ position: [0, 2, 5], fov: 45 }} dpr={[1, 2]} gl={{ antialias: true }}>
  <Suspense fallback={null}>
    <Environment preset="studio" />
    <OrbitControls makeDefault />
    <Scene />
  </Suspense>
</Canvas>

Rules:

  • Always wrap scene content in <Suspense> -- loaders (GLTF, textures, HDRI) need it
  • Set dpr={[1, 2]} to clamp pixel ratio (Retina without melting GPUs)
  • Keep the Canvas parent component minimal -- re-renders propagate into the scene

R3F Hooks

HookPurposeGotcha
useFrame((state, delta) => {})Per-frame logic (animation, physics)Never setState inside
useThree()Access gl, scene, camera, size, viewport, pointerDestructure only what you need
useLoader(TextureLoader, url)Load any Three.js resourceWrap parent in Suspense
useGraph(scene)Extract nodes/materials from loaded sceneUseful after useGLTF

useFrame Tips

useFrame((state, delta) => {
  // Use delta for framerate-independent animation
  meshRef.current.rotation.y += delta * 0.5
  // Access clock for time-based effects
  material.uniforms.uTime.value = state.clock.elapsedTime
})

Drei Essentials

ComponentUse Case
EnvironmentHDRI lighting (presets: studio, sunset, city, forest, dawn)
FloatIdle floating animation (speed, rotationIntensity, floatIntensity)
Text3DExtruded 3D text (needs JSON font from Facetype.js)
useGLTFLoad .glb/.gltf models (returns { nodes, materials, scene })
useGLTF.preload(url)Preload model before component mounts
MeshTransmissionMaterialGlass/crystal/liquid refraction effects
PresentationControlsDrag-to-rotate for product showcases
CenterAuto-center any group of meshes
DetailedLOD -- swap geometry by camera distance
useTextureLoad textures with Suspense support
InstancesDeclarative instancing for repeated meshes

Postprocessing

import { EffectComposer, Bloom, ChromaticAberration } from '@react-three/postprocessing'
import { BlendFunction } from 'postprocessing'

<EffectComposer>
  <Bloom
    luminanceThreshold={1}
    luminanceSmoothing={0.4}
    intensity={0.6}
  />
  <ChromaticAberration
    blendFunction={BlendFunction.NORMAL}
    offset={[0.002, 0.002]}
  />
</EffectComposer>

Rules:

  • Bloom is selective by default -- lift material color/emissive above 1.0 to make it glow
  • luminanceThreshold={1} = nothing glows unless explicitly emissive
  • Order matters inside EffectComposer
  • Effects are merged into a single pass (performant by design)

Performance Patterns

PatternWhen
<Instances> / InstancedMesh100+ identical meshes (particles, trees, crowds)
<Detailed distances={[0, 50, 100]}>LOD: swap hi/lo models by distance
dispose={null} on <primitive>Prevent auto-dispose when reusing shared geometry
useGLTF + DracoCompress .glb models (70-90% size reduction)
useTexture + KTX2Compressed GPU textures (1/4 VRAM)
frameloop="demand" on CanvasOnly render when something changes (static scenes)
invalidate() from useThreeTrigger a render in demand mode
Offscreen canvas (<Canvas eventSource={...}>)Run rendering off main thread

Target metrics: < 100 draw calls, < 1M triangles, 60fps on mid-range GPU. Use stats-gl or r3f-perf to monitor.


Do Not

1. Never setState in useFrame

Causes full React re-render 60x/second. Mutate refs directly.

// BAD
useFrame(() => {
  setRotation(prev => prev + 0.01) // React re-render every frame
})

// GOOD
useFrame((_, delta) => {
  meshRef.current.rotation.y += delta * 0.5 // Direct mutation, zero re-renders
})

2. Never allocate in the render loop

new Vector3() per frame = GC spikes = stutter.

// BAD
useFrame((state) => {
  const target = new THREE.Vector3(0, Math.sin(state.clock.elapsedTime), 0)
  meshRef.current.position.copy(target)
})

// GOOD
const _target = useMemo(() => new THREE.Vector3(), [])
useFrame((state) => {
  _target.set(0, Math.sin(state.clock.elapsedTime), 0)
  meshRef.current.position.copy(_target)
})

3. Never forget dispose (memory leak)

Three.js textures, geometries, and materials live on the GPU. Unmounting a React component does NOT free them.

// BAD -- texture stays in VRAM after unmount
const texture = useLoader(TextureLoader, '/big-texture.jpg')

// GOOD -- R3F auto-disposes when using JSX primitives
// For manual resources, dispose in cleanup:
useEffect(() => {
  return () => {
    texture.dispose()
    geometry.dispose()
    material.dispose()
  }
}, [])

4. Never re-render the Canvas parent

State changes in the parent force the entire Canvas to remount = flash, lost state, reloaded assets.

// BAD
function App() {
  const [uiState, setUiState] = useState(false) // re-renders remount Canvas
  return (
    <>
      <button onClick={() => setUiState(!uiState)}>Toggle</button>
      <Canvas><Scene config={uiState} /></Canvas>
    </>
  )
}

// GOOD -- isolate Canvas in its own component
function App() {
  return (
    <>
      <UI />
      <SceneCanvas />
    </>
  )
}

5. Never load assets without Suspense

Loaders (useGLTF, useTexture, useLoader) throw promises. Without Suspense, you get crashes.

// BAD
<Canvas>
  <Model /> {/* useGLTF inside -- will throw */}
</Canvas>

// GOOD
<Canvas>
  <Suspense fallback={<Loader />}>
    <Model />
  </Suspense>
</Canvas>

Quick Reference: Loading Sub-resources

NeedLoad
Scene boilerplate, lighting rigs, controlsreferences/scene-setup.md
Custom shaders, GLSL patterns, uniformsreferences/shaders.md
Animation principles, easing, timing../motion-principles/SKILL.md
GSAP + Three.js integration../gsap/SKILL.md

Download now (ZIP)

Trending

More talk lately.thin dataabout the whole repository

Dec 2025: 0 mentionsJan 2026: 0 mentionsFeb 2026: 0 mentionsMar 2026: 0 mentionsApr 2026: 0 mentionsMay 2026: 0 mentionsJun 2026: 0 mentionsJul 2026: 0 mentionsAug 2026: 0 mentionsSep 2026: 0 mentionsOct 2026: 1 mentionNov 2026: 0 mentions
Dec 2025Jun 2026Nov 2026
Mentions a month of the jwuthri-cloud/Tracely-ai repository that our weekly crawl found: only 1 in all, so this is a hint, not a trend. There is no adoption data for this file yet.

Who's talking about jwuthri-cloud/Tracely-ai

The biggest 1 of 1 mention linking to the repository that our crawl found. Each line is their own headline.

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.