threepipe
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

script.ts 1.4KB

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