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

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