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ů.

script.ts 2.7KB

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