threepipe
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

script.ts 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import {_testFinish, downloadBlob, IAsset, ITexture, ThreeViewer} from 'threepipe'
  2. const viewer = new ThreeViewer({canvas: document.getElementById('mcanvas') as HTMLCanvasElement})
  3. async function init() {
  4. // import a hdr file
  5. const dataTexture = await viewer.import<ITexture>('https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr')
  6. if (!dataTexture) {
  7. console.error('Unable to import texture')
  8. return
  9. }
  10. // export as exr
  11. const blob = await viewer.export(dataTexture, {exportExt: 'exr'})
  12. if (!blob || blob.ext !== 'exr') {
  13. console.error('Unable to export texture', blob)
  14. return
  15. }
  16. // load the exr as environment map
  17. const map = await viewer.setEnvironmentMap({
  18. path: 'file.exr',
  19. file: blob,
  20. } as IAsset)
  21. if (!map) {
  22. console.error('Unable to load exr')
  23. return
  24. }
  25. viewer.scene.background = map
  26. // add download button
  27. const downloadButton = document.createElement('button')
  28. downloadButton.innerText = 'Download .exr'
  29. downloadButton.style.position = 'absolute'
  30. downloadButton.style.bottom = '3rem'
  31. downloadButton.style.right = '3rem'
  32. downloadButton.style.zIndex = '10000'
  33. downloadButton.onclick = () => downloadBlob(blob, 'file.exr')
  34. document.body.appendChild(downloadButton)
  35. }
  36. init().finally(_testFinish)