Index of every page on this site: llms.txt
All skills
Run it yourself

Add 3D and WebGL to websites — interactive hero objects, product viewers, particles, shader backgrounds, scroll-driven 3D scenes — with Three.js or React Three Fiber (drei), Spline, or model-viewer, while keeping load time, mobile performance and fallbacks under control. Use whenever the user mentions 3D, WebGL, Three.js, R3F, react-three-fiber, shaders, GLB/GLTF models, particles, Spline, or wants an immersive/"wow" hero.

Use this Skill: https://skilld.dev/gh/kiln-skills/kiln/web-3d

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

SKILL.md

≈110 tokens for metadata: the name and description. ≈927 when used: this file.

Description uses 5.4% of example budget

Before choosing a Skill, your Agent reads its name and description. All available Skills share that space.

  • A shorter description leaves more room for other Skills. This entry exceeds our 1% size suggestion.

In our Claude Code example, all Skill names and descriptions share 8,000 characters. This Skill uses ≈435 characters, or 5.4%.

The 1% threshold is a size suggestion. Longer descriptions can still fit.

Your model, settings, and other Skills decide how much text your Agent can read.

Example settings and source

The example uses a 200k-token context and default Claude Code settings. The count includes the name, description, separators, and when_to_use when present. Codex also counts local file paths.

Skit's source and limits: Codex 0.160.1, Claude Code 2.1.292.

Web 3D

3D is the heaviest thing on a page. Treat it as a progressive enhancement layered on a page that already works and looks good without it.

1. Pick the right tool

Need Use
Show a product model, rotate/zoom, AR <model-viewer> web component — simplest, accessible
Designer built the scene visually Spline (export as React component / embed) — fast to ship, heavier runtime
Custom interactive scene in React/Next.js React Three Fiber: npm i three @react-three/fiber @react-three/drei
Custom scene in vanilla / Vue / Astro Three.js directly (npm i three) — or TresJS for Vue
Gradient/noise background, distortion effects A single fullscreen shader plane (Three.js) or a lighter lib like OGL

2. Assets

  • Models: GLB, compressed. npx gltf-transform optimize in.glb out.glb --texture-compress webp (Draco/Meshopt geometry + compressed textures). Target < 2–3 MB for a hero, ideally < 1 MB.
  • Textures: power-of-two sizes, ≤ 2048px, WebP/KTX2.
  • Generate typed R3F components from models: npx gltfjsx model.glb --transform.
  • Bake lighting into textures when possible instead of many real-time lights/shadows.

3. Loading strategy (protect LCP)

  • The hero's text and CTA render as normal HTML first. The canvas loads after, behind them or beside them.
  • Next.js: const Scene = dynamic(() => import("./Scene"), { ssr: false }). Load when near viewport (IntersectionObserver) if not above the fold.
  • Show a poster image (a render of the scene) until the canvas is ready, then crossfade — no layout shift (fixed aspect-ratio container).
  • drei <Preload all />, useGLTF.preload(url); <Suspense fallback={…}>.

4. R3F essentials

<Canvas dpr={[1, 1.75]} camera={{ position: [0, 0, 5], fov: 45 }}
  gl={{ antialias: true, powerPreference: "high-performance" }}>
  <Suspense fallback={null}>
    <Environment preset="city" />
    <Model />
  </Suspense>
</Canvas>
  • Animate in useFrame((state, delta) => { ref.current.rotation.y += delta * 0.3 }) — mutate refs, never setState per frame.
  • Pointer interaction: use state.pointer inside useFrame and lerp toward it (THREE.MathUtils.damp) for smooth follow.
  • Scroll-linked 3D: drei ScrollControls + useScroll, or read GSAP ScrollTrigger progress into a ref that useFrame reads.
  • Reuse geometries/materials; use <Instances>/InstancedMesh for many copies (particles, grids).
  • frameloop="demand" for mostly-static scenes (render only on change) — big battery win.
  • Pause rendering when the canvas is off-screen.

5. Performance & mobile

  • Cap DPR (dpr={[1, 1.5]} on mobile). Fewer lights, no or baked shadows, lower particle counts on mobile.
  • drei <PerformanceMonitor> / AdaptiveDpr to degrade quality automatically.
  • Budget: < 100 draw calls for a hero, steady 60fps on a mid-range phone. Check with r3f-perf in development.
  • Dispose of geometries/textures/materials on unmount in vanilla Three.js (R3F does this automatically for its own objects).

6. Accessibility & fallbacks

  • Canvas is decorative → aria-hidden="true"; all meaningful content stays in HTML.
  • Interactive viewer → keyboard controls or buttons for rotate/zoom, plus a text description.
  • Reduced motion → stop auto-rotation and idle animations (static frame).
  • No WebGL / low-power device → keep the poster image. Detect failure with an error boundary around <Canvas>.
  • Don't hijack scroll or wheel on the canvas unless the scene is the whole experience.

7. Verify

Check network weight of the 3D assets, Lighthouse LCP with and without the scene, fps on throttled CPU, mobile at 375px, reduced motion, and WebGL-disabled fallback.

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts15d3 checks · Risk SAFE
  • Gen Agent Trust Hub15d

    The skill provides architectural guidance and code snippets for integrating 3D graphics (WebGL, Three.js) into websites using industry-standard tools and optimization techniques. No security risks were identified.

  • Socket15d

    No alerts

  • Snyk15d

    Risk: LOW · No issues

Signed by skilld at 555d7ea. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 weeks ago.

Activeupdated 2 weeks ago

README badge

README badge for kiln-skills/kiln/web-3d