---
name: 3d-web-experience
description: 精通构建网页 3D 体验——Three.js、React
Three Fiber、Spline、WebGL 以及交互式 3D 场景。涵盖产品配置器、3D 作品集、沉浸式网站,以及为网页体验增添层次感。
risk: critical
source: vibeship-spawner-skills (Apache 2.0)
date_added: 2026-02-27
---
# 3D 网页体验
精通构建网页 3D 体验——Three.js、React Three Fiber、
Spline、WebGL 以及交互式 3D 场景。涵盖产品配置器、3D
作品集、沉浸式网站,以及为网页体验增添层次感。
**角色**:3D 网页体验架构师
你为网页带来第三个维度。你清楚 3D 何时能提升体验,何时只是炫技。你在视觉冲击力与性能之间取得平衡。你让从未接触过 3D 应用的用户也能轻松使用 3D。你在不牺牲可用性的前提下,创造令人惊叹的时刻。
### 专业领域
- Three.js
- React Three Fiber
- Spline
- WebGL
- GLSL shaders
- 3D 优化
- 模型准备
## 能力
- Three.js 实现
- React Three Fiber
- WebGL 优化
- 3D 模型集成
- Spline 工作流
- 3D 产品配置器
- 交互式 3D 场景
- 3D 性能优化
## 模式
### 3D 技术栈选择
选择合适的 3D 方案
**何时使用**:启动 3D 网页项目时
## 3D 技术栈选择
### 方案对比
| 工具 | 最适合 | 学习曲线 | 控制力 |
|------|----------|----------------|---------|
| Spline | 快速原型、设计师 | 低 | 中 |
| React Three Fiber | React 应用、复杂场景 | 中 | 高 |
| Three.js vanilla | 最大控制力、非 React | 高 | 最大 |
| Babylon.js | 游戏、重度 3D | 高 | 最大 |
### 决策树
```
Need quick 3D element?
└── Yes → Spline
└── No → Continue
Using React?
└── Yes → React Three Fiber
└── No → Continue
Need max performance/control?
└── Yes → Three.js vanilla
└── No → Spline or R3F
```
### Spline(最快上手)
```jsx
import Spline from '@splinetool/react-spline';
export default function Scene() {
return (
);
}
```
### React Three Fiber
```jsx
import { Canvas } from '@react-three/fiber';
import { OrbitControls, useGLTF } from '@react-three/drei';
function Model() {
const { scene } = useGLTF('/model.glb');
return ;
}
export default function Scene() {
return (
);
}
```
### 3D 模型管线
让模型达到可上线网页的状态
**何时使用**:准备 3D 资源时
## 3D 模型管线
### 格式选择
| 格式 | 使用场景 | 大小 |
|--------|----------|------|
| GLB/GLTF | 标准网页 3D | 最小 |
| FBX | 来自 3D 软件 | 大 |
| OBJ | 简单网格 | 中 |
| USDZ | Apple AR | 中 |
### 优化管线
```
1. Model in Blender/etc
2. Reduce poly count (< 100K for web)
3. Bake textures (combine materials)
4. Export as GLB
5. Compress with gltf-transform
6. Test file size (< 5MB ideal)
```
### GLTF 压缩
```bash
# Install gltf-transform
npm install -g @gltf-transform/cli
# Compress model
gltf-transform optimize input.glb output.glb \
--compress draco \
--texture-compress webp
```
### 在 R3F 中加载
```jsx
import { useGLTF, useProgress, Html } from '@react-three/drei';
import { Suspense } from 'react';
function Loader() {
const { progress } = useProgress();
return {progress.toFixed(0)}%;
}
export default function Scene() {
return (
);
}
```
### 滚动驱动的 3D
响应滚动的 3D
**何时使用**:将 3D 与滚动结合时
## 滚动驱动的 3D
### R3F + Scroll Controls
```jsx
import { ScrollControls, useScroll } from '@react-three/drei';
import { useFrame } from '@react-three/fiber';
function RotatingModel() {
const scroll = useScroll();
const ref = useRef();
useFrame(() => {
// 根据滚动位置旋转
ref.current.rotation.y = scroll.offset * Math.PI * 2;
});
return ...;
}
export default function Scene() {
return (
);
}
```
### GSAP + Three.js
```javascript
import gsap from 'gsap';
import ScrollTrigger from 'gsap/ScrollTrigger';
gsap.to(camera.position, {
scrollTrigger: {
trigger: '.section',
scrub: true,
},
z: 5,
y: 2,
});
```
### 常见滚动效果
- 摄像机穿越场景的移动
- 滚动时模型旋转
- 显示/隐藏元素
- 颜色/材质变化
- 爆炸视图动画
### 性能优化
保持 3D 流畅
**何时使用**:始终——3D 开销很大
## 3D 性能
### 性能目标
| 设备 | 目标 FPS | 最大三角面数 |
|--------|------------|---------------|
| 桌面端 | 60fps | 500K |
| 移动端 | 30-60fps | 100K |
| 低端设备 | 30fps | 50K |
### 快速见效的做法
```jsx
// 1. 对重复对象使用实例化
import { Instances, Instance } from '@react-three/drei';
// 2. 限制灯光数量
// 只用一个
// 3. 使用 LOD(细节层次)
import { LOD } from 'three';
// 4. 懒加载模型
const Model = lazy(() => import('./Model'));
```
### 移动端检测
```jsx
const isMobile = /iPhone|iPad|Android/i.test(navigator.userAgent);