threepipe
Version:
A modern 3D viewer framework built on top of three.js, written in TypeScript, designed to make creating high-quality, modular, and extensible 3D experiences on the web simple and enjoyable.
27 lines • 1.11 kB
JavaScript
import { Importer } from '../../assetmanager';
import { STLLoader } from 'three/examples/jsm/loaders/STLLoader.js';
import { Color, Mesh } from 'three';
import { PhysicalMaterial } from '../../core';
import { BaseImporterPlugin } from '../base/BaseImporterPlugin';
/**
* Adds support for loading `.stl`, `model/stl` files and data uris.
* @category Plugins
*/
export class STLLoadPlugin extends BaseImporterPlugin {
constructor() {
super(...arguments);
this._importer = new Importer(class extends STLLoader {
transform(res, _) {
if (!res.attributes?.normal)
res.computeVertexNormals();
// todo set mesh name from options/path
return res ? new Mesh(res, new PhysicalMaterial({
color: new Color(1, 1, 1),
vertexColors: res.hasAttribute('color'),
})) : undefined;
}
}, ['stl'], ['model/stl', 'model/x.stl-binary', 'model/x.stl-ascii'], false);
}
}
STLLoadPlugin.PluginType = 'STLLoadPlugin';
//# sourceMappingURL=STLLoadPlugin.js.map