threepipe
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

STLLoadPlugin.ts 1.1KB

12345678910111213141516171819202122232425
  1. import {ILoader, Importer} from '../../assetmanager'
  2. import {STLLoader} from 'three/examples/jsm/loaders/STLLoader.js'
  3. import {BufferGeometry, Color, Mesh} from 'three'
  4. import {AnyOptions} from 'ts-browser-helpers'
  5. import {PhysicalMaterial} from '../../core'
  6. import {BaseImporterPlugin} from '../base/BaseImporterPlugin'
  7. /**
  8. * Adds support for loading `.stl`, `model/stl` files and data uris.
  9. * @category Plugins
  10. */
  11. export class STLLoadPlugin extends BaseImporterPlugin {
  12. public static readonly PluginType = 'STLLoadPlugin'
  13. protected _importer = new Importer(class extends STLLoader implements ILoader {
  14. transform(res: BufferGeometry, _: AnyOptions): Mesh|undefined {
  15. if (!res.attributes?.normal) res.computeVertexNormals()
  16. // todo set mesh name from options/path
  17. return res ? new Mesh(res, new PhysicalMaterial({
  18. color: new Color(1, 1, 1),
  19. vertexColors: res.hasAttribute('color'),
  20. })) : undefined
  21. }
  22. }, ['stl'], ['model/stl', 'model/x.stl-binary', 'model/x.stl-ascii'], false)
  23. }