Three.js Loaders
Targets three.js r186. Examples use WebGLRenderer; the WebGPU and TSL section uses WebGPURenderer.
Quick Start
import * as THREE from "three";
import { GLTFLoader } from "three/addons/loaders/GLTFLoader.js";
import { RoomEnvironment } from "three/addons/environments/RoomEnvironment.js";
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.environment = new THREE.PMREMGenerator(renderer).fromScene(new RoomEnvironment(), 0.04).texture; // glTF PBR materials render black without lights or an environment
const camera = new THREE.PerspectiveCamera(50, window.innerWidth / window.innerHeight, 0.1, 100);
camera.position.set(2, 1.5, 3);
camera.lookAt(0, 0, 0);
const gltf = await new GLTFLoader().loadAsync("model.glb");
scene.add(gltf.scene);
function animate() {
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);LoadingManager
One manager coordinates several loaders and reports combined progress. loadAsync still rejects on failure; manager.onError fires as well.
import { GLTFLoader } from "three/addons/loaders/GLTFLoader.js";
const manager = new THREE.LoadingManager();
manager.onStart = (url, loaded, total) => {
manager.abort() cancels in-flight requests for loaders that load through FileLoader (models, HDR, EXR, KTX2). Loaders that load through an HTML image element, such as TextureLoader, ignore it.
import { GLTFLoader } from "three/addons/loaders/GLTFLoader.js";
const manager = new THREE.LoadingManager();
const timeoutId = setTimeout(() => manager.abort(), 30000);
try {
const gltf = await
Texture Loading
TextureLoader.load() returns the texture immediately and fills it in when the image decodes; assign it right away and the first render picks it up. Adding a map to a material that has already rendered without one needs material.needsUpdate = true. onProgress is never called for image loading.
new THREE.TextureLoader().load(
"texture.jpg",
(map) => {
map.colorSpace = THREE.SRGBColorSpace; // a color map; scalar maps keep NoColorSpace
mesh.material.map = map;
mesh.material.needsUpdate = true; // the material rendered without a map before
},
Texture configuration
const map = new THREE.TextureLoader().load("color.jpg");
map.colorSpace = THREE.SRGBColorSpace; // LDR color images; scalar maps keep NoColorSpace
map.wrapS = THREE.RepeatWrapping; // ClampToEdgeWrapping (default), RepeatWrapping, MirroredRepeatWrapping
Color spaces: LDR color images (albedo, emissive) are SRGBColorSpace; scalar maps (normal, bump, roughness, metalness, ao, alpha) keep the default NoColorSpace. GLTFLoader sets the correct color spaces for the textures it loads, and the HDR loaders below set LinearSRGBColorSpace themselves. A texture you load yourself for a glTF model's material needs map.flipY = false to match the textures GLTFLoader loads.
CubeTextureLoader
For skyboxes and cube environments, six faces in +X, -X, +Y, -Y, +Z, -Z order; the loader sets sRGB itself.
const cubeTexture = await new THREE.CubeTextureLoader().loadAsync([
"px.jpg",
"nx.jpg",
"py.jpg",
"ny.jpg",
"pz.jpg",
"nz.jpg",
]);
scene.background = cubeTexture;
scene.environment = cubeTexture;HDR Environments
HDRLoader (Radiance .hdr) and EXRLoader return floating-point equirectangular textures. Both renderers prefilter an equirectangular environment themselves, so no PMREM step is needed for a file — set mapping and assign it.
import { HDRLoader } from "three/addons/loaders/HDRLoader.js";
import { EXRLoader } from "three/addons/loaders/EXRLoader.js";
const env = await new HDRLoader().loadAsync("environment.hdr");
env.mapping = THREE.EquirectangularReflectionMapping;
scene.environment =
Dim the environment with scene.environmentIntensity (and rotate it with scene.environmentRotation); material.envMapIntensity scales only a material's own envMap, which stays null on models lit by scene.environment.
UltraHDRLoader reads gain-map JPEGs — HDR dynamic range at JPEG file sizes — the same way:
import { UltraHDRLoader } from "three/addons/loaders/UltraHDRLoader.js";
const env = await new UltraHDRLoader().loadAsync("environment.jpg");
env.mapping = THREE.EquirectangularReflectionMapping;
scene.environment = env;Use PMREMGenerator for generated environments, not files:
import { RoomEnvironment } from "three/addons/environments/RoomEnvironment.js";
const pmremGenerator = new THREE.PMREMGenerator(renderer);
const room = new RoomEnvironment();
scene.environment = pmremGenerator.fromScene(room, 0.04).texture;
room.dispose(); pmremGenerator.glTF and GLB
The primary format for web delivery. The result carries scene, animations, cameras, asset (version, generator) and userData (authoring custom data).
import { GLTFLoader } from "three/addons/loaders/GLTFLoader.js";
const gltf = await new GLTFLoader().loadAsync("model.glb");
scene.add(gltf.scene);
if (gltf.animations.length > 0) {
const mixer
Draco, meshopt and KTX2 compression
The Draco decoder and the Basis transcoder load from the three package by default; call setDecoderPath / setTranscoderPath only when you host them yourself, and then pin the path to the three release you ship. A file that requires EXT_meshopt_compression or KHR_meshopt_compression fails to load unless setMeshoptDecoder is set.
import { GLTFLoader } from "three/addons/loaders/GLTFLoader.js";
import { DRACOLoader } from "three/addons/loaders/DRACOLoader.js";
import { KTX2Loader } from "three/addons/loaders/KTX2Loader.js";
import { MeshoptDecoder } from "three/addons/libs/meshopt_decoder.module.js";
const gltfLoader = new GLTFLoader()
Processing loaded content
import { GLTFLoader } from "three/addons/loaders/GLTFLoader.js";
const gltf = await new GLTFLoader().loadAsync("model.glb");
const model = gltf.scene;
model.traverse((
Other Model Formats
OBJ + MTL
import { MTLLoader } from "three/addons/loaders/MTLLoader.js";
import { OBJLoader } from "three/addons/loaders/OBJLoader.js";
const materials = await new MTLLoader().loadAsync("model.mtl");
materials.preload();
const object = await new OBJLoader
FBX
import { FBXLoader } from "three/addons/loaders/FBXLoader.js";
const object = await new FBXLoader().loadAsync("model.fbx");
object.scale.setScalar(0.01); // FBX files are often exported in centimeters
const mixer = new THREE.AnimationMixer
STL
import { STLLoader } from "three/addons/loaders/STLLoader.js";
const geometry = await new STLLoader().loadAsync("model.stl");
scene.add(new THREE.Mesh(geometry, new THREE.MeshStandardMaterial({ color: 0x888888
PLY
The loader honors the file's data types, so double properties arrive as attributes backed by a Float64Array, which WebGLRenderer cannot upload; convert them to Float32BufferAttribute before rendering.
import { PLYLoader } from "three/addons/loaders/PLYLoader.js";
const geometry = await new PLYLoader().loadAsync("model.ply");
for (const name of Object.keys
USD
import { USDLoader } from "three/addons/loaders/USDLoader.js";
const model = await new USDLoader().loadAsync("model.usdz"); // USD, USDA, USDC and USDZ archives
scene.add(model);Async Patterns and Custom Sources
Load independent assets in parallel:
import { GLTFLoader } from "three/addons/loaders/GLTFLoader.js";
import { HDRLoader } from "three/addons/loaders/HDRLoader.js";
const [model, environment, colorMap] = await Promise.all([
new GLTFLoader().loadAsync
Parse data you already hold (a downloaded file, a file input, a database record):
import { GLTFLoader } from "three/addons/loaders/GLTFLoader.js";
const response = await fetch("model.glb");
const buffer = await response.arrayBuffer();
const gltf = await new GLTFLoader().parseAsync(buffer, "");
Blob URLs and data URLs work as loader URLs:
async function loadTextureFromBlob(blob) {
const url = URL.createObjectURL(blob);
const texture = await new THREE.TextureLoader().loadAsync(url);
URL.revokeObjectURL(url);
return texture;
}Prefix paths and rewrite URLs through the manager:
import { GLTFLoader } from "three/addons/loaders/GLTFLoader.js";
const loader = new GLTFLoader();
loader.setPath("assets/models/"); // prefix for the URL you pass to load
loader.setResourcePath("assets/textures/"); // where the file's own references resolve
const gltf
Enable the shared cache to serve repeated URLs from memory:
THREE.Cache.enabled = true;
THREE.Cache.clear(); // empty it when you need to force reloadsKeep payloads small — Draco or meshopt for geometry, KTX2 for textures, produced as in threejs-asset-pipeline — and show a placeholder mesh while the real model loads, swapping it in once loading resolves.
Cloning and Disposal
Object3D.clone() on a skinned model shares the skeleton: every copy stays bound to the original's bones, so copies follow the original and ignore their own animation. Use SkeletonUtils.clone() for instances.
import { GLTFLoader } from "three/addons/loaders/GLTFLoader.js";
import * as SkeletonUtils from "three/addons/utils/SkeletonUtils.js";
const gltf = await new GLTFLoader().loadAsync("character.glb");
scene.add(gltf.scene);
const copy = SkeletonUtils.
object.dispose() frees renderer-side state for that object only (WebGPU bindings, InstancedMesh buffers) and does not visit children or dispose geometry, materials or textures — traverse the subtree:
import { GLTFLoader } from "three/addons/loaders/GLTFLoader.js";
const gltf = await new GLTFLoader().loadAsync("model.glb");
const model = gltf.scene;
scene.add(model);
// ... later
scene.
WebGPU and TSL
import * as THREE from "three/webgpu";
import { GLTFLoader } from "three/addons/loaders/GLTFLoader.js";
import { RoomEnvironment } from "three/addons/environments/RoomEnvironment.js";
const renderer =
ktx2Loader.detectSupport(renderer)and thePMREMGeneratormethods (fromScene,fromEquirectangular,fromCubemap) throw beforeawait renderer.init(). Max anisotropy isrenderer.getMaxAnisotropy();renderer.capabilitiesdoes not exist under WebGPURenderer.- Gaussian splats:
SPLATLoader,SPZLoader,KSPLATLoaderandGaussianSplatPLYLoaderload data fornew GaussianSplat(data)fromthree/addons/objects/GaussianSplat.js, which requires WebGPURenderer.
Common Mistakes
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js"→import { GLTFLoader } from "three/addons/loaders/GLTFLoader.js": thethree/examples/jsm/specifier does not resolve under the import map three.js documents.import { RGBELoader } from "three/addons/loaders/RGBELoader.js"→import { HDRLoader } from "three/addons/loaders/HDRLoader.js": renamed from RGBELoader in r180; the old class warns on every construction.new Promise((resolve, reject) => loader.load(url, resolve, undefined, reject))→loader.loadAsync(url): every loader already implements loadAsync, which rejects on error.material.map = new THREE.TextureLoader().load("color.jpg")→const map = new THREE.TextureLoader().load("color.jpg"); map.colorSpace = THREE.SRGBColorSpace; material.map = map;: a loaded color map defaults to NoColorSpace and renders washed out.normalMap.colorSpace = THREE.LinearSRGBColorSpace→normalMap.colorSpace = THREE.NoColorSpace: scalar maps (normal, bump, roughness, metalness, ao, alpha) keep NoColorSpace; LinearSRGBColorSpace is for linear color data.texture.encoding = THREE.sRGBEncoding→ : encoding and sRGBEncoding no longer exist, so the old line leaves the map at NoColorSpace and it renders washed out.
See Also
threejs-fundamentals- renderer setup, resize handling and the app scaffold around loaded assetsthreejs-texturesandthreejs-materials- texture properties and color spaces, and adjusting the materials loaded models come withthreejs-asset-pipeline- compressing and optimizing glTF files before they reach these loadersthreejs-animation- AnimationMixer, clips and skinned-mesh playback