threepipe
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import {_testFinish, _testStart, downloadBlob, IObject3D, LoadingScreenPlugin, ThreeViewer} from 'threepipe'
  2. const viewer = new ThreeViewer({canvas: document.getElementById('mcanvas') as HTMLCanvasElement, msaa: true,
  3. plugins: [LoadingScreenPlugin],
  4. })
  5. async function init() {
  6. // load obj + mtl
  7. const result = await viewer.load<IObject3D>('https://threejs.org/examples/models/obj/male02/male02.obj', {
  8. autoCenter: true,
  9. autoScale: true,
  10. })
  11. // todo wait for images to load
  12. // export to glb
  13. const blob = await viewer.export(result)
  14. // const blob = await viewer.exportScene(); // its possible to export the whole scene also
  15. if (!blob || blob.ext !== 'glb') {
  16. console.error('Unable to export scene')
  17. return
  18. }
  19. // clear scene
  20. viewer.scene.disposeSceneModels()
  21. // load environment map and glb
  22. await viewer.setEnvironmentMap('https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr')
  23. await viewer.load({
  24. path: 'file.glb',
  25. file: blob,
  26. })
  27. // add download button
  28. const downloadButton = document.createElement('button')
  29. downloadButton.innerText = 'Download .glb'
  30. downloadButton.style.position = 'absolute'
  31. downloadButton.style.bottom = '3rem'
  32. downloadButton.style.right = '3rem'
  33. downloadButton.style.zIndex = '10000'
  34. downloadButton.onclick = () => downloadBlob(blob, 'file.glb')
  35. document.body.appendChild(downloadButton)
  36. }
  37. _testStart()
  38. init().finally(_testFinish)