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

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