asset-pipeline-3d
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese3D Asset Pipeline
3D资产处理流程
Prepare and optimize 3D assets for performant web delivery.
Tool Versions (2026)
- gltf-transform: v4+
- Meshoptimizer: v0.21+
- Basis Universal: v1.16+
- Blender: 4.2+
为高性能Web交付准备并优化3D资产。
工具版本(2026)
- gltf-transform: v4+
- Meshoptimizer: v0.21+
- Basis Universal: v1.16+
- Blender: 4.2+
Decision Frameworks
决策框架
When to Use Which Compression
何时使用哪种压缩方式
Geometry Compression:
├─ Need fastest decode time? → Meshopt (recommended)
├─ Need smallest file size? → Draco (10-20% smaller)
├─ Animated models (skinned/morphs)? → Meshopt (better animation support)
├─ Static meshes only? → Either works
└─ Maximum compatibility? → No compression (larger files)
Texture Compression:
├─ GPU-compressed (fastest rendering)? → KTX2/Basis Universal
├─ Good balance (size vs quality)? → WebP
├─ Best quality at cost of size? → PNG (lossless) or AVIF
├─ Need alpha channel? → WebP, PNG, KTX2, or AVIF
└─ Photo textures, no alpha? → JPEG or WebP几何体压缩:
├─ 需要最快解码速度? → Meshopt (推荐)
├─ 需要最小文件体积? → Draco (小10-20%)
├─ 带动画的模型(蒙皮/变形)? → Meshopt (更好的动画支持)
├─ 仅静态模型? → 两者均可
└─ 最大兼容性? → 不压缩(文件更大)
纹理压缩:
├─ GPU压缩(最快渲染)? → KTX2/Basis Universal
├─ 平衡体积与质量? → WebP
├─ 最佳质量(牺牲体积)? → PNG(无损)或AVIF
├─ 需要透明通道? → WebP、PNG、KTX2或AVIF
└─ 照片纹理,无透明通道? → JPEG或WebPWhen to Use Which Pipeline
何时使用哪种处理流程
Single hero model (product viewer)?
→ gltf-transform optimize with high quality settings
Many similar models (e-commerce)?
→ Batch processing script with consistent settings
Game assets (performance critical)?
→ Aggressive compression + LODs + texture atlases
Architectural visualization?
→ High poly + baked lighting + KTX2 textures
Real-time application?
→ Meshopt + KTX2 + LODs + strict budgets单个核心模型(产品查看器)?
→ 使用高质量设置的gltf-transform optimize
多个相似模型(电商场景)?
→ 使用统一设置的批量处理脚本
游戏资产(性能要求严格)?
→ 激进压缩 + LOD + 纹理图集
建筑可视化?
→ 高多边形 + 烘焙光照 + KTX2纹理
实时应用?
→ Meshopt + KTX2 + LOD + 严格性能预算Compression Decision Matrix
压缩决策矩阵
| Scenario | Geometry | Textures | LODs |
|---|---|---|---|
| Product viewer | Meshopt | WebP/KTX2 | Optional |
| Game assets | Meshopt | KTX2 | Required |
| Archviz | Meshopt | KTX2 2048px | Per-room |
| Mobile | Meshopt | KTX2 512-1024px | Required |
| E-commerce batch | Draco (smaller) | WebP | Optional |
| 场景 | 几何体 | 纹理 | LOD |
|---|---|---|---|
| 产品查看器 | Meshopt | WebP/KTX2 | 可选 |
| 游戏资产 | Meshopt | KTX2 | 必填 |
| 建筑可视化 | Meshopt | KTX2 2048px | 按房间设置 |
| 移动端 | Meshopt | KTX2 512-1024px | 必填 |
| 电商批量处理 | Draco(体积更小) | WebP | 可选 |
GLTF/GLB Overview
GLTF/GLB 概述
GLTF (GL Transmission Format) is the standard for web 3D. GLB is the binary version (single file).
GLTF supports:
- Meshes, materials (PBR), textures
- Skeletal animations, morph targets
- Scene hierarchy, cameras, lights
- Extensions for advanced features
File structure:
- - JSON with external binary/textures
.gltf - - Single binary file (preferred for web)
.glb
GLTF(GL传输格式)是Web 3D的标准格式。GLB是其二进制版本(单文件)。
GLTF支持:
- 网格、材质(PBR)、纹理
- 骨骼动画、变形目标
- 场景层级、相机、灯光
- 用于高级功能的扩展
文件结构:
- - 包含外部二进制/纹理的JSON文件
.gltf - - 单二进制文件(Web场景首选)
.glb
Compression Tools
压缩工具
gltf-transform (Recommended)
gltf-transform(推荐)
Node.js CLI for GLTF optimization. Install:
npm install -g @gltf-transform/clibash
undefined用于GLTF优化的Node.js CLI工具。安装:
npm install -g @gltf-transform/clibash
undefinedMeshopt compression (recommended - faster decode)
Meshopt压缩(推荐 - 解码更快)
gltf-transform meshopt input.glb output.glb
gltf-transform meshopt input.glb output.glb
Draco compression (smaller files, slower decode)
Draco压缩(体积更小,解码更慢)
gltf-transform draco input.glb output.glb
gltf-transform draco input.glb output.glb
Texture compression to KTX2/Basis (GPU-compressed)
纹理压缩为KTX2/Basis(GPU压缩)
gltf-transform ktx input.glb output.glb --compress uastc
gltf-transform ktx input.glb output.glb --compress uastc
Full optimization pipeline (2026 recommended)
完整优化流程(2026推荐)
gltf-transform optimize input.glb output.glb
--compress meshopt
--texture-compress ktx2
--compress meshopt
--texture-compress ktx2
gltf-transform optimize input.glb output.glb
--compress meshopt
--texture-compress ktx2
--compress meshopt
--texture-compress ktx2
WebP textures (good balance, wider support)
WebP纹理(平衡体积与质量,支持更广)
gltf-transform optimize input.glb output.glb
--compress meshopt
--texture-compress webp
--compress meshopt
--texture-compress webp
gltf-transform optimize input.glb output.glb
--compress meshopt
--texture-compress webp
--compress meshopt
--texture-compress webp
Resize textures (power of 2)
调整纹理尺寸(2的幂次)
gltf-transform resize input.glb output.glb --width 1024 --height 1024
gltf-transform resize input.glb output.glb --width 1024 --height 1024
Flatten scene hierarchy (reduces draw calls)
扁平化场景层级(减少绘制调用)
gltf-transform flatten input.glb output.glb
gltf-transform flatten input.glb output.glb
Merge meshes sharing materials
合并共享材质的网格
gltf-transform join input.glb output.glb
gltf-transform join input.glb output.glb
Remove unused data
移除未使用的数据
gltf-transform prune input.glb output.glb
gltf-transform prune input.glb output.glb
Deduplicate accessors
去重访问器
gltf-transform dedup input.glb output.glb
gltf-transform dedup input.glb output.glb
Generate simplified LOD
生成简化的LOD
gltf-transform simplify input.glb output.glb --ratio 0.5 --error 0.001
gltf-transform simplify input.glb output.glb --ratio 0.5 --error 0.001
Full production pipeline
完整生产流程
gltf-transform optimize input.glb output.glb
--compress meshopt
--texture-compress ktx2
--texture-size 1024
--compress meshopt
--texture-compress ktx2
--texture-size 1024
undefinedgltf-transform optimize input.glb output.glb
--compress meshopt
--texture-compress ktx2
--texture-size 1024
--compress meshopt
--texture-compress ktx2
--texture-size 1024
undefinedgltfpack
gltfpack
Alternative CLI (part of meshoptimizer). Faster, less flexible.
bash
undefined替代CLI工具(属于meshoptimizer)。速度更快,灵活性较低。
bash
undefinedBasic optimization
基础优化
gltfpack -i input.glb -o output.glb
gltfpack -i input.glb -o output.glb
With Meshopt compression
启用Meshopt压缩
gltfpack -i input.glb -o output.glb -cc
gltfpack -i input.glb -o output.glb -cc
With KTX2 texture compression
启用KTX2纹理压缩
gltfpack -i input.glb -o output.glb -tc
gltfpack -i input.glb -o output.glb -tc
Simplify (50% triangle reduction)
简化(减少50%三角形数量)
gltfpack -i input.glb -o output.glb -si 0.5
gltfpack -i input.glb -o output.glb -si 0.5
All optimizations (production ready)
所有优化(生产就绪)
gltfpack -i input.glb -o output.glb -cc -tc -si 0.5
undefinedgltfpack -i input.glb -o output.glb -cc -tc -si 0.5
undefinedTexture Optimization
纹理优化
Format Selection
格式选择
| Format | Use Case | Alpha | Compression | GPU Decode |
|---|---|---|---|---|
| KTX2/Basis | GPU-compressed (best) | Yes | UASTC/ETC1S | Native |
| WebP | General textures | Yes | Lossy/Lossless | CPU |
| AVIF | Best file compression | Yes | Lossy | CPU |
| JPEG | Photos, no alpha | No | Lossy | CPU |
| PNG | UI, sharp edges | Yes | Lossless | CPU |
KTX2/Basis Universal is preferred for 2026 - textures stay compressed in GPU memory.
| 格式 | 使用场景 | 透明通道 | 压缩方式 | GPU解码 |
|---|---|---|---|---|
| KTX2/Basis | GPU压缩(最佳选择) | 支持 | UASTC/ETC1S | 原生支持 |
| WebP | 通用纹理 | 支持 | 有损/无损 | CPU解码 |
| AVIF | 文件压缩率最佳 | 支持 | 有损 | CPU解码 |
| JPEG | 照片纹理,无透明通道 | 不支持 | 有损 | CPU解码 |
| PNG | UI、锐利边缘纹理 | 支持 | 无损 | CPU解码 |
KTX2/Basis Universal是2026年的首选格式 - 纹理在GPU内存中保持压缩状态。
Size Guidelines
尺寸指南
| Texture Type | Mobile | Desktop | Notes |
|---|---|---|---|
| Diffuse/Albedo | 512-1024 | 1024-2048 | sRGB color space |
| Normal | 512-1024 | 1024-2048 | Linear, tangent space |
| Roughness/Metal | 256-512 | 512-1024 | Linear, can pack |
| AO | 256-512 | 512-1024 | Linear, can pack |
| Environment | 256-512 | 512-1024 | HDR for reflections |
Power of 2: Always use power-of-2 dimensions (256, 512, 1024, 2048) for mipmapping.
| 纹理类型 | 移动端 | 桌面端 | 说明 |
|---|---|---|---|
| 漫反射/基础色 | 512-1024 | 1024-2048 | sRGB色彩空间 |
| 法线 | 512-1024 | 1024-2048 | 线性、切线空间 |
| 粗糙度/金属度 | 256-512 | 512-1024 | 线性,可打包 |
| 环境光遮蔽(AO) | 256-512 | 512-1024 | 线性,可打包 |
| 环境贴图 | 256-512 | 512-1024 | HDR用于反射 |
2的幂次: 始终使用2的幂次尺寸(256、512、1024、2048)以支持多级渐远纹理(mipmapping)。
Compression Commands
压缩命令
bash
undefinedbash
undefinedImageMagick - resize and convert
ImageMagick - 调整尺寸并转换格式
magick input.png -resize 1024x1024 -quality 85 output.webp
magick input.png -resize 1024x1024 -quality 85 output.webp
cwebp (WebP)
cwebp(WebP格式)
cwebp -q 80 input.png -o output.webp
cwebp -q 80 input.png -o output.webp
Basis Universal (KTX2) - high quality UASTC
Basis Universal(KTX2)- 高质量UASTC格式
basisu -uastc -uastc_level 2 input.png -output_file output.ktx2
basisu -uastc -uastc_level 2 input.png -output_file output.ktx2
Basis Universal - smaller ETC1S (lower quality)
Basis Universal - 体积更小的ETC1S(质量较低)
basisu input.png -output_file output.ktx2
basisu input.png -output_file output.ktx2
toktx (Khronos tool)
toktx(Khronos工具)
toktx --t2 --uastc 2 output.ktx2 input.png
toktx --t2 --uastc 2 output.ktx2 input.png
Squoosh CLI (WebP/AVIF)
Squoosh CLI(WebP/AVIF)
squoosh-cli --webp '{quality:80}' input.png
squoosh-cli --avif '{quality:60}' input.png
undefinedsquoosh-cli --webp '{quality:80}' input.png
squoosh-cli --avif '{quality:60}' input.png
undefinedChannel Packing (ORM)
通道打包(ORM)
Combine grayscale maps into RGBA channels to reduce texture count:
R: Ambient Occlusion
G: Roughness
B: Metalness
A: (unused or height)javascript
// Three.js with packed ORM texture
const ormTexture = textureLoader.load('/orm.png')
ormTexture.colorSpace = THREE.LinearSRGBColorSpace
const material = new THREE.MeshStandardNodeMaterial({
aoMap: ormTexture,
roughnessMap: ormTexture,
metalnessMap: ormTexture,
// Channel selection happens automatically in ORM workflow
})将灰度图合并到RGBA通道以减少纹理数量:
R: 环境光遮蔽(Ambient Occlusion)
G: 粗糙度(Roughness)
B: 金属度(Metalness)
A: (未使用或高度图)javascript
// Three.js中使用打包的ORM纹理
const ormTexture = textureLoader.load('/orm.png')
ormTexture.colorSpace = THREE.LinearSRGBColorSpace
const material = new THREE.MeshStandardNodeMaterial({
aoMap: ormTexture,
roughnessMap: ormTexture,
metalnessMap: ormTexture,
// 通道选择在ORM工作流中自动完成
})Blender Export Settings
Blender导出设置
GLTF Export Checklist
GLTF导出检查清单
- Apply transforms: Ctrl+A → All Transforms
- Apply modifiers: Check "Apply Modifiers" in export
- Check scale: Blender default 1 unit = 1 meter
- Clean up: Remove unused materials, objects, shape keys
- 应用变换:Ctrl+A → 所有变换
- 应用修改器:在导出中勾选“应用修改器”
- 检查比例:Blender默认1单位=1米
- 清理内容:移除未使用的材质、对象、形状键
Export Settings (Blender 4.2+)
导出设置(Blender 4.2+)
Format: GLB (single file)
Include:
[x] Selected Objects (if exporting subset)
[x] Custom Properties
[x] Cameras (if needed)
[x] Punctual Lights (if needed)
Transform:
+Y Up (standard for web)
Data:
Mesh:
[x] Apply Modifiers
[x] UVs
[x] Normals
[ ] Tangents (let Three.js compute)
[ ] Vertex Colors (unless needed)
Material:
[x] Materials → Export
[x] Images → Automatic (embeds in GLB)
Shape Keys: [x] (if using morph targets)
Skinning: [x] (if using armatures)
Armature:
[x] Export Deformation Bones Only
Animation:
[x] Animations
Sampling Rate: 24 or match source
Compression:
[ ] Draco (prefer post-processing with gltf-transform)格式: GLB(单文件)
包含:
[x] 选中对象(如果导出子集)
[x] 自定义属性
[x] 相机(如果需要)
[x] 点光源(如果需要)
变换:
+Y 向上(Web标准)
数据:
网格:
[x] 应用修改器
[x] UV
[x] 法线
[ ] 切线(让Three.js计算)
[ ] 顶点颜色(除非需要)
材质:
[x] 材质 → 导出
[x] 图像 → 自动(嵌入到GLB中)
形状键: [x](如果使用变形目标)
蒙皮: [x](如果使用骨骼)
骨骼:
[x] 仅导出变形骨骼
动画:
[x] 动画
采样率: 24或与源文件一致
压缩:
[ ] Draco(推荐使用gltf-transform进行后处理)Common Export Issues
常见导出问题
| Problem | Solution |
|---|---|
| Model too big/small | Apply scale (Ctrl+A) before export |
| Missing textures | Pack textures (File → External Data → Pack) |
| Broken normals | Recalculate normals (Shift+N in Edit mode) |
| Flipped faces | Check normals direction, flip if needed |
| Animation jitter | Increase keyframe sampling rate |
| Materials wrong | Use Principled BSDF, check texture paths |
| Bones missing | Check "Export Deformation Bones Only" |
| 问题 | 解决方案 |
|---|---|
| 模型过大/过小 | 导出前应用缩放(Ctrl+A) |
| 纹理丢失 | 打包纹理(文件 → 外部数据 → 打包) |
| 法线错误 | 重新计算法线(编辑模式下Shift+N) |
| 面翻转 | 检查法线方向,必要时翻转 |
| 动画抖动 | 提高关键帧采样率 |
| 材质异常 | 使用Principled BSDF材质,检查纹理路径 |
| 骨骼丢失 | 勾选“仅导出变形骨骼” |
Loading in Three.js
在Three.js中加载
WebGPU Setup (2026)
WebGPU设置(2026)
javascript
import * as THREE from 'three/webgpu'
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js'
import { MeshoptDecoder } from 'three/addons/libs/meshopt_decoder.module.js'
import { KTX2Loader } from 'three/addons/loaders/KTX2Loader.js'
const loader = new GLTFLoader()
// Meshopt decoder (recommended)
loader.setMeshoptDecoder(MeshoptDecoder)
// KTX2 textures (requires renderer for format detection)
const ktx2Loader = new KTX2Loader()
ktx2Loader.setTranscoderPath('https://cdn.jsdelivr.net/npm/three@0.171.0/examples/jsm/libs/basis/')
ktx2Loader.detectSupport(renderer) // Required!
loader.setKTX2Loader(ktx2Loader)
// Load
const gltf = await loader.loadAsync('/model.glb')
scene.add(gltf.scene)javascript
import * as THREE from 'three/webgpu'
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js'
import { MeshoptDecoder } from 'three/addons/libs/meshopt_decoder.module.js'
import { KTX2Loader } from 'three/addons/loaders/KTX2Loader.js'
const loader = new GLTFLoader()
// Meshopt解码器(推荐)
loader.setMeshoptDecoder(MeshoptDecoder)
// KTX2纹理(需要渲染器检测格式支持)
const ktx2Loader = new KTX2Loader()
ktx2Loader.setTranscoderPath('https://cdn.jsdelivr.net/npm/three@0.171.0/examples/jsm/libs/basis/')
ktx2Loader.detectSupport(renderer) // 必填!
loader.setKTX2Loader(ktx2Loader)
// 加载模型
const gltf = await loader.loadAsync('/model.glb')
scene.add(gltf.scene)Draco Fallback (if needed)
Draco降级方案(如有需要)
javascript
import { DRACOLoader } from 'three/addons/loaders/DRACOLoader.js'
const dracoLoader = new DRACOLoader()
dracoLoader.setDecoderPath('https://www.gstatic.com/draco/versioned/decoders/1.5.7/')
loader.setDRACOLoader(dracoLoader)javascript
import { DRACOLoader } from 'three/addons/loaders/DRACOLoader.js'
const dracoLoader = new DRACOLoader()
dracoLoader.setDecoderPath('https://www.gstatic.com/draco/versioned/decoders/1.5.7/')
loader.setDRACOLoader(dracoLoader)React Three Fiber
React Three Fiber
jsx
import { useGLTF } from '@react-three/drei'
// Drei handles Meshopt and Draco automatically
const { scene, nodes, materials, animations } = useGLTF('/model.glb')
// Preload for instant display
useGLTF.preload('/model.glb')jsx
import { useGLTF } from '@react-three/drei'
// Drei自动处理Meshopt和Draco
const { scene, nodes, materials, animations } = useGLTF('/model.glb')
// 预加载以实现即时显示
useGLTF.preload('/model.glb')Performance Budgets
性能预算
Target Metrics
目标指标
| Platform | Triangles | Draw Calls | Texture Memory | File Size |
|---|---|---|---|---|
| Mobile | <100K | <50 | <50MB | <5MB |
| Desktop | <500K | <100 | <200MB | <20MB |
| High-end | <2M | <200 | <500MB | <50MB |
| 平台 | 三角形数量 | 绘制调用 | 纹理内存 | 文件体积 |
|---|---|---|---|---|
| 移动端 | <100K | <50 | <50MB | <5MB |
| 桌面端 | <500K | <100 | <200MB | <20MB |
| 高端设备 | <2M | <200 | <500MB | <50MB |
Profiling
性能分析
javascript
// Three.js render info (call after render)
console.log(renderer.info.render)
// { calls, triangles, points, lines, frame }
console.log(renderer.info.memory)
// { geometries, textures }
// Performance monitor
import Stats from 'stats.js'
const stats = new Stats()
stats.showPanel(0) // 0: fps, 1: ms, 2: mb
document.body.appendChild(stats.dom)
function animate() {
stats.begin()
renderer.render(scene, camera)
stats.end()
}
renderer.setAnimationLoop(animate)javascript
// Three.js渲染信息(渲染后调用)
console.log(renderer.info.render)
// { calls, triangles, points, lines, frame }
console.log(renderer.info.memory)
// { geometries, textures }
// 性能监控器
import Stats from 'stats.js'
const stats = new Stats()
stats.showPanel(0) // 0: fps, 1: 毫秒, 2: 内存占用
document.body.appendChild(stats.dom)
function animate() {
stats.begin()
renderer.render(scene, camera)
stats.end()
}
renderer.setAnimationLoop(animate)Asset Validation
资产验证
bash
undefinedbash
undefinedValidate GLTF structure
验证GLTF结构
npx gltf-validator model.glb
npx gltf-validator model.glb
Online validation
在线验证
Check file size breakdown
查看文件体积细分
gltf-transform inspect model.glb
undefinedgltf-transform inspect model.glb
undefinedRelated Skills
相关技能
| When you need... | Use skill |
|---|---|
| Build 3D scenes with Three.js | → threejs |
| Build 3D scenes with React | → react-three-fiber |
| Debug rendering/performance issues | → graphics-troubleshooting |
| 当你需要... | 使用技能 |
|---|---|
| 使用Three.js构建3D场景 | → threejs |
| 使用React构建3D场景 | → react-three-fiber |
| 调试渲染/性能问题 | → graphics-troubleshooting |
Reference Files
参考文件
- references/compression.md - Detailed compression comparisons
- references/textures.md - Texture format deep dive
- references/validation.md - Asset validation and debugging
- references/lod.md - Level-of-detail strategies
- references/baking.md - Texture baking workflows
- references/compression.md - 详细的压缩对比
- references/textures.md - 纹理格式深度解析
- references/validation.md - 资产验证与调试
- references/lod.md - 多级细节(LOD)策略
- references/baking.md - 纹理烘焙工作流