threepipe
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import {_testFinish, CanvasSnapshotPlugin, isWebpExportSupported, 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. renderScale: 'auto',
  7. })
  8. async function init() {
  9. const snapshotPlugin = viewer.addPluginSync(new CanvasSnapshotPlugin())
  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. createSimpleButtons({
  16. ['Download snapshot (rect png)']: async(btn: HTMLButtonElement) => {
  17. btn.disabled = true
  18. await snapshotPlugin.downloadSnapshot('snapshot.png', {
  19. scale: 1, // scale the final image
  20. displayPixelRatio: 2, // render scale
  21. mimeType: 'image/png', // mime type of the image
  22. rect: { // region to take snapshot. Crop center of the canvas
  23. height: viewer.canvas.clientHeight / 2,
  24. width: viewer.canvas.clientWidth / 2,
  25. x: viewer.canvas.clientWidth / 4,
  26. y: viewer.canvas.clientHeight / 4,
  27. },
  28. })
  29. btn.disabled = false
  30. },
  31. ['Download snapshot (jpeg)']: async(btn: HTMLButtonElement) => {
  32. btn.disabled = true
  33. await snapshotPlugin.downloadSnapshot('snapshot.jpeg', {
  34. mimeType: 'image/jpeg', // mime type of the image
  35. quality: 0.9, // quality of the image (0-1) only for jpeg and webp
  36. displayPixelRatio: 2, // render scale
  37. })
  38. btn.disabled = false
  39. },
  40. ['Download snapshot (webp)']: async(btn: HTMLButtonElement) => {
  41. btn.disabled = true
  42. if (!isWebpExportSupported()) {
  43. alert('WebP export is not supported in this browser, try the latest version of chrome, firefox or edge.')
  44. btn.disabled = false
  45. return
  46. }
  47. await snapshotPlugin.downloadSnapshot('snapshot.webp', {
  48. mimeType: 'image/webp', // mime type of the image
  49. scale: 1, // scale the final image
  50. quality: 0.9, // quality of the image (0-1) only for jpeg and webp
  51. displayPixelRatio: 2, // render scale
  52. })
  53. btn.disabled = false
  54. },
  55. })
  56. }
  57. init().then(_testFinish)