threepipe
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import {_testFinish, AssetExporterPlugin, downloadBlob, IObject3D, LoadingScreenPlugin, ThreeViewer} from 'threepipe'
  2. import {createSimpleButtons} from '../examples-utils/simple-bottom-buttons.js'
  3. import {GLTFDracoExportPlugin} from '@threepipe/plugin-gltf-transform'
  4. const viewer = new ThreeViewer({
  5. canvas: document.getElementById('mcanvas') as HTMLCanvasElement,
  6. dropzone: {
  7. addOptions: {
  8. disposeSceneObjects: true,
  9. },
  10. },
  11. msaa: true,
  12. })
  13. async function init() {
  14. viewer.addPluginSync(LoadingScreenPlugin)
  15. viewer.addPluginSync(AssetExporterPlugin)
  16. viewer.addPluginSync(GLTFDracoExportPlugin)
  17. // Note: see asset-exporter-plugin example as well
  18. // load obj + mtl
  19. await viewer.setEnvironmentMap('https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr')
  20. const helmet = await viewer.load<IObject3D>('https://threejs.org/examples/models/gltf/DamagedHelmet/glTF/DamagedHelmet.gltf', {
  21. autoCenter: true,
  22. autoScale: true,
  23. })
  24. if (!helmet) {
  25. console.error('Unable to load model')
  26. return
  27. }
  28. const mesh = helmet.getObjectByName('node_damagedHelmet_-6514')!
  29. // const blob = await viewer.export(helmetObject, {exportExt: 'glb'})
  30. // const blob = await viewer.exportScene({viewerConfig: false}) // export scene without viewer config
  31. // const blob = await viewer.exportScene() // export scene with viewer config and default settings.
  32. createSimpleButtons({
  33. ['Download Helmet Object GLB + DRACO']: async() => {
  34. const blob = await viewer.export(mesh, {
  35. exportExt: 'glb',
  36. embedUrlImages: true, // embed images in glb even when url is available.
  37. compress: true,
  38. })
  39. if (!blob) {
  40. alert('Unable to export helmet object')
  41. return
  42. }
  43. downloadBlob(blob, 'helmet.' + blob.ext)
  44. },
  45. ['Download Scene GLB (Without Viewer Config) + DRACO']: async() => {
  46. const blob = await viewer.exportScene({viewerConfig: false, compress: true})
  47. if (!blob || blob.ext !== 'glb') {
  48. alert('Unable to export scene')
  49. return
  50. }
  51. downloadBlob(blob, 'scene.glb')
  52. },
  53. ['Download Scene GLB (With Viewer Config) + DRACO']: async() => {
  54. const blob = await viewer.exportScene({viewerConfig: true, compress: true})
  55. if (!blob || blob.ext !== 'glb') {
  56. alert('Unable to export scene')
  57. return
  58. }
  59. downloadBlob(blob, 'scene_with_config.glb')
  60. },
  61. })
  62. }
  63. init().finally(_testFinish)