Overview
The OBJ/MTL loader enables you to load 3D models in the Wavefront OBJ format with optional MTL (Material Template Library) files. This is one of the most common 3D model formats and is widely supported by modeling software.Usage
Parameters
Loader type. Use
'mtl' for OBJ files (this is the default if not specified).URL or path to the OBJ model file.
URL or path to the MTL material file. Optional but recommended for textured models.If not provided, the model will load with default materials.
Units for the model scale. Options:
'scene'- Scene units (default)'meters'- Meters
Scale factor for the model. Can be:
- A single number:
1(uniform scale) - An array:
[x, y, z]for per-axis scaling
scale: [2, 2, 2] or scale: 2Rotation for the model in degrees. Can be:
- A single number:
90(rotation around Y axis) - An object:
{ x: 90, y: 0, z: 0 } - An array:
[90, 0, 0](X, Y, Z rotation)
Anchor point for the model positioning. Options:
'center'- Center of the model'bottom-left'- Bottom-left corner'bottom-right'- Bottom-right corner'top-left'- Top-left corner'top-right'- Top-right corner'bottom-center'- Bottom center'top-center'- Top center'left'- Left center'right'- Right center
Manual adjustment to override the automatic center calculation.Example:
{ x: 0, y: 0, z: 0 }Whether the model should be included in raycasting for mouse interactions.
Whether to calculate and display a bounding box for the model.
Whether to enable tooltips for the model.
Whether to clone the model when adding multiple instances.
Whether to send cookies and authorization headers with cross-origin requests.Applies to both OBJ and MTL file requests.
Callback
The callback function receives the loaded model object with the following properties:Model Structure
OBJ/MTL models are loaded with the following structure:- The first child of the loaded OBJ becomes the root object
- Materials from the MTL file are applied automatically
- Multiple meshes and groups are preserved
- Texture paths in MTL are resolved relative to the MTL file location
/home/daytona/workspace/source/src/objects/loadObj.js:68-70:
Material Loading
The MTL file is loaded first, then applied to the OBJ model:/home/daytona/workspace/source/src/objects/loadObj.js:44-60
If the MTL file fails to load, the model will still load with default gray materials.
Examples
Basic OBJ with Materials
OBJ without MTL (Default Materials)
Multiple OBJ Instances
Custom Anchor Point
Texture Paths
Texture references in MTL files should be relative paths or absolute URLs:Common Issues
MTL Not Loading
If materials don’t appear:- Check the browser console for MTL loading errors
- Verify the MTL path is correct and accessible
- Ensure CORS headers are set if loading from a different domain
- Use
withCredentials: trueif authentication is required