r3f-interaction

Implements pointer events, camera controls, gestures, and selection in React Three Fiber scenes.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @react-three/fiber, @react-three/drei, @use-gesture/react, @react-spring/three, @react-three/postprocessing, three.

What problem does it solve? Building interactive 3D experiences in React requires wiring up raycasting, pointer events, camera controls, and drag gestures manually, which is error-prone and verbose without established patterns. ## Core Features & Use Cases - Pointer Events & Raycasting: Attach onClick, onPointerOver, onPointerMove, and other handlers directly to meshes with full access to intersection data like points, UVs, and face normals. - Camera & Transform Controls: Configure OrbitControls, MapControls, FlyControls, PointerLockControls, TransformControls, and PivotControls from @react-three/drei for navigation and object manipulation. - Gestures, Selection & Keyboard Input: Implement drag with @use-gesture/react, multi-select with outline postprocessing, keyboard-driven movement via KeyboardControls, and scroll-driven animation with ScrollControls. - Use Case: Build a product configurator where users click meshes to select parts, drag objects with a gizmo, orbit the camera with damping, and see selected items highlighted with an outline effect. ## Quick Start Add click and hover handlers to a mesh in my React Three Fiber scene and set up OrbitControls with damping and distance limits.

Frequently Asked Questions about r3f-interaction

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

FAQPage Schema
How do I add click events to meshes in React Three Fiber?

Attach onClick directly to the mesh element and access intersection data through the event object, including point, distance, face, and uv coordinates. Call event.stopPropagation() to prevent the click from reaching objects behind it.

How to implement drag and drop for 3D objects in React?

Use useDrag from @use-gesture/react combined with @react-spring/three to animate position during dragging, or use DragControls from @react-three/drei. Disable OrbitControls during drag by toggling its enabled property on drag start and end.

What camera controls does @react-three/drei provide?

Drei provides OrbitControls, MapControls, FlyControls, FirstPersonControls, PointerLockControls, TrackballControls, ArcballControls, and CameraControls. OrbitControls with enableDamping covers most orbit, zoom, and pan needs, while CameraControls supports smooth programmatic transitions.

How do I highlight selected objects with an outline in React Three Fiber?

Use the Selection, Select, EffectComposer, and Outline components from @react-three/postprocessing. Wrap selectable meshes in Select with an enabled prop tied to your selection state, and the Outline effect renders a glowing edge around selected items.

Why are my pointer events firing on hidden objects in R3F?

Raycasting hits every object along the ray by default, including ones behind your target. Call event.stopPropagation() in handlers, disable raycasting on decorative meshes with raycast={() => null}, or use layers to filter raycast targets.

How do I handle keyboard input for moving objects in a 3D scene?

Wrap your Canvas in KeyboardControls from drei with a key map, then call useKeyboardControls inside a component and read pressed keys each frame with useFrame. This supports bindings like WASD, arrows, and space for movement logic.