threepipe
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

STLLoadPlugin.ts 1.3KB

123456789101112131415161718192021222324252627282930313233343536
  1. import {IViewerPluginSync, ThreeViewer} from '../../viewer'
  2. import {ILoader, Importer} from '../../assetmanager'
  3. import {STLLoader} from 'three/examples/jsm/loaders/STLLoader.js'
  4. import {BufferGeometry, Color, Mesh} from 'three'
  5. import {AnyOptions} from 'ts-browser-helpers'
  6. import {PhysicalMaterial} from '../../core'
  7. /**
  8. * Adds support for loading `.stl`, `model/stl` files and data uris.
  9. * @category Plugins
  10. */
  11. export class STLLoadPlugin implements IViewerPluginSync {
  12. declare ['constructor']: typeof STLLoadPlugin
  13. public static readonly PluginType = 'STLLoadPlugin'
  14. private _importer = new Importer(class extends STLLoader implements ILoader {
  15. transform(res: BufferGeometry, _: AnyOptions): Mesh|undefined {
  16. if (!res.attributes?.normal) res.computeVertexNormals()
  17. // todo set mesh name from options/path
  18. return res ? new Mesh(res, new PhysicalMaterial({color: new Color(1, 1, 1)})) : undefined
  19. }
  20. }, ['stl'], ['model/stl', 'model/x.stl-binary', 'model/x.stl-ascii'], false)
  21. onAdded(viewer: ThreeViewer) {
  22. viewer.assetManager.importer.addImporter(this._importer)
  23. }
  24. onRemove(viewer: ThreeViewer) {
  25. viewer.assetManager.importer.removeImporter(this._importer)
  26. }
  27. dispose() {
  28. return
  29. }
  30. }