STLLoader class

Description: A THREE loader for STL ASCII files, as created by Solidworks and other CAD programs.

Supports both binary and ASCII encoded files, with automatic detection of type.

The loader returns a non-indexed buffer geometry.

Limitations: Binary decoding supports "Magics" color format. There is perhaps some question as to how valid it is to always assume little-endian-ness. ASCII decoding assumes file is UTF-8.

Usage:

 final loader = STLLoader();
 final geometry = await loader.fromAsset( 'assets/models/stl/slotted_disk.stl');
 scene.add(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 = MeshPhongMaterial({ MaterialProperty.opacity: geometry.alpha, MaterialProperty.vertexColors: true });
 } else { .... }
 final mesh = 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:

final mesh = Mesh( geometry, material );

For example:

 final materials = [];
 final nGeometryGroups = geometry.groups.length;

 final colorMap = ...; // Some logic to index colors.

 for (int i = 0; i < nGeometryGroups; i++) {

		final material = MeshPhongMaterial({
			MaterialProperty.color: colorMap[i],
			MaterialProperty.wireframe: false
		});

 }

 materials.add(material);
 final mesh = Mesh(geometry, materials);
Inheritance

Constructors

STLLoader.new([LoadingManager? manager])
manager — The loadingManager for the loader to use. Default is DefaultLoadingManager.

Properties

crossOrigin String
getter/setter pairinherited
flipY bool
getter/setter pairinherited
hashCode int
The hash code for this object.
no setterinherited
manager ↔ LoadingManager
getter/setter pairinherited
mimeType String
getter/setter pairinherited
path String
getter/setter pairinherited
requestHeader Map<String, dynamic>
getter/setter pairinherited
resourcePath String?
getter/setter pairinherited
responseType String
getter/setter pairinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
withCredentials bool
getter/setter pairinherited

Methods

dispose() → void
override
fromAsset(String asset, {String? package}) Future<Mesh?>
asset - path of the file to be loaded
override
fromBlob(Blob blob) Future<Mesh>
blob - a blob of the file to be loaded
override
fromBytes(Uint8List bytes) Future<Mesh>
bytes - the loaded bytes of the file
override
fromFile(File file) Future<Mesh>
file - the file to be loaded
override
fromNetwork(Uri uri) Future<Mesh?>
uri - a uri containing the location of the file to be loaded
override
fromPath(String filePath) Future<Mesh?>
filePath - path of the file to be loaded
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
setCrossOrigin(String crossOrigin) → Loader
crossOrigin — The crossOrigin string to implement CORS for loading the url from a different domain that allows CORS.
inherited
setPath(String path) → Loader
path — Set the base path for the asset.
inherited
setRequestHeader(Map<String, dynamic> requestHeader) → Loader
requestHeader - key: The name of the header whose value is to be set. value: The value to set as the body of the header.
inherited
setResourcePath(String? resourcePath) → Loader
resourcePath — Set the base path for dependent resources like textures.
inherited
setWithCredentials(bool value) → Loader
Whether the XMLHttpRequest uses credentials such as cookies, authorization headers or TLS client certificates. See XMLHttpRequest.withCredentials.
inherited
toString() String
A string representation of this object.
inherited
unknown(dynamic url) Future
url - a dynmaic data that gets parsed by the system
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited