r3f-fundamentals

Implements React Three Fiber scenes using Canvas, hooks, JSX elements, and event handling.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @react-three/fiber, three, leva.

What problem does it solve? Building 3D scenes in React with Three.js requires bridging imperative WebGL APIs with declarative React patterns, which is error-prone without clear guidance on Canvas setup, render loops, and event handling. ## Core Features & Use Cases - Canvas and Render Loop Setup: Configure the Canvas component with camera, renderer, shadows, and frameloop options, and drive animations with useFrame including priority control. - State Access and JSX Elements: Use useThree for selective state subscriptions, declare Three.js objects as JSX with nested props, attach semantics, and the extend function for custom classes. - Events, Refs, and Debugging: Handle pointer events with propagation control, access Three.js objects imperatively via refs, apply performance patterns, and tune parameters live with Leva controls. - Use Case: When building an interactive product configurator, use this Skill to scaffold a Canvas with shadows, animate a rotating mesh with useFrame, and add click/hover handlers that change materials. ## Quick Start Create a React Three Fiber scene with a Canvas containing a rotating box mesh animated via useFrame and lit by ambient and directional lights.

Frequently Asked Questions about r3f-fundamentals

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

FAQPage Schema
How do I animate objects in React Three Fiber?

Use the useFrame hook, which runs a callback every frame with state and delta time arguments. Mutate object properties via refs, such as meshRef.current.rotation.y += delta, to animate without triggering React re-renders.

How to access the Three.js camera and renderer in R3F?

Use the useThree hook with a selector, like useThree((state) => state.camera), to subscribe to specific state slices. Available state includes gl (renderer), scene, camera, pointer, clock, size, and viewport.

Does React Three Fiber support click and hover events on 3D objects?

Yes, R3F provides React-style events on meshes including onClick, onPointerOver, onPointerOut, and onPointerMove. Event objects expose intersection data like point, distance, face, and uv, and support stopPropagation for bubbling control.

How do I use custom Three.js classes like OrbitControls in R3F?

Call extend({ OrbitControls }) once at module level, then use the lowercase JSX element with args for constructor parameters. For TypeScript, declare the element in the JSX.IntrinsicElements interface.

Why does my R3F app re-render too often and hurt performance?

Re-renders happen when new arrays or objects are passed as props each render or when useThree subscribes to the full state. Fix this by mutating refs inside useFrame, memoizing props with useMemo, and using selective state subscriptions.

How do I add a debug GUI to tweak R3F scene parameters?

Install leva and use the useControls hook to bind sliders, colors, and booleans to scene properties. It supports folders, buttons for actions, monitors for read-only values, and can be hidden in production via the Leva component's hidden prop.