Three.js 3D 网页体验开发
3d-web-experience
使用 Three.js、React Three Fiber、Spline 和 WebGL 构建沉浸式 3D 网页体验。涵盖产品配置器、3D 作品集、滚动驱动的 3D、模型管线优化、性能预算和交互场景。在构建 3D 网站、three.js 场景或 WebGL 体验时使用。
- License 许可
- MIT
- 最近更新
- 2026-09-14
- Stars
- ★ 68
- Forks
- 15
01 前言 Front Matter
- name
- 3d-web-experience
- description
- Build immersive 3D web experiences with Three.js, React Three Fiber, Spline, and WebGL. Covers product configurators, 3D portfolios, scroll-driven 3D, model pipeline optimization, performance budgets, and interactive scenes. Use when building 3D websites, three.js scenes, or WebGL experiences.
02 资源文件 2
- 参考文档references/benchmarks.md4.5 KB
- 参考文档references/format-guide.md5.7 KB
03 SKILL.md 正文
3D Web Experience
Role: 3D Web Experience Architect — bringing depth to the web with purpose and performance.
Stack Selection
| Tool | Best For | Learning Curve | Control |
|---|---|---|---|
| Spline | Quick prototypes, designer handoff | Low | Medium |
| React Three Fiber | React apps, complex scenes | Medium | High |
| Three.js vanilla | Max control, non-React projects | High | Maximum |
| Babylon.js | Game-like experiences, heavy 3D | High | Maximum |
Decision Tree
Quick 3D element needed? → Spline
Using React? → React Three Fiber (R3F)
Need max performance/control? → Three.js vanilla
Building a game? → Babylon.js
React Three Fiber Setup
import { Canvas } from "@react-three/fiber";
import { OrbitControls, Environment, useGLTF, Float } from "@react-three/drei";
import { Suspense } from "react";
function Model({ url }: { url: string }) {
const { scene } = useGLTF(url);
return <primitive object={scene} scale={1} />;
}
function LoadingFallback() {
return (
<mesh>
<boxGeometry args={[1, 1, 1]} />
<meshStandardMaterial color="#8b5cf6" wireframe />
</mesh>
);
}
export default function Scene() {
return (
<Canvas camera={{ position: [0, 2, 5], fov: 45 }} dpr={[1, 2]}>
<ambientLight intensity={0.5} />
<directionalLight position={[5, 5, 5]} intensity={1} castShadow />
<Suspense fallback={<LoadingFallback />}>
<Float speed={2} rotationIntensity={0.5} floatIntensity={0.5}>
<Model url="/model.glb" />
</Float>
<Environment preset="city" />
</Suspense>
<OrbitControls enableDamping dampingFactor={0.05} />
</Canvas>
);
}
3D Model Pipeline
Optimization Steps
1. Model in Blender/3D software
2. Reduce polygon count (< 100K for web, < 50K for mobile)
3. Bake textures (combine materials, reduce draw calls)
4. Export as GLB (binary GLTF — smallest size)
5. Compress: gltf-transform optimize input.glb output.glb --compress draco --texture-compress webp
6. Target: < 5MB total, < 2MB for mobile
Loading with Progress
import { useGLTF, useProgress, Html } from "@react-three/drei";
function Loader() {
const { progress } = useProgress();
return (
<Html center>
<div style={{ color: "white", fontSize: "1.5rem" }}>
{progress.toFixed(0)}%
</div>
</Html>
);
}
Scroll-Driven 3D
R3F + ScrollControls
import { ScrollControls, useScroll } from "@react-three/drei";
import { useFrame } from "@react-three/fiber";
import { useRef } from "react";
function ScrollModel() {
const scroll = useScroll();
const ref = useRef<THREE.Group>(null);
useFrame(() => {
if (!ref.current) return;
ref.current.rotation.y = scroll.offset * Math.PI * 2;
ref.current.position.y = Math.sin(scroll.offset * Math.PI) * 2;
});
return <group ref={ref}><Model url="/model.glb" /></group>;
}
export default function ScrollScene() {
return (
<Canvas style={{ height: "100vh", position: "fixed", top: 0 }}>
<ScrollControls pages={3} damping={0.25}>
<ScrollModel />
</ScrollControls>
</Canvas>
);
}
GSAP + Three.js (vanilla)
import gsap from "gsap";
import ScrollTrigger from "gsap/ScrollTrigger";
gsap.registerPlugin(ScrollTrigger);
gsap.to(camera.position, {
scrollTrigger: { trigger: ".hero-section", start: "top top", end: "bottom top", scrub: 1 },
z: 5, y: 2, duration: 1,
});
Performance Budget
| Metric | Target | Measurement |
|---|---|---|
| Model file size | < 5MB | gzip compressed |
| Draw calls | < 50 | Three.js stats panel |
| Triangles | < 100K | GPU budget |
| Textures | < 2048px | Power of 2 dimensions |
| FPS | 60fps desktop, 30fps mobile | requestAnimationFrame |
| Load time | < 3s on 4G | Lighthouse |
Anti-Patterns
- 3D for 3D's sake — If an image works, use an image. 3D must serve a purpose.
- Desktop-only 3D — Test on real mobile devices. Provide static fallbacks.
- No loading state — Always show progress. Load 3D after page is interactive.
- Uncompressed models — Always run through gltf-transform pipeline.
- No
Suspenseboundaries — Wrap 3D content for graceful loading.
04 同仓库更多 Skills
演示测试技能
demo-skill
用于测试的演示插件技能。
智能体技能开发
write-a-skill
创建新的智能体技能,具备合理的结构、渐进式披露(progressive disclosure)机制和配套捆绑资源。当用户想要创建、编写或构建新技能时使用。
网络调研与数据提取
web-research
深度网络研究与数据提取技能。通过获取 URL、阅读文档、爬取 API 文档、评估 npm/pypi 包、比较技术,并将研究发现综合为可操作的建议,系统地研究任意主题。适用于研究库、框架、API、解决方案,或任何需要网络调查的主题。
自动化测试套件设计与实现
testing
设计并实现全面的测试套件。涵盖单元测试、集成测试、使用 Playwright 的 E2E 测试、API 测试、mock 策略、测试数据工厂、TDD 工作流、快照测试、覆盖率目标以及 CI 集成。适用于编写测试、设计测试架构或排查测试失败。
工程开发工作流与质量规范
superpowers
核心工程工作流,在每一项任务中都会激活。强制执行系统化的“先计划后编码”方法论、多文件重构安全、依赖感知的变更、预检验证以及零占位符质量标准。在所有编码任务中主动(PROACTIVELY)使用。
CSS样式系统设计与实现
styling
使用 Tailwind CSS、原生 CSS 或 CSS-in-JS 实现生产级样式系统。涵盖 CSS 架构(BEM、utility-first、模块化)、设计令牌、响应式模式、动画系统、暗黑模式、容器查询、打印样式以及性能优化。适用于实现设计或构建 CSS 架构。