threejs-impl-react-three-fiber

Implements declarative 3D scenes in React using React Three Fiber hooks and JSX mapping.

1|Updated Aug 20, 2023
One-click install
npx skills add https://github.com/imanlangaran/mini-projects --skill threejs-impl-react-three-fiber-imanlangaran
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: threejs-impl-react-three-fiber
Source: https://github.com/imanlangaran/mini-projects/tree/main/react/three-gsap/.claude/skills/threejs-impl-react-three-fiber
Command: npx skills add https://github.com/imanlangaran/mini-projects --skill threejs-impl-react-three-fiber-imanlangaran

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @react-three/fiber, three, react, and includes references (resource) components.

What problem does it solve? Building 3D scenes in React with React Three Fiber often leads to subtle bugs: mixing imperative Three.js code with R3F's declarative model, allocating objects inside useFrame, forgetting Suspense boundaries for loaders, and causing unnecessary re-renders. This Skill provides the correct patterns, API references, and anti-patterns to avoid these mistakes. ## Core Features & Use Cases - Complete API Reference: Covers Canvas props, useFrame, useThree, useLoader, useGraph, extend(), createPortal, and the full pointer event system with TypeScript signatures. - Anti-Pattern Catalog: Documents eight common mistakes (object creation in useFrame, missing Suspense, selector-less useThree, imperative scene.add, primitive duplication, disposal of shared resources, hardcoded timesteps, missing invalidate calls) with wrong/correct code pairs. - Working Examples: Provides verified code for animated meshes, GLTF loading with Suspense, demand-mode rendering, custom controls via extend(), and portal-based minimaps. - Use Case: When building a product configurator with a 3D model viewer in React, use this Skill to correctly load GLTF assets, wire up OrbitControls, and use frameloop="demand" with invalidate() to avoid wasting GPU cycles on a static scene. ## Quick Start Use the threejs-impl-react-three-fiber skill to build a React Three Fiber scene with a spinning box and a loaded GLTF model wrapped in Suspense.

Frequently Asked Questions about threejs-impl-react-three-fiber

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I use Three.js with React using React Three Fiber?

Wrap your scene in the Canvas component from @react-three/fiber and declare Three.js objects as lowercase JSX elements like <mesh>, <boxGeometry>, and <meshStandardMaterial>. R3F maps JSX to Three.js constructors, handles attachment, and disposes objects on unmount automatically.

How do I load a GLTF model in React Three Fiber?

Use useLoader with GLTFLoader and wrap the component in a <Suspense> boundary, since useLoader suspends while loading. You can call useLoader.preload at module scope to start fetching before mount, then render the result with <primitive object={gltf.scene} />.

Why does my React Three Fiber app re-render every frame?

Calling useThree() without a selector subscribes to the entire RootState, which changes every frame. Use a selector like useThree((state) => state.camera) so the component only re-renders when that specific value changes.

Does React Three Fiber work with React 18?

Yes, @react-three/fiber 8.x is designed for React 18 and uses its concurrent features including Suspense for asset loading. The Canvas component manages the render loop, camera, and raycasting independently of the React DOM tree.

Why is my animation speed different on high-refresh monitors in R3F?

Incrementing values by a fixed amount inside useFrame ties animation speed to frame rate. Multiply increments by the delta parameter from useFrame's callback so motion is time-based and consistent across 30fps and 144Hz displays.

When should I use frameloop demand in React Three Fiber?

Use frameloop="demand" for static scenes like dashboards or configurators that do not animate continuously, since it stops the render loop and saves GPU cycles. After any visual mutation you must call invalidate() from useThree to request a new frame.