three.js Knowledge Patch
Use this skill when working on a three.js application, addon, node graph, asset
pipeline, renderer integration, or upgrade. Inspect the project's three
dependency before applying release-specific advice. Prefer the installed
package, application code, and tests when they disagree with compatibility
guidance.
Reference index
| Reference | Topics |
|---|---|
| migrations-and-deprecations.md | Removed and deprecated APIs, renames, upgrade-sensitive behavior |
| rendering-and-webxr.md | WebGL, WebGPU, buffers, render targets, shadows, compute, WebXR |
| tsl-and-node-graphs.md | TSL, node materials, shader graphs, storage nodes, transpilation |
| assets-and-interchange.md | Loaders, exporters, formats, serialization, cache and editor interchange |
| scene-animation-and-geometry.md | Scene graph, animation, materials, lighting, geometry, math, physics |
| addons-postprocessing-and-controls.md | Passes, effects, controls, HTML surfaces, inspectors and utilities |
Start with migration hazards
Removed modules and assets
- Replace removed
PeppersGhostEffect,RGBMLoader,MeshPostProcessingMaterial,TiledLighting, scriptable-node APIs, and obsolete VOX classes before upgrading. - Replace
WebGLCubeRenderTargetwithCubeRenderTargetwhen usingWebGPURenderer. - Use
USDLoaderinstead of deprecatedUSDZLoader; avoid new uses ofMeshGouraudMaterial,LottieLoader,VTKLoader, andLWOLoader. - Do not resolve
examples/fonts, DRACO exporter encoders, or Lottie/TTF libraries from the installed package; these assets are no longer bundled. - Audit all previously deprecated APIs before an r178 upgrade because that release removed deprecated code broadly.
High-impact renames
| Old | Current |
|---|---|
NodeBuilder.monitor |
NodeBuilder.observer |
varying() |
toVarying() |
vertexStage() |
toVertexStage() |
RGBELoader |
HDRLoader |
label() |
setName() |
DFGApprox |
DFGLUT |
Line2NodeMaterial.useColor |
Line2NodeMaterial.vertexColors |
AnaglyphEffect.screenDistance |
AnaglyphEffect.planeDistance |
directionToFaceDirection |
negateOnBackSide |
PI2 |
TWO_PI |
reverseDepthBuffer |
reversedDepthBuffer |
Also replace directionToColor() with packNormalToRGB() and
colorToDirection() with unpackRGBToNormal(). For WebGL shader directions,
choose transformNormalByInverseViewMatrix() for normals and
transformDirectionByInverseViewMatrix() for directions.
Async lifecycle changes
- Pass an element to
Controls.connect(element). - Await
renderer.init()before renderer-dependent loader detection or GPU work; initialization returns the renderer. - Use
DRACOExporter.parseAsync()in place ofparse(). - Treat
FileLoader.load()andImageBitmapLoader.load()as callback-driven; they no longer return a value. - Do not build new code on deprecated
renderAsync()orcomputeAsync();waitForGPU()is gone. WebGPURenderer.compileAsync()is genuinely non-blocking.- Use
Loader.abort()as the common cancellation entry point.
State and default changes
SpriteNodeMaterial.transparentdefaults totrue; set it explicitly when opaque behavior is required.- Camera scale no longer contributes to the view matrix.
SpriteNodeMaterial.sizeAttenuationonly affects perspective cameras.Cachedoes not retainBlobvalues.- Loader cache keys are isolated by loader type.
- When
matrixAutoUpdateis disabled and.matrixchanges directly, setmatrixWorldNeedsUpdate = truebeforeupdateWorldMatrix(). - Raw WebGL pixel-store mutations must go through
renderer.state.pixelStorei()to keep cached renderer state synchronized. - Background and environment-map rotations now follow object rotation conventions; remove compensating rotations written for the old convention.
FBXLoaderconverts +Z-up assets to +Y-up automatically.
Renderer quick reference
Output and render-target control
- Output typing appears as renderer
colorBufferType, WebGLoutputBufferType, and WebGPU backendoutputType. On the WebGPU path,getOutputBufferType()replacesgetColorBufferType(). - Use
WebGPURenderer.setOutputRenderTarget()to choose the renderer output target explicitly. - Use
initRenderTarget()when a WebGPU target must be initialized before its first render. RenderTarget.clone()creates independent texture resources, andRenderTarget.copy()preserves multiview state.- Do not resize render targets during an XR render.
WebGPU capabilities
- Compatibility mode can be requested explicitly; automatic negotiation upgrades to core mode where possible and disables antialiasing if compatibility mode remains active.
- Render bundles support transparent objects, MRT, and
InstancedMesh. - MRT supports per-attachment blending and material
outputNode. - Texture support includes 3D and array storage textures, texture-array render
targets, BPTC formats, manual mipmaps, and
GPUTexture-backed external textures. - Use
ReadbackBufferor partialgetArrayBufferAsync()reads for targeted GPU readback. dispatchWorkgroupsIndirectdrives compute counts from an indirect buffer.- The addon renderer provides dynamic lights and Forward+ clustered lighting.
WebGL capabilities
reversedDepthBufferis the current constructor option.- Shadows support alpha-to-coverage;
PCFShadowMapnow supplies soft shadows. - MRT supports pixel readback, 2D array textures, and MSAA through the WebGL
backend used by
WebGPURenderer. WebGLRendereroffersoutputBufferType,setEffects(), packed normal maps, and aNodeMaterialcompatibility layer.
WebXR
WebGPURendererhas an XR manager with XR layers, MSAA, dynamicArrayCamerasizing, tone mapping, and output color-space handling.- Use
XRRenderTargetfor XR-specific target work. - Raw camera access is available from
WebXRManager. - Grip updates can emit an event through
WebXRController.
TSL and node-graph quick reference
Current construction patterns
- Use
toVarying(),toVertexStage(),setName(), and assignment's automatictoVar()conversion. - Use
positionGeometryrather thanpositionLocalwhenpositionNodeneeds pre-skinning or otherwise pre-transformed vertices. - Use
premultiplyAlpha;premultis the former name. - Use
DFGLUT; do not call removednodeObject()for Node classes. - TSL no longer defines
stringorarrayBuffer.
Data and compute
- Graphs can use
mat2, arrays, structs, atomics, boolean uniforms, matrix attributes, storage-backed instance attributes, and 3D storage textures. - Texture operations include
load(),sample(), offset access,texture3DLoad(),texture3DLevel(),textureGather(), andtextureGatherCompare(). - Compute work can use
computeKernel(), subgroup reductions, indirect dispatch, global/local scopes, and frame or before-event hooks. - Provide tangent attributes explicitly when the graph requires them; TSL no longer auto-generates tangents.
Diagnostics and transpilation
debug()callbacks receive(builder, code);DebugNodecallbacks receive raw data.StackTraceand stackdebug()are available for diagnostics.- The transpiler handles matrices, boolean vectors, varyings, texture
operations,
discard,switch, structs, bitcasts, simplifiedFn()layouts, linking, and WGSL encoding.
Assets and interchange quick reference
ImageUtils.getDataURL(image, type)selects the encoded MIME type; without a type, do not assume the source image format is preserved.DRACOLoaderandKTX2Loaderuse relative file URLs by default. Configure deployed decoder/transcoder paths deliberately.GLTFLoaderno longer probes WebP or AVIF support; gate incompatible assets in the application.KTX2Loadercovers additional ASTC, EAC, BCn, PVRTC, RGB9E5, R11G11B10, and 16-bit normalized formats and can generate mipmaps.MaterialLoader.registerMaterial()andMaterial.fromJSON()support custom material deserialization.GLTFExportercarries animation metadata, supports animations across multiple scenes, and can export WebP textures.PLYLoaderandPLYExporterpreserve declared attribute data types.USDLoaderhandles unified USD input, composition, animation, broader primitives and materials;USDZExportersupports hierarchy, animation, and multi-material output.
Scene, material, and geometry quick reference
Material.allowOverridecontrols override-material replacement and is preserved bycopy().Object3D.staticandpivotsurvive copying and serialization.MeshandSpriteexposecount;BatchedMeshsupports per-instance opacity and wireframes.- Physically based output changed through corrected blending, GGX VNDF PMREM sampling, direct-light multi-scattering compensation, and energy-conservation fixes. Revalidate image baselines after upgrades.
- Geometry without normals is flat-shaded automatically, but
ProgressiveLightMapstill requires normals. CapsuleGeometryusesheightandheightSegments;TorusGeometryaddsthetaStartandthetaLength.- Quaternion slerp extrapolates outside
[0, 1]. - Use
Timerfor new timing code instead of deprecatedClock.
Working method
- Read the installed
threeversion and identify direct imports fromthree/addons, TSL, renderer internals, and copied example assets. - Search the migration reference for every imported symbol and directly accessed renderer or node property.
- Read the topic reference for the subsystem being changed; many rendering changes alter output without causing an exception.
- Update application code and asset URLs together when an addon, decoder, or packaged resource moved.
- Exercise both WebGL and WebGPU paths when the application supports both.
- Re-run image comparisons, animation tests, serializer fixtures, and XR or input smoke tests affected by the change.
When code depends on renderer internals, inspect the installed source before choosing a property or class name. Internal renderer and node-pipeline surfaces have changed more often than public scene APIs.