Capítulo 201 de 859
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:
const loader = new STLLoader();
const geometry = await loader.loadAsync( './models/stl/slotted_disk.stl' )
scene.add( new THREE.Mesh( geometry ) );
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);
import { STLLoader } from 'three/addons/loaders/STLLoader.js';
Constructor
| Signature |
|---|
new STLLoader( manager : LoadingManager ) |
Methods
| Method | Description |
|---|---|
.load( url : string, onLoad : function, onProgress : onProgressCallback, onError : onErrorCallback ) | Starts loading from the given URL and passes the loaded STL asset to the onLoad() callback. |
.parse( data : ArrayBuffer ) : BufferGeometry | Parses the given STL data and returns the resulting geometry. |