Skip to content
Tutorials Center
My learning

Topics

Lesson 23 of 39 ยท Textures and Loading Models

OBJ, STL, FBX and the LoadingManager

Load OBJ, STL, PLY and FBX files in Three.js, export OBJ and STL, and build progress bars with LoadingManager, caching and custom loaders. Runnable examples.

glTF is the best format for the web, but you will meet others: an engineer sends an STL for a 3D-printed part, a scan comes as PLY, an old asset pack ships OBJ with an MTL file, and a game studio hands you FBX. Three.js has an add-on loader for each of them, and they all work the same way: create a loader, call load or parse, and receive geometry or an object.

This lesson tours the common formats, shows how to export, and then covers the tool that ties loading together: the LoadingManager, which lets you show one progress bar for dozens of files.

Which format when

Format Contains Typical use Loader
glTF / GLB Meshes, PBR materials, textures, rigs, animations The default for web delivery GLTFLoader
OBJ (+ MTL) Static geometry, simple materials Old asset packs, simple exchange OBJLoader, MTLLoader
STL Triangles only, no color 3D printing, CAD STLLoader
PLY Points or triangles, optional vertex colors Scans, point clouds PLYLoader
FBX Meshes, materials, skeletons, animations Game pipelines FBXLoader
USDZ Apple AR scenes AR on iOS USDZLoader (limited)

All of them live in three/addons/loaders/. Loaders that return geometry (STLLoader, PLYLoader) leave the material choice to you; loaders that return an object (OBJLoader, FBXLoader, GLTFLoader) give you a ready-to-add group.

OBJ and STL

An OBJ file is plain text: lines starting v are vertices, vn normals, vt UVs and f faces. That makes it easy to understand. An STL file (binary or ASCII) lists triangles and their normals, nothing more.

Both loaders have a parse method that accepts file contents, so you can try them without a server:

Parsing OBJ and STL text

Two details worth remembering. First, OBJ faces with four corners are split into triangles by the loader, which is why the vertex count is larger than the five v lines. Second, real OBJ files reference an .mtl file for colors; load it first with MTLLoader, call materials.preload(), then objLoader.setMaterials(materials). If the model comes out white, the MTL step or its texture paths are usually the cause.

FBX and PLY

FBXLoader is the most capable of the old formats: it brings skeletons and animation clips (in object.animations). FBX files are heavy, and large ones are slow to parse, so convert them to glTF when you control the pipeline (the free tool FBX2glTF or Blender both do it). FBX models often use centimetres, so check the size with Box3 as in the glTF lesson.

JavaScript
import { FBXLoader } from 'three/addons/loaders/FBXLoader.js';
const fbx = await new FBXLoader().loadAsync('/models/character.fbx');
fbx.scale.setScalar(0.01);
scene.add(fbx);
mixer = new THREE.AnimationMixer(fbx);
mixer.clipAction(fbx.animations[0]).play();

PLYLoader returns geometry, and if the file has per-vertex colors it adds a color attribute. To show them, set vertexColors: true on the material, or render as THREE.Points for a scan.

Exporting

Three.js can write several formats too. OBJExporter and STLExporter return strings (or DataView for binary STL); GLTFExporter handles glTF/GLB; PLYExporter and USDZExporter exist for their formats. To let a visitor download the result, wrap the text in a Blob and click a hidden link:

JavaScript
const blob = new Blob([text], { type: 'text/plain' });
const a = document.createElement('a');
a.href = URL.createObjectURL(blob);
a.download = 'shape.obj';
a.click();
URL.revokeObjectURL(a.href);

Exporting is how an in-browser editor (a product customizer, a level builder) saves its work.

The LoadingManager

Every loader accepts a LoadingManager in its constructor. The manager counts how many items have started, finished or failed across all the loaders that share it, and calls your functions:

JavaScript
const manager = new THREE.LoadingManager();
manager.onStart    = (url, loaded, total) => {};
manager.onProgress = (url, loaded, total) => { bar.style.width = (loaded / total * 100) + '%'; };
manager.onLoad     = () => hideSpinner();     // everything finished
manager.onError    = (url) => console.warn('failed:', url);

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

A GLTFLoader that uses the manager also reports the textures and .bin files the model itself pulls in, so a single progress bar covers the whole scene. Add manager.setURLModifier((url) => ...) if you need to rewrite URLs (for instance to serve from a CDN or to map names to blobs).

One progress bar for several textures

The manager waits until all five images are in before onLoad fires. In a real app you would fade out a loading screen at that moment instead of calling start() directly.

THREE.Cache and custom loading

Setting THREE.Cache.enabled = true makes FileLoader (the base of most loaders) remember downloaded files in memory, so loading the same URL twice does not hit the network again. It is off by default; turn it on when many objects reference the same texture URL. For anything else (your own JSON level format, binary data), use THREE.FileLoader directly with setResponseType('arraybuffer'), or just fetch and feed the data to a parse method.

Round trip with an exporter

To see how the two directions fit, this example exports a torus knot to OBJ text, counts the lines, and loads the text back with OBJLoader:

Export to OBJ and load it back

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. STLLoader returns which kind of object?

    STL files hold only triangles. The loader gives geometry and you wrap it in a Mesh with the material you want.
  2. 2. What does LoadingManager.onLoad signal?

    onLoad fires when all items registered with the manager are done. onProgress fires per item and onStart when loading begins.
  3. 3. Why are .obj files often rendered white or untextured?

    OBJ references an MTL file for colors and textures. Load it with MTLLoader and call setMaterials, and make sure texture paths resolve.
  4. 4. Which loader is the best choice when you control the pipeline and want the smallest, fastest web delivery?

    glTF/GLB is designed for runtime loading and supports Draco, Meshopt and KTX2 compression.

Summary

  • Add-on loaders exist for OBJ, MTL, STL, PLY, FBX and more; geometry loaders leave the material to you, object loaders return ready groups.
  • parse loads from memory, load and loadAsync fetch from a URL.
  • Exporters (OBJ, STL, PLY, glTF) let you save or download scenes.
  • A shared LoadingManager gives one progress bar and one "all loaded" event.
  • Prefer glTF for delivery and convert FBX or OBJ assets when you can.

Next: The Animation Loop and Timing