一键导入
frontend-three-fiber-drei
Use when working with React Three Fiber, drei components, 3D scenes, camera management, or coordinate systems (Y-up)
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Use when working with React Three Fiber, drei components, 3D scenes, camera management, or coordinate systems (Y-up)
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Use when deploying Cloudflare Workers, managing R2 storage, or working with Cloudflare infrastructure
Use when working with ANTD components, theme tokens, icons, forms, or feedback components (message/notification/modal)
Use when adding, referencing, or serving static assets (images, fonts, videos, 3D models) through the R2 CDN pipeline with type-safe imports
Use when writing or reviewing JavaScript/TypeScript code for style patterns like concise arrows, inline handlers, expression formatting, or when tempted to use eslint-disable
Use when working with environment variables in frontend code
Use when creating or modifying keyboard shortcuts/hotkeys in frontend code
| name | frontend-three-fiber-drei |
| description | Use when working with React Three Fiber, drei components, 3D scenes, camera management, or coordinate systems (Y-up) |
Guidelines for working with 3D scenes using React Three Fiber (@react-three/fiber) and drei (@react-three/drei).
CRITICAL: This project uses Y-up coordinate system (Three.js default)
| Axis | Direction | Usage |
|---|---|---|
| +X | Right | Strafe right |
| +Y | Up | Vertical movement |
| +Z | Forward (towards camera) | Movement away from camera |
| -Z | Into screen | Movement towards target |
<Canvas
camera={{
position: [-10, 10, 10], // Y is height
up: [0, 1, 0], // Y-up
fov: 75,
}}
>
| Term | Axis | Description |
|---|---|---|
| Yaw | Around Y | Horizontal look (left/right) |
| Pitch | Around X | Vertical look (up/down) |
| Forward | -Z | Direction camera faces |
| Right | +X | Camera's right side |
| Up | +Y | World up direction |
// Calculate look direction from yaw/pitch (Y-up)
const lookDir = new THREE.Vector3(
-Math.sin(yaw) * Math.cos(pitch),
Math.sin(pitch),
-Math.cos(yaw) * Math.cos(pitch)
);
camera.up.set(0, 1, 0);
camera.lookAt(camera.position.clone().add(lookDir));
// Forward/Right in XZ plane, Up along Y
const forward = new THREE.Vector3(-Math.sin(yaw), 0, -Math.cos(yaw));
const right = new THREE.Vector3(Math.cos(yaw), 0, -Math.sin(yaw));
const up = new THREE.Vector3(0, 1, 0);
CRITICAL: Switching cameras with drei's makeDefault has state isolation issues.
// This pattern causes problems for camera state restoration:
<Canvas camera={{ position: [...] }}> {/* PerspectiveCamera */}
{isOrthographic && (
<OrthographicCamera makeDefault position={...} />
)}
<CustomFlyControls />
</Canvas>
Problem: useThree().camera returns the currently active camera. State (position, refs) set on one camera doesn't transfer to the other when switching.
Symptoms:
getCameraState() returns wrong camera's statesetCameraState() applies to wrong cameraKnown failed approaches:
Workarounds:
| Feature | Custom FlyControls | drei CameraControls |
|---|---|---|
| WASD Movement | ✅ Yes | ❌ No |
| Mouse Look FPS | ✅ Yes | ❌ No (orbit only) |
| ALT + Orbit | ✅ Yes | ✅ Yes (default) |
| Q/E Vertical | ✅ Yes | ❌ No |
| saveState/restoreState | ❌ No | ✅ Yes |
Choose FlyControls for FPS-style navigation. Choose CameraControls for orbit-style with state management.
| File | Purpose |
|---|---|
components/Fiber/Fiber_Canvas/Fiber_Canvas.tsx | Base canvas wrapper with camera config |
components/Fiber/Fiber_Canvas/Fiber_Canvas_FlyControls/ | WASD + mouse look + orbit controls |
components/Fiber/Fiber_PLY/Fiber_PLY.tsx | Gaussian splat (.ply) loading |
components/Fiber/Fiber_USD/Fiber_USD.tsx | USD model loading |
<Grid
args={[100, 100]}
position={[0, 0, 0]}
rotation={[0, 0, 0]} // No rotation for Y-up
/>
const plane = new THREE.Plane(new THREE.Vector3(0, 1, 0), 0);
const intersectionPoint = new THREE.Vector3();
raycaster.ray.intersectPlane(plane, intersectionPoint);
// Calculate yaw/pitch to look at origin from camera position
const calculateInitialAngles = (pos: [number, number, number]) => {
const [x, y, z] = pos;
const yaw = Math.atan2(x, z);
const pitch = -Math.atan2(y, Math.sqrt(x * x + z * z));
return { yaw, pitch };
};
| Wrong (Z-up) | Correct (Y-up) |
|---|---|
up: [0, 0, 1] | up: [0, 1, 0] |
camera.up.set(0, 0, 1) | camera.up.set(0, 1, 0) |
new THREE.Plane(new THREE.Vector3(0, 0, 1), 0) | new THREE.Plane(new THREE.Vector3(0, 1, 0), 0) |
position.z for height | position.y for height |
rotation={[-Math.PI / 2, 0, 0]} for grid | rotation={[0, 0, 0]} for grid |