agentleFS
komogortevkomogortev/threejs-skills/skills/threejs-loaders/SKILL.md

threejs-loaders

Skill1 starsChanged 8 months agoMITView on GitHub

Three.js asset loading - GLTF, textures, images, models, async patterns. Use when loading 3D models, textures, HDR environments, or managing loading progress.

9 other projects use a version of this, 8 of them edited.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

3 rules. 0 are common, 2 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 8 edited versions we read keep these.

  • 2

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use Draco compression for large geometry

    line 181
  2. Distinctive:

    Use KTX2/Basis for textures

    line 182
  3. Very specific:

    Use loader.setPath() to avoid repeating base paths

    line 184

“Common” is measured: kept by at least 6 in 10 of the 8 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Three.js Loaders

Quick Start

import * as THREE from "three";
import { GLTFLoader } from "three/addons/loaders/GLTFLoader.js";

const loader = new GLTFLoader();
loader.load("model.glb", (gltf) => {
  scene.add(gltf.scene);
});

const textureLoader = new THREE.TextureLoader();
const texture = textureLoader.load("texture.jpg");

LoadingManager

const manager = new THREE.LoadingManager();
manager.onLoad = () => startGame();
manager.onProgress = (url, loaded, total) => {
  updateProgressBar((loaded / total) * 100);
};
manager.onError = (url) => console.error(`Error loading: ${url}`);

const gltfLoader = new GLTFLoader(manager);
const textureLoader = new THREE.TextureLoader(manager);

GLTF/GLB Loading

import { GLTFLoader } from "three/addons/loaders/GLTFLoader.js";

const loader = new GLTFLoader();
loader.load("model.glb", (gltf) => {
  const model = gltf.scene;
  scene.add(model);

  // Animations
  if (gltf.animations.length > 0) {
    const mixer = new THREE.AnimationMixer(model);
    gltf.animations.forEach((clip) => mixer.clipAction(clip).play());
  }
});

With Draco Compression

import { DRACOLoader } from "three/addons/loaders/DRACOLoader.js";

const dracoLoader = new DRACOLoader();
dracoLoader.setDecoderPath("https://www.gstatic.com/draco/versioned/decoders/1.5.6/");

const gltfLoader = new GLTFLoader();
gltfLoader.setDRACOLoader(dracoLoader);
gltfLoader.load("model.glb", (gltf) => scene.add(gltf.scene));

FBX Loading

import { FBXLoader } from "three/addons/loaders/FBXLoader.js";

const loader = new FBXLoader();
loader.load("model.fbx", (object) => {
  object.scale.setScalar(0.01); // Mixamo exports at 100x scale

  const mixer = new THREE.AnimationMixer(object);
  object.animations.forEach((clip) => mixer.clipAction(clip).play());

  scene.add(object);
});

Texture Loading

const loader = new THREE.TextureLoader();
loader.load("texture.jpg", (tex) => {
  tex.colorSpace = THREE.SRGBColorSpace; // For albedo/color maps
  tex.wrapS = THREE.RepeatWrapping;
  tex.wrapT = THREE.RepeatWrapping;
  tex.repeat.set(2, 2);
  tex.anisotropy = renderer.capabilities.getMaxAnisotropy();
  material.map = tex;
  material.needsUpdate = true;
});

HDR Environment

import { RGBELoader } from "three/addons/loaders/RGBELoader.js";

const pmremGenerator = new THREE.PMREMGenerator(renderer);
pmremGenerator.compileEquirectangularShader();

new RGBELoader().load("environment.hdr", (texture) => {
  const envMap = pmremGenerator.fromEquirectangular(texture).texture;
  scene.environment = envMap;
  scene.background = envMap;
  texture.dispose();
  pmremGenerator.dispose();
});

Async/Promise Patterns

// Promisify any loader
function loadGLTF(url) {
  return new Promise((resolve, reject) => {
    new GLTFLoader().load(url, resolve, undefined, reject);
  });
}

// Load multiple in parallel
async function loadAssets() {
  const [model, envTexture] = await Promise.all([
    loadGLTF("model.glb"),
    loadRGBE("environment.hdr"),
  ]);
  scene.add(model.scene);
  scene.environment = envTexture;
}

Parse from ArrayBuffer

const response = await fetch("model.glb");
const buffer = await response.arrayBuffer();

new GLTFLoader().parse(buffer, "", (gltf) => {
  scene.add(gltf.scene);
});

Caching

THREE.Cache.enabled = true; // Enable built-in URL cache

// Manual cache
const modelCache = new Map();
async function loadCached(url) {
  if (modelCache.has(url)) return modelCache.get(url).clone();
  const gltf = await loadGLTF(url);
  modelCache.set(url, gltf.scene);
  return gltf.scene.clone();
}

Error Handling

async function loadWithRetry(url, maxRetries = 3) {
  for (let i = 0; i < maxRetries; i++) {
    try {
      return await loadGLTF(url);
    } catch (error) {
      if (i === maxRetries - 1) throw error;
      await new Promise((r) => setTimeout(r, 1000 * (i + 1)));
    }
  }
}

Performance Tips

  1. Use Draco compression for large geometry
  2. Use KTX2/Basis for textures
  3. Enable THREE.Cache.enabled = true
  4. Use loader.setPath() to avoid repeating base paths
  5. Load progressively — show placeholder while loading

See Also

  • threejs-fbx-mixamo — Multi-FBX Mixamo animation loading pipeline
  • threejs-animation — Playing loaded animations

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.