Loading three.js assets: glTF with Draco, meshopt and KTX2 compression, other model formats, textures, HDR and EXR environments, progress, caching, cloning a…
Install the skill above, then run this in your AI tool:
/threejs-loaders <your description>
About
Targets three.js r186. Examples use WebGLRenderer; the WebGPU and TSL section uses WebGPURenderer.
Source
What gets added to your project
Preview every file this package writes on install before you run the command above.
Summary
js assets: glTF with Draco, meshopt and KTX2 compression, other model formats, textures, HDR and EXR environments, progress, caching, cloning and disposal. Use when loading 3D models, textures or environment maps, or managi...
Skill instructions
Three.js Loaders
Targets three.js r186. Examples use WebGLRenderer; the WebGPU and TSL section uses WebGPURenderer.
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.
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.
javascript
newTHREE.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
},
undefined, // onProgress: not supported for image loading(error) => {
console.error("Could not load texture", error);
},
);
Texture configuration
javascript
const map = newTHREE.TextureLoader().load("color.jpg");
map.colorSpace = THREE.SRGBColorSpace; // LDR color images; scalar maps keep NoColorSpace
map.wrapS = THREE.RepeatWrapping; // ClampToEdgeWrapping (default), RepeatWrapping, MirroredRepeatWrapping
map.wrapT = THREE.RepeatWrapping;
map.repeat.set(2, 2);
map.offset.set(0.5, 0.5);
map.rotation = Math.PI / 4;
map.center.set(0.5, 0.5);
map.minFilter = THREE.LinearMipmapLinearFilter; // default
map.magFilter = THREE.LinearFilter; // default; NearestFilter for a pixelated look
map.anisotropy = renderer.capabilities.getMaxAnisotropy(); // sharper textures at grazing angles
mesh.material.map = map;
// wrap, filters, anisotropy, colorSpace and flipY (true by default) apply at upload: set them before the first render or set map.needsUpdate = true; repeat, offset, rotation and center apply every frame
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.
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.
javascript
import { HDRLoader } from"three/addons/loaders/HDRLoader.js";
import { EXRLoader } from"three/addons/loaders/EXRLoader.js";
const env = awaitnewHDRLoader().loadAsync("environment.hdr");
env.mapping = THREE.EquirectangularReflectionMapping;
scene.environment = env;
scene.background = env; // without mapping, a background texture draws as a flat screen quadconst exr = awaitnewEXRLoader().loadAsync("environment.exr");
exr.mapping = THREE.EquirectangularReflectionMapping;
scene.environment = exr;
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:
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";
const gltf = awaitnewGLTFLoader().loadAsync("model.glb");
const model = gltf.scene;
model.traverse((child) => {
if (child.isMesh) {
child.castShadow = true; // shadows also need renderer.shadowMap.enabled = true and a light with castShadow
child.receiveShadow = true;
}
});
model.getObjectByName("Head"); // look up named nodes
scene.environmentIntensity = 0.5; // dim scene.environment for this scene// Center the model and scale it into a unit boxconst box = newTHREE.Box3().setFromObject(model);
const center = box.getCenter(newTHREE.Vector3());
const size = box.getSize(newTHREE.Vector3());
const scale = 1 / Math.max(size.x, size.y, size.z);
model.scale.setScalar(scale);
model.position.copy(center).multiplyScalar(-scale); // the offset is scaled too
scene.add(model);
import { FBXLoader } from"three/addons/loaders/FBXLoader.js";
const object = awaitnewFBXLoader().loadAsync("model.fbx");
object.scale.setScalar(0.01); // FBX files are often exported in centimetersconst mixer = newTHREE.AnimationMixer(object); // call mixer.update(timer.getDelta()) every frame, as in the glTF exampleif (object.animations.length > 0) mixer.clipAction(object.animations[0]).play();
scene.add(object);
STL
javascript
import { STLLoader } from"three/addons/loaders/STLLoader.js";
const geometry = awaitnewSTLLoader().loadAsync("model.stl");
scene.add(newTHREE.Mesh(geometry, newTHREE.MeshStandardMaterial({ color: 0x888888 })));
scene.add(newTHREE.HemisphereLight(0xffffff, 0x444444, 1));
scene.add(newTHREE.DirectionalLight(0xffffff, 2)); // lit materials render black without lights; this one shines down from (0, 1, 0)
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.
javascript
import { PLYLoader } from"three/addons/loaders/PLYLoader.js";
const geometry = awaitnewPLYLoader().loadAsync("model.ply");
for (const name ofObject.keys(geometry.attributes)) {
const attribute = geometry.getAttribute(name);
if (attribute.arrayinstanceofFloat64Array) {
geometry.setAttribute(name, newTHREE.Float32BufferAttribute(attribute.array, attribute.itemSize));
}
}
if (!geometry.hasAttribute("normal")) geometry.computeVertexNormals(); // keep the file's own normalsconst material = newTHREE.MeshStandardMaterial({ vertexColors: geometry.hasAttribute("color") }); // vertexColors without a color attribute renders black
scene.add(newTHREE.Mesh(geometry, material));
scene.add(newTHREE.HemisphereLight(0xffffff, 0x444444, 1));
scene.add(newTHREE.DirectionalLight(0xffffff, 2)); // lit materials render black without lights; this one shines down from (0, 1, 0)
USD
javascript
import { USDLoader } from"three/addons/loaders/USDLoader.js";
const model = awaitnewUSDLoader().loadAsync("model.usdz"); // USD, USDA, USDC and USDZ archives
scene.add(model);
Prefix paths and rewrite URLs through the manager:
javascript
import { GLTFLoader } from"three/addons/loaders/GLTFLoader.js";
const loader = newGLTFLoader();
loader.setPath("assets/models/"); // prefix for the URL you pass to load
loader.setResourcePath("assets/textures/"); // where the file's own references resolveconst gltf = await loader.loadAsync("model.glb"); // loads assets/models/model.glbconst manager = newTHREE.LoadingManager();
manager.setURLModifier((url) => url.replace("assets/", "https://cdn.example.com/assets/"));
const cdnGltf = awaitnewGLTFLoader(manager).loadAsync("assets/models/model.glb"); // fetched from https://cdn.example.com/assets/models/model.glb
Enable the shared cache to serve repeated URLs from memory:
javascript
THREE.Cache.enabled = true;
THREE.Cache.clear(); // empty it when you need to force reloads
Keep 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.
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:
javascript
import { GLTFLoader } from"three/addons/loaders/GLTFLoader.js";
const gltf = awaitnewGLTFLoader().loadAsync("model.glb");
const model = gltf.scene;
scene.add(model);
// ... later
scene.remove(model);
model.traverse((child) => {
child.dispose(); // per-object renderer state: InstancedMesh buffers, WebGPU bindingsif (child.geometry) { // meshes, lines and points
child.geometry.dispose();
const materials = Array.isArray(child.material) ? child.material : [child.material];
for (const material of materials) {
for (const value ofObject.values(material)) {
if (value?.isTexture) value.dispose();
}
material.dispose();
}
}
});
WebGPU and TSL
javascript
import * asTHREEfrom"three/webgpu";
import { GLTFLoader } from"three/addons/loaders/GLTFLoader.js";
import { RoomEnvironment } from"three/addons/environments/RoomEnvironment.js";
const renderer = newTHREE.WebGPURenderer({ antialias: true });
await renderer.init(); // before any other use of the renderer
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
const scene = newTHREE.Scene();
scene.background = newTHREE.Color(0x111827); // the WebGPU canvas is transparent by default
scene.environment = newTHREE.PMREMGenerator(renderer).fromScene(newRoomEnvironment(), 0.04).texture;
const camera = newTHREE.PerspectiveCamera(50, window.innerWidth / window.innerHeight, 0.1, 100);
camera.position.set(2, 1.5, 3);
camera.lookAt(0, 0, 0);
const gltf = awaitnewGLTFLoader().loadAsync("model.glb"); // loaded materials become node materials automatically
scene.add(gltf.scene);
functionanimate() { renderer.render(scene, camera); } renderer.setAnimationLoop(animate);
ktx2Loader.detectSupport(renderer) and the PMREMGenerator methods (fromScene, fromEquirectangular, fromCubemap) throw before await renderer.init(). Max anisotropy is renderer.getMaxAnisotropy(); renderer.capabilities does not exist under WebGPURenderer.
Gaussian splats: SPLATLoader, SPZLoader, KSPLATLoader and GaussianSplatPLYLoader load data for new GaussianSplat(data) from three/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": the three/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 → texture.colorSpace = THREE.SRGBColorSpace: encoding and sRGBEncoding no longer exist, so the old line leaves the map at NoColorSpace and it renders washed out.
child.material.envMapIntensity = 0.5 → scene.environmentIntensity = 0.5: envMapIntensity scales only material.envMap, which stays null when the model is lit by scene.environment.
scene.environment = pmremGenerator.fromEquirectangular(hdrTexture).texture → hdrTexture.mapping = THREE.EquirectangularReflectionMapping; scene.environment = hdrTexture;: both renderers run that PMREM step themselves for an equirectangular texture, so the manual pass only adds code and a render target to dispose.
scene.background = hdrTexture → hdrTexture.mapping = THREE.EquirectangularReflectionMapping; scene.background = hdrTexture;: without the mapping, a background texture draws as a flat screen quad.
ktx2Loader.setTranscoderPath(pathFromAnotherRelease) → const ktx2Loader = new KTX2Loader().detectSupport(renderer): the Basis transcoder and the Draco decoder load from the three package by default; a path pinned to another release mismatches the loader.
ktx2Loader.detectSupportAsync(renderer) → await renderer.init(); ktx2Loader.detectSupport(renderer);: detectSupportAsync is deprecated in r181; call detectSupport once the renderer is initialized.
renderer.capabilities.getMaxAnisotropy() → renderer.getMaxAnisotropy(): capabilities exists on WebGLRenderer only; under WebGPURenderer use the renderer method.
scene.add(new THREE.Mesh(await new PLYLoader().loadAsync("scan.ply"), material)) → const geometry = await new PLYLoader().loadAsync("scan.ply"); for (const [name, a] of Object.entries(geometry.attributes)) if (a.array instanceof Float64Array) geometry.setAttribute(name, new THREE.Float32BufferAttribute(a.array, a.itemSize)); scene.add(new THREE.Mesh(geometry, material));: PLYLoader keeps double properties as Float64 attributes, which WebGLRenderer cannot upload (it throws Unsupported buffer data format).
gltf.scene.clone() → SkeletonUtils.clone(gltf.scene): Object3D.clone() shares the skeleton, so every copy stays bound to the original's bones and follows its animation.
gltf.scene.dispose() → gltf.scene.traverse((child) => { child.geometry?.dispose(); for (const material of [child.material ?? []].flat()) { for (const value of Object.values(material)) if (value?.isTexture) value.dispose(); material.dispose(); } child.dispose(); }): Object3D.dispose() frees renderer state for that object only, never its geometry, materials or textures, and material.dispose() does not free the material's textures.
fetch(url, { signal: controller.signal }) → setTimeout(() => manager.abort(), 30000): loaders are cancelled through their LoadingManager, which aborts in-flight FileLoader requests.
new USDZLoader() → new USDLoader(): deprecated in r179; USDLoader reads USD, USDA, USDC and USDZ.
See Also
threejs-fundamentals - renderer setup, resize handling and the app scaffold around loaded assets
threejs-textures and threejs-materials - texture properties and color spaces, and adjusting the materials loaded models come with
threejs-asset-pipeline - compressing and optimizing glTF files before they reach these loaders
threejs-animation - AnimationMixer, clips and skinned-mesh playback
Add this badge to a GitHub README so readers can open the package page and install the same version.
[](https://www.aipm-registry.com/skills/cloudai-x/threejs-loaders/1.0.0?utm_source=github&utm_medium=readme&utm_campaign=package_badge)
This imported publisher has not claimed its AIPM account. A connected account confirms account control, but it does not guarantee that a package is safe.
AI assistant context
What this skill is for
@cloudai-x/threejs-loaders@1.0.0 is an AIPM skill package for All tools. Use it when a project needs the reusable AI behavior described as: Loading three.js assets: glTF with Draco, meshopt and KTX2 compression, other model formats, textures, HDR and EXR environments, progress, caching, cloning and disposal. Use when loading 3D models, textures or environment maps, or managi...
Shrinking glTF assets for three.js with gltf-transform: inspect, validate and optimize commands, Draco, meshopt and quantization, KTX2, WebP and AVIF textures, the loader setup each output needs, and gltfjsx for React. Use when compressi...
Three.js textures: image loading, color spaces, UV channels and transforms, texture types from canvas to HDR and KTX2, render targets, texture memory. Use when working with images on materials, UV coordinates, cubemaps, render targets or...
Picking with raycasting, camera controls, transform gizmos, drag, hover and box selection for three.js, identical under WebGL and WebGPU. Use when handling mouse, touch or keyboard input, detecting clicks on 3D objects, adding camera con...
Run aipm add @cloudai-x/threejs-loaders@1.0.0 in a project that has AIPM initialized.
Supported tools
@cloudai-x/threejs-loaders@1.0.0 supports All tools.
Before installing
AIPM skills can add files to your project. Review the package name, target, description, license, and publisher before installing. Use a clean branch when trying a new skill.