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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import {
  2. _testFinish,
  3. CanvasSnapshotPlugin,
  4. isWebpExportSupported,
  5. LoadingScreenPlugin,
  6. SSAAPlugin,
  7. ThreeViewer,
  8. } from 'threepipe'
  9. import {createSimpleButtons} from '../examples-utils/simple-bottom-buttons.js'
  10. const viewer = new ThreeViewer({
  11. canvas: document.getElementById('mcanvas') as HTMLCanvasElement,
  12. msaa: true,
  13. renderScale: 'auto',
  14. plugins: [LoadingScreenPlugin, SSAAPlugin],
  15. })
  16. async function init() {
  17. const snapshotPlugin = viewer.addPluginSync(new CanvasSnapshotPlugin())
  18. await viewer.setEnvironmentMap('https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr')
  19. await viewer.load('https://threejs.org/examples/models/gltf/kira.glb', {
  20. autoCenter: true,
  21. autoScale: true,
  22. })
  23. createSimpleButtons({
  24. ['Download snapshot (jpeg)']: async(btn: HTMLButtonElement) => {
  25. btn.disabled = true
  26. await snapshotPlugin.downloadSnapshot('snapshot.jpeg', {
  27. mimeType: 'image/jpeg', // mime type of the image
  28. quality: 0.9, // quality of the image (0-1) only for jpeg and webp
  29. displayPixelRatio: 2, // render scale
  30. waitForProgressive: true,
  31. progressiveFrames: 64, // wait for 64 frames of ProgressivePlugin/SSAA before exporting
  32. })
  33. btn.disabled = false
  34. },
  35. ['Download snapshot (1024x1024 size, png)']: async(btn: HTMLButtonElement) => {
  36. btn.disabled = true
  37. // save scale
  38. const scale = viewer.renderManager.renderScale
  39. // set fixed render size
  40. viewer.setRenderSize({width: 1024, height: 1024})
  41. // (optional) hide the canvas. (not needed if you have an overlay)
  42. await snapshotPlugin.downloadSnapshot('snapshot.png', {
  43. mimeType: 'image/png', // mime type of the image
  44. })
  45. // revert scale
  46. viewer.renderManager.renderScale = scale
  47. // revert render size to fill container
  48. viewer.setSize()
  49. btn.disabled = false
  50. },
  51. ['Download snapshot (crop rect, png)']: async(btn: HTMLButtonElement) => {
  52. btn.disabled = true
  53. await snapshotPlugin.downloadSnapshot('snapshot.png', {
  54. scale: 1, // scale the final image
  55. displayPixelRatio: 2, // render scale
  56. mimeType: 'image/png', // mime type of the image
  57. rect: { // region to take snapshot. Crop center of the canvas
  58. height: viewer.canvas.clientHeight / 2,
  59. width: viewer.canvas.clientWidth / 2,
  60. x: viewer.canvas.clientWidth / 4,
  61. y: viewer.canvas.clientHeight / 4,
  62. },
  63. })
  64. btn.disabled = false
  65. },
  66. ['Download snapshot (webp)']: async(btn: HTMLButtonElement) => {
  67. btn.disabled = true
  68. if (!isWebpExportSupported()) {
  69. alert('WebP export is not supported in this browser, try the latest version of chrome, firefox or edge.')
  70. btn.disabled = false
  71. return
  72. }
  73. await snapshotPlugin.downloadSnapshot('snapshot.webp', {
  74. mimeType: 'image/webp', // mime type of the image
  75. scale: 1, // scale the final image
  76. quality: 0.9, // quality of the image (0-1) only for jpeg and webp
  77. displayPixelRatio: 2, // render scale
  78. })
  79. btn.disabled = false
  80. },
  81. ['Download 3x3 Tiles (png zip)']: async(btn: HTMLButtonElement) => {
  82. btn.disabled = true
  83. await snapshotPlugin.downloadSnapshot('snapshot', {
  84. mimeType: 'image/png', // mime type of the image
  85. // scale: 1, // scale the final image
  86. // quality: 0.9, // quality of the image (0-1) only for jpeg and webp
  87. displayPixelRatio: 4, // render scale
  88. tileRows: 3,
  89. tileColumns: 3,
  90. })
  91. btn.disabled = false
  92. },
  93. })
  94. }
  95. init().finally(_testFinish)