three-best-practices
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseThree.js Best Practices
Three.js 最佳实践
Comprehensive performance optimization guide for Three.js applications. Contains 120+ rules across 18 categories, prioritized by impact.
这是一份针对Three.js应用的全面性能优化指南,包含18个分类下的120+条规则,按影响优先级排序。
Sources & Credits
来源与致谢
This skill compiles best practices from multiple authoritative sources:
- Official guidelines from Three.js
branch maintained by mrdoobllms- 100 Three.js Tips by Utsubo - Excellent comprehensive guide covering WebGPU, asset optimization, and performance tips
本指南整合了多个权威来源的最佳实践:
- 由mrdoob维护的Three.js
分支官方指南llms- Utsubo发布的《100个Three.js技巧》(100 Three.js Tips)——涵盖WebGPU、资源优化和性能技巧的优质综合指南
When to Apply
适用场景
Reference these guidelines when:
- Setting up a new Three.js project
- Writing or reviewing Three.js code
- Optimizing performance or fixing memory leaks
- Working with custom shaders (GLSL or TSL)
- Implementing WebGPU features
- Building VR/AR experiences with WebXR
- Integrating physics engines
- Optimizing for mobile devices
在以下场景中可参考本指南:
- 搭建新的Three.js项目时
- 编写或评审Three.js代码时
- 优化性能或修复内存泄漏时
- 处理自定义着色器(GLSL或TSL)时
- 实现WebGPU功能时
- 构建WebXR相关的VR/AR体验时
- 集成物理引擎时
- 针对移动设备进行优化时
Rule Categories by Priority
按优先级排序的规则分类
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 0 | Modern Setup & Imports | FUNDAMENTAL | |
| 1 | Memory Management & Dispose | CRITICAL | |
| 2 | Render Loop Optimization | CRITICAL | |
| 3 | Draw Call Optimization | CRITICAL | |
| 4 | Geometry & Buffer Management | HIGH | |
| 5 | Material & Texture Optimization | HIGH | |
| 6 | Asset Compression | HIGH | |
| 7 | Lighting & Shadows | MEDIUM-HIGH | |
| 8 | Scene Graph Organization | MEDIUM | |
| 9 | Shader Best Practices (GLSL) | MEDIUM | |
| 10 | TSL (Three.js Shading Language) | MEDIUM | |
| 11 | WebGPU Renderer | MEDIUM | |
| 12 | Loading & Assets | MEDIUM | |
| 13 | Core Web Vitals | MEDIUM-HIGH | |
| 14 | Camera & Controls | LOW-MEDIUM | |
| 15 | Animation System | MEDIUM | |
| 16 | Physics Integration | MEDIUM | |
| 17 | WebXR / VR / AR | MEDIUM | |
| 18 | Audio | LOW-MEDIUM | |
| 19 | Post-Processing | MEDIUM | |
| 20 | Mobile Optimization | HIGH | |
| 21 | Production | HIGH | |
| 22 | Debug & DevTools | LOW | |
| 优先级 | 分类 | 影响等级 | 前缀 |
|---|---|---|---|
| 0 | 现代项目配置与导入 | 基础核心 | |
| 1 | 内存管理与资源释放 | 至关重要 | |
| 2 | 渲染循环优化 | 至关重要 | |
| 3 | 绘制调用优化 | 至关重要 | |
| 4 | 几何体与缓冲区管理 | 高影响 | |
| 5 | 材质与纹理优化 | 高影响 | |
| 6 | 资源压缩 | 高影响 | |
| 7 | 光照与阴影 | 中高影响 | |
| 8 | 场景图组织 | 中影响 | |
| 9 | GLSL着色器最佳实践 | 中影响 | |
| 10 | TSL(Three.js着色语言) | 中影响 | |
| 11 | WebGPU渲染器 | 中影响 | |
| 12 | 加载与资源管理 | 中影响 | |
| 13 | Web核心指标 | 中高影响 | |
| 14 | 相机与控制器 | 中低影响 | |
| 15 | 动画系统 | 中影响 | |
| 16 | 物理引擎集成 | 中影响 | |
| 17 | WebXR / VR / AR | 中影响 | |
| 18 | 音频 | 中低影响 | |
| 19 | 后期处理 | 中影响 | |
| 20 | 移动端优化 | 高影响 | |
| 21 | 生产环境部署 | 高影响 | |
| 22 | 调试与开发工具 | 低影响 | |
Quick Reference
快速参考
0. Modern Setup (FUNDAMENTAL)
0. 现代项目配置(基础核心)
- - Use Import Maps, not old CDN scripts
setup-use-import-maps - - WebGLRenderer (default) vs WebGPURenderer (TSL/compute)
setup-choose-renderer - - Use
setup-animation-loopnot manual RAFrenderer.setAnimationLoop() - - Complete modern scene template
setup-basic-scene-template
- - 使用Import Maps,而非旧版CDN脚本
setup-use-import-maps - - WebGLRenderer(默认)与WebGPURenderer(TSL/计算场景)的选择
setup-choose-renderer - - 使用
setup-animation-loop而非手动RAFrenderer.setAnimationLoop() - - 完整的现代场景模板
setup-basic-scene-template
1. Memory Management (CRITICAL)
1. 内存管理(至关重要)
- - Always dispose geometries
memory-dispose-geometry - - Always dispose materials and textures
memory-dispose-material - - Dispose dynamically created textures
memory-dispose-textures - - Always dispose WebGLRenderTarget
memory-dispose-render-targets - - Use recursive disposal for hierarchies
memory-dispose-recursive - - Dispose in React cleanup/unmount
memory-dispose-on-unmount - - Dispose renderer when destroying view
memory-renderer-dispose - - Reuse geometries and materials
memory-reuse-objects
- - 务必释放几何体资源
memory-dispose-geometry - - 务必释放材质与纹理资源
memory-dispose-material - - 释放动态创建的纹理
memory-dispose-textures - - 务必释放WebGLRenderTarget
memory-dispose-render-targets - - 对层级结构使用递归释放
memory-dispose-recursive - - 在React的清理/卸载阶段释放资源
memory-dispose-on-unmount - - 销毁视图时释放渲染器
memory-renderer-dispose - - 复用几何体与材质
memory-reuse-objects
2. Render Loop (CRITICAL)
2. 渲染循环(至关重要)
- - Single requestAnimationFrame loop
render-single-raf - - Render on demand for static scenes
render-conditional - - Use delta time for animations
render-delta-time - - Never allocate in render loop
render-avoid-allocations - - Cache expensive computations
render-cache-computations - - Enable frustum culling
render-frustum-culling - - Disable auto matrix updates for static objects
render-update-matrix-manual - - Limit pixel ratio to 2
render-pixel-ratio - - Use antialiasing judiciously
render-antialias-wisely
- - 单个requestAnimationFrame循环
render-single-raf - - 静态场景按需渲染
render-conditional - - 使用deltaTime处理动画
render-delta-time - - 绝不在渲染循环中分配内存
render-avoid-allocations - - 缓存耗时计算结果
render-cache-computations - - 启用视锥体剔除
render-frustum-culling - - 禁用静态对象的自动矩阵更新
render-update-matrix-manual - - 将像素比限制为2
render-pixel-ratio - - 谨慎使用抗锯齿
render-antialias-wisely
3. Draw Call Optimization (CRITICAL)
3. 绘制调用优化(至关重要)
- - Target under 100 draw calls per frame
draw-call-optimization - - Use InstancedMesh for identical objects
geometry-instanced-mesh - - Use BatchedMesh for varied geometries (same material)
geometry-batched-mesh - - Merge static geometries with BufferGeometryUtils
geometry-merge-static
- - 目标是每帧绘制调用低于100次
draw-call-optimization - - 对相同对象使用InstancedMesh
geometry-instanced-mesh - - 对不同几何体(相同材质)使用BatchedMesh
geometry-batched-mesh - - 使用BufferGeometryUtils合并静态几何体
geometry-merge-static
4. Geometry (HIGH)
4. 几何体(高影响)
- - Always use BufferGeometry
geometry-buffer-geometry - - Merge static geometries
geometry-merge-static - - Use InstancedMesh for identical objects
geometry-instanced-mesh - - Use Level of Detail for complex models
geometry-lod - - Use indexed geometry
geometry-index-buffer - - Minimize vertex count
geometry-vertex-count - - Use appropriate typed arrays
geometry-attributes-typed - - Consider interleaved buffers
geometry-interleaved
- - 始终使用BufferGeometry
geometry-buffer-geometry - - 合并静态几何体
geometry-merge-static - - 对相同对象使用InstancedMesh
geometry-instanced-mesh - - 为复杂模型使用LOD(细节层次)
geometry-lod - - 使用索引几何体
geometry-index-buffer - - 最小化顶点数量
geometry-vertex-count - - 使用合适的类型数组
geometry-attributes-typed - - 考虑使用交错缓冲区
geometry-interleaved
5. Materials & Textures (HIGH)
5. 材质与纹理(高影响)
- - Reuse materials across meshes
material-reuse - - Use simplest material that works
material-simplest-sufficient - - Power-of-two texture dimensions
material-texture-size-power-of-two - - Use compressed textures (KTX2/Basis)
material-texture-compression - - Enable mipmaps appropriately
material-texture-mipmaps - - Use anisotropic filtering for floors
material-texture-anisotropy - - Use texture atlases
material-texture-atlas - - Minimize transparent materials
material-avoid-transparency - - Use onBeforeCompile for shader mods (or TSL)
material-onbeforecompile
- - 在多个网格间复用材质
material-reuse - - 使用满足需求的最简材质
material-simplest-sufficient - - 纹理尺寸使用2的幂次
material-texture-size-power-of-two - - 使用压缩纹理(KTX2/Basis)
material-texture-compression - - 合理启用mipmaps
material-texture-mipmaps - - 为地面使用各向异性过滤
material-texture-anisotropy - - 使用纹理图集
material-texture-atlas - - 尽量减少透明材质
material-avoid-transparency - - 使用onBeforeCompile修改着色器(或使用TSL)
material-onbeforecompile
6. Asset Compression (HIGH)
6. 资源压缩(高影响)
- - Draco, Meshopt, KTX2 compression guide
asset-compression - - 90-95% geometry size reduction
asset-draco - - GPU-compressed textures (UASTC vs ETC1S)
asset-ktx2 - - Alternative to Draco with faster decompression
asset-meshopt - - Level of Detail for 30-40% frame rate improvement
asset-lod
- - Draco、Meshopt、KTX2压缩指南
asset-compression - - 几何体尺寸减少90-95%
asset-draco - - GPU压缩纹理(UASTC vs ETC1S)
asset-ktx2 - - Draco的替代方案,解压速度更快
asset-meshopt - - LOD(细节层次)可提升30-40%帧率
asset-lod
7. Lighting & Shadows (MEDIUM-HIGH)
7. 光照与阴影(中高影响)
- - Limit to 3 or fewer active lights
lighting-limit-lights - - PointLight cost, CSM, fake shadows
lighting-shadows-advanced - - Bake lighting for static scenes
lighting-bake-static - - Fit shadow camera tightly
lighting-shadow-camera-tight - - Choose appropriate shadow resolution (512-4096)
lighting-shadow-map-size - - Enable shadows selectively
lighting-shadow-selective - - Use CSM for large scenes
lighting-shadow-cascade - - Disable autoUpdate for static scenes
lighting-shadow-auto-update - - Use Light Probes
lighting-probe - - Environment maps for ambient light
lighting-environment - - Gradient planes for budget contact shadows
lighting-fake-shadows
- - 限制活跃灯光数量为3个或更少
lighting-limit-lights - - 点光源开销、CSM、模拟阴影
lighting-shadows-advanced - - 为静态场景烘焙光照
lighting-bake-static - - 紧密贴合阴影相机范围
lighting-shadow-camera-tight - - 选择合适的阴影分辨率(512-4096)
lighting-shadow-map-size - - 选择性启用阴影
lighting-shadow-selective - - 大型场景使用CSM(级联阴影贴图)
lighting-shadow-cascade - - 静态场景禁用自动更新
lighting-shadow-auto-update - - 使用光照探针
lighting-probe - - 使用环境贴图实现环境光
lighting-environment - - 使用渐变平面实现低成本接触阴影
lighting-fake-shadows
8. Scene Graph (MEDIUM)
8. 场景图(中影响)
- - Use Groups for organization
scene-group-objects - - Use Layers for selective rendering
scene-layers - - Use visible flag, not add/remove
scene-visible-toggle - - Flatten static hierarchies
scene-flatten-static - - Name objects for debugging
scene-name-objects - - Reuse objects instead of create/destroy
object-pooling
- - 使用Group组织对象
scene-group-objects - - 使用Layers实现选择性渲染
scene-layers - - 使用visible属性切换显示,而非添加/移除对象
scene-visible-toggle - - 扁平化静态层级结构
scene-flatten-static - - 为对象命名以便调试
scene-name-objects - - 复用对象而非创建/销毁
object-pooling
9. Shaders GLSL (MEDIUM)
9. GLSL着色器(中影响)
- - Use mediump for mobile (~2x faster)
shader-precision - - Mobile-specific optimizations (varyings, branching)
shader-mobile - - Replace conditionals with mix/step
shader-avoid-branching - - Precompute on CPU
shader-precompute-cpu - - Avoid discard, use alphaTest
shader-avoid-discard - - Use textureLod for known mip levels
shader-texture-lod - - Prefer uniform arrays
shader-uniform-arrays - - Limit varyings to 3 for mobile
shader-varying-interpolation - - Pack data into RGBA channels
shader-pack-data - - Use Three.js shader chunks
shader-chunk-injection
- - 移动端使用mediump(速度提升约2倍)
shader-precision - - 移动端特定优化(varyings、分支)
shader-mobile - - 使用mix/step替代条件判断
shader-avoid-branching - - 在CPU端预计算
shader-precompute-cpu - - 避免使用discard,改用alphaTest
shader-avoid-discard - - 已知mip级别时使用textureLod
shader-texture-lod - - 优先使用uniform数组
shader-uniform-arrays - - 移动端限制varyings数量为3个
shader-varying-interpolation - - 将数据打包到RGBA通道
shader-pack-data - - 使用Three.js着色器片段
shader-chunk-injection
10. TSL - Three.js Shading Language (MEDIUM)
10. TSL - Three.js着色语言(中影响)
- - Use TSL instead of onBeforeCompile
tsl-why-use - - WebGPU setup for TSL
tsl-setup-webgpu - - Full TSL type system and functions
tsl-complete-reference - - Material node properties reference
tsl-material-slots - - Use NodeMaterial classes
tsl-node-materials - - Types, operations, swizzling
tsl-basic-operations - - Creating TSL functions with Fn()
tsl-functions - - If, select, loops in TSL
tsl-conditionals - - Textures and triplanar mapping
tsl-textures - - Built-in noise functions (mx_noise_float, mx_fractal_noise)
tsl-noise - - bloom, blur, dof, ao
tsl-post-processing - - GPGPU and compute operations
tsl-compute-shaders - - GLSL to TSL translation
tsl-glsl-to-tsl
- - 使用TSL替代onBeforeCompile
tsl-why-use - - 为TSL配置WebGPU
tsl-setup-webgpu - - 完整的TSL类型系统与函数
tsl-complete-reference - - 材质节点属性参考
tsl-material-slots - - 使用NodeMaterial类
tsl-node-materials - - 类型、操作、分量选择
tsl-basic-operations - - 使用Fn()创建TSL函数
tsl-functions - - TSL中的if、select、循环
tsl-conditionals - - 纹理与三平面映射
tsl-textures - - 内置噪声函数(mx_noise_float、mx_fractal_noise)
tsl-noise - - bloom、模糊、景深、环境光遮蔽
tsl-post-processing - - GPGPU与计算操作
tsl-compute-shaders - - GLSL到TSL的转换
tsl-glsl-to-tsl
11. WebGPU Renderer (MEDIUM)
11. WebGPU渲染器(中影响)
- - Setup, browser support, migration guide
webgpu-renderer - - Use renderAsync for compute-heavy scenes
webgpu-render-async - - Check adapter features
webgpu-feature-detection - - GPU-persistent buffers
webgpu-instanced-array - - Read-write compute textures
webgpu-storage-textures - - Shared memory (10-100x faster)
webgpu-workgroup-memory - - GPU-driven rendering
webgpu-indirect-draws
- - 配置、浏览器支持、迁移指南
webgpu-renderer - - 计算密集型场景使用renderAsync
webgpu-render-async - - 检查适配器特性
webgpu-feature-detection - - GPU持久化缓冲区
webgpu-instanced-array - - 可读写计算纹理
webgpu-storage-textures - - 共享内存(速度提升10-100倍)
webgpu-workgroup-memory - - 驱动GPU渲染
webgpu-indirect-draws
12. Loading & Assets (MEDIUM)
12. 加载与资源(中影响)
- - Use Draco for large meshes
loading-draco-compression - - Use glTF format
loading-gltf-preferred - - Full loader setup with DRACO/Meshopt/KTX2
gltf-loading-optimization - - Show loading progress
loading-progress-feedback - - Use async/await for loading
loading-async-await - - Lazy load non-critical assets
loading-lazy - - Enable caching
loading-cache-assets - - Unload unused assets
loading-dispose-unused
- - 大型网格使用Draco
loading-draco-compression - - 使用glTF格式
loading-gltf-preferred - - 配置支持DRACO/Meshopt/KTX2的完整加载器
gltf-loading-optimization - - 显示加载进度
loading-progress-feedback - - 使用async/await处理加载
loading-async-await - - 懒加载非关键资源
loading-lazy - - 启用缓存
loading-cache-assets - - 卸载未使用资源
loading-dispose-unused
13. Core Web Vitals (MEDIUM-HIGH)
13. Web核心指标(中高影响)
- - LCP, FID, CLS optimization for 3D
core-web-vitals - - Lazy load 3D below the fold with IntersectionObserver
vitals-lazy-load - - Dynamic import Three.js modules
vitals-code-split - - Preload critical assets with link tags
vitals-preload - - Low-res to high-res progressive load
vitals-progressive-loading - - Show placeholder geometry during load
vitals-placeholders - - Offload heavy work to workers
vitals-web-workers - - Stream large scenes by chunks
vitals-streaming
- - 3D场景下的LCP、FID、CLS优化
core-web-vitals - - 使用IntersectionObserver懒加载视口下方的3D内容
vitals-lazy-load - - 动态导入Three.js模块
vitals-code-split - - 使用link标签预加载关键资源
vitals-preload - - 从低分辨率到高分辨率渐进式加载
vitals-progressive-loading - - 加载时显示占位几何体
vitals-placeholders - - 将繁重工作卸载到Web Worker
vitals-web-workers - - 分块流式加载大型场景
vitals-streaming
14. Camera & Controls (LOW-MEDIUM)
14. 相机与控制器(中低影响)
- - Set tight near/far planes
camera-near-far - - Choose appropriate FOV
camera-fov - - Use damping for smooth controls
camera-controls-damping - - Handle resize properly
camera-resize-handler - - Set orbit control limits
camera-orbit-limits
- - 设置紧凑的近/远裁剪面
camera-near-far - - 选择合适的视场角
camera-fov - - 使用阻尼实现平滑控制器
camera-controls-damping - - 正确处理窗口大小变化
camera-resize-handler - - 设置轨道控制器限制
camera-orbit-limits
15. Animation (MEDIUM)
15. 动画(中影响)
- - AnimationMixer, blending, morph targets, skeletal
animation-system
- - AnimationMixer、混合、 morph targets、骨骼动画
animation-system
16. Physics (MEDIUM)
16. 物理引擎(中影响)
- - Rapier, Cannon-es integration patterns
physics-integration - - GPU physics with compute shaders
physics-compute-shaders
- - Rapier、Cannon-es集成模式
physics-integration - - 使用计算着色器实现GPU物理
physics-compute-shaders
17. WebXR (MEDIUM)
17. WebXR(中影响)
- - VR/AR buttons, controllers, hit testing
webxr-setup
- - VR/AR按钮、控制器、命中测试
webxr-setup
18. Audio (LOW-MEDIUM)
18. 音频(中低影响)
- - PositionalAudio, HRTF, spatial sound
audio-spatial
- - PositionalAudio、HRTF、空间音频
audio-spatial
19. Post-Processing (MEDIUM)
19. 后期处理(中影响)
- - pmndrs/postprocessing guide
postprocessing-optimization - - Disable AA, stencil, depth for post
postpro-renderer-config - - Combine effects in single pass
postpro-merge-effects - - Selective bloom for performance
postpro-selective-bloom - - Half resolution for 2x FPS
postpro-resolution-scaling - - TSL-based post for WebGPU
postpro-webgpu-native
- - pmndrs/postprocessing指南
postprocessing-optimization - - 后期处理时禁用AA、模板、深度
postpro-renderer-config - - 单通道合并多个效果
postpro-merge-effects - - 选择性 bloom 以提升性能
postpro-selective-bloom - - 半分辨率可提升2倍FPS
postpro-resolution-scaling - - 基于TSL的WebGPU后期处理
postpro-webgpu-native
20. Optimization (HIGH)
20. 移动端优化(高影响)
- - Mobile-specific optimizations and checklist
mobile-optimization - - BVH, layers, GPU picking
raycasting-optimization
- - 移动端特定优化与检查清单
mobile-optimization - - BVH、Layers、GPU拾取
raycasting-optimization
21. Production (HIGH)
21. 生产环境(高影响)
- - WebGL context loss and recovery
error-handling-recovery - - Breaking changes by version
migration-checklist
- - WebGL上下文丢失与恢复
error-handling-recovery - - 各版本的破坏性变更
migration-checklist
22. Debug & DevTools (LOW)
22. 调试与开发工具(低影响)
- - Complete debugging toolkit
debug-devtools - - stats-gl for WebGL/WebGPU monitoring
debug-stats-gl - - lil-gui for live parameter tweaking
debug-lil-gui - - Spector.js for WebGL frame capture
debug-spector - - Monitor draw calls and memory
debug-renderer-info - - Fast raycasting with BVH
debug-three-mesh-bvh - - Handle WebGL context loss
debug-context-lost - - Profile render loop sections
debug-animation-loop-profiling - - Remove debug code in production
debug-conditional
- - 完整的调试工具集
debug-devtools - - 使用stats-gl监控WebGL/WebGPU
debug-stats-gl - - 使用lil-gui实时调整参数
debug-lil-gui - - 使用Spector.js捕获WebGL帧
debug-spector - - 监控绘制调用与内存
debug-renderer-info - - 使用BVH实现快速射线检测
debug-three-mesh-bvh - - 处理WebGL上下文丢失
debug-context-lost - - 分析渲染循环各部分性能
debug-animation-loop-profiling - - 生产环境移除调试代码
debug-conditional
How to Use
使用方法
Read individual rule files for detailed explanations and code examples:
rules/setup-use-import-maps.md
rules/memory-dispose-geometry.md
rules/tsl-complete-reference.md
rules/mobile-optimization.mdEach rule file contains:
- Brief explanation of why it matters
- BAD code example with explanation
- GOOD code example with explanation
- Additional context and references
阅读单个规则文件获取详细说明与代码示例:
rules/setup-use-import-maps.md
rules/memory-dispose-geometry.md
rules/tsl-complete-reference.md
rules/mobile-optimization.md每个规则文件包含:
- 规则重要性的简要说明
- 错误代码示例及解释
- 正确代码示例及解释
- 额外上下文与参考资料
Key Patterns
核心模式
Modern Import Maps
现代Import Maps
html
<script type="importmap">
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/three@0.182.0/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.182.0/examples/jsm/",
"three/tsl": "https://cdn.jsdelivr.net/npm/three@0.182.0/build/three.tsl.js"
}
}
</script>html
<script type="importmap">
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/three@0.182.0/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.182.0/examples/jsm/",
"three/tsl": "https://cdn.jsdelivr.net/npm/three@0.182.0/build/three.tsl.js"
}
}
</script>Proper Disposal
正确的资源释放
javascript
function disposeObject(obj) {
if (obj.geometry) obj.geometry.dispose();
if (obj.material) {
if (Array.isArray(obj.material)) {
obj.material.forEach(m => m.dispose());
} else {
obj.material.dispose();
}
}
}javascript
function disposeObject(obj) {
if (obj.geometry) obj.geometry.dispose();
if (obj.material) {
if (Array.isArray(obj.material)) {
obj.material.forEach(m => m.dispose());
} else {
obj.material.dispose();
}
}
}TSL Basic Usage
TSL基础用法
javascript
import { texture, uv, color, time, sin } from 'three/tsl';
const material = new THREE.MeshStandardNodeMaterial();
material.colorNode = texture(map).mul(color(0xff0000));
material.colorNode = color(0x00ff00).mul(sin(time).mul(0.5).add(0.5));javascript
import { texture, uv, color, time, sin } from 'three/tsl';
const material = new THREE.MeshStandardNodeMaterial();
material.colorNode = texture(map).mul(color(0xff0000));
material.colorNode = color(0x00ff00).mul(sin(time).mul(0.5).add(0.5));Mobile Detection
移动端检测
javascript
const isMobile = /Android|iPhone|iPad|iPod/i.test(navigator.userAgent);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, isMobile ? 1.5 : 2));javascript
const isMobile = /Android|iPhone|iPad|iPod/i.test(navigator.userAgent);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, isMobile ? 1.5 : 2));