File: STLLoader.md | Updated: 11/15/2025
A loader for the STL format, as created by Solidworks and other CAD programs.
Supports both binary and ASCII encoded files. The loader returns a non-indexed buffer geometry.
Limitations:
For binary STLs geometry might contain colors for vertices. To use it:
// use the same code to load STL as above
if ( geometry.hasColors ) {
material = new THREE.MeshPhongMaterial( { opacity: geometry.alpha, vertexColors: true } );
}
const mesh = new THREE.Mesh( geometry, material );
For ASCII STLs containing multiple solids, each solid is assigned to a different group. Groups can be used to assign a different color by defining an array of materials with the same length of geometry.groups and passing it to the Mesh constructor:
const materials = [];
const nGeometryGroups = geometry.groups.length;
for ( let i = 0; i < nGeometryGroups; i ++ ) {
const material = new THREE.MeshPhongMaterial( { color: colorMap[ i ], wireframe: false } );
materials.push( material );
}
const mesh = new THREE.Mesh(geometry, materials);
const loader = new STLLoader();
const geometry = await loader.loadAsync( './models/stl/slotted_disk.stl' )
scene.add( new THREE.Mesh( geometry ) );
STLLoader is an addon, and must be imported explicitly, see Installation#Addons.
import { STLLoader } from 'three/addons/loaders/STLLoader.js';
Constructs a new STL loader.
manager | The loading manager.
---|---
Starts loading from the given URL and passes the loaded STL asset to the onLoad() callback.
url | The path/URL of the file to be loaded. This can also be a data URI.
---|---
onLoad | Executed when the loading process has been finished.
onProgress | Executed while the loading is in progress.
onError | Executed when errors occur.
Overrides: Loader#load
Parses the given STL data and returns the resulting geometry.
data | The raw STL data as an array buffer.
---|---
Overrides: Loader#parse
Returns: The parsed geometry.