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 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import {_testFinish, downloadBlob, isWebpExportSupported, LoadingScreenPlugin, ThreeViewer} from 'threepipe'
  2. import {createSimpleButtons} from '../examples-utils/simple-bottom-buttons.js'
  3. const viewer = new ThreeViewer({
  4. canvas: document.getElementById('mcanvas') as HTMLCanvasElement,
  5. msaa: true,
  6. plugins: [LoadingScreenPlugin],
  7. })
  8. // Note: see also: CanvasSnapshotPlugin
  9. async function init() {
  10. await viewer.setEnvironmentMap('https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr')
  11. await viewer.load('https://threejs.org/examples/models/gltf/kira.glb', {
  12. autoCenter: true,
  13. autoScale: true,
  14. })
  15. async function downloadSnapshot(type = 'png') {
  16. const blob = await viewer.getScreenshotBlob({mimeType: 'image/' + type, quality: 0.85})
  17. // or to get data url:
  18. // const dataUrl = await viewer.getScreenshotDataUrl({mimeType: 'image/' + type, quality: 0.85})
  19. if (blob) downloadBlob(blob, 'snapshot.' + type)
  20. else alert('Unable to get screenshot')
  21. }
  22. createSimpleButtons({
  23. ['Download snapshot (PNG)']: async(btn: HTMLButtonElement) => {
  24. btn.disabled = true
  25. await downloadSnapshot()
  26. btn.disabled = false
  27. },
  28. ['Download snapshot (JPEG)']: async(btn: HTMLButtonElement) => {
  29. btn.disabled = true
  30. await downloadSnapshot('jpeg')
  31. btn.disabled = false
  32. },
  33. ['Download snapshot (WEBP)']: async(btn: HTMLButtonElement) => {
  34. btn.disabled = true
  35. if (!isWebpExportSupported()) {
  36. alert('WebP export is not supported in this browser, try the latest version of chrome, firefox or edge.')
  37. btn.disabled = false
  38. return
  39. }
  40. await downloadSnapshot('webp')
  41. btn.disabled = false
  42. },
  43. })
  44. }
  45. init().finally(_testFinish)