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ů.

CanvasSnapshotPlugin.md 2.4KB

před 1 rokem
před 1 rokem
před 1 rokem
před 1 rokem
před 1 rokem
před 1 rokem
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. ---
  2. prev:
  3. text: 'SSAOPlugin'
  4. link: './SSAOPlugin'
  5. next:
  6. text: 'PickingPlugin'
  7. link: './PickingPlugin'
  8. ---
  9. # CanvasSnapshotPlugin
  10. [//]: # (todo: image)
  11. [Example](https://threepipe.org/examples/#canvas-snapshot-plugin/) —
  12. [Source Code](https://github.com/repalash/threepipe/blob/master/src/plugins/export/CanvasSnapshotPlugin.ts) —
  13. [API Reference](https://threepipe.org/docs/classes/CanvasSnapshotPlugin.html)
  14. Canvas Snapshot Plugin adds support for taking snapshots of the canvas and exporting them as images and data urls. It includes options to take snapshot of a region, mime type, quality render scale, tiled zip export for large resolution, scaling the output image, interfacing with SSAA, Progressive plugins etc.
  15. Check out the interface [CanvasSnapshotOptions](https://threepipe.org/docs/interfaces/CanvasSnapshotOptions.html) for more details.
  16. ```typescript
  17. import {ThreeViewer, CanvasSnapshotPlugin} from 'threepipe'
  18. const viewer = new ThreeViewer({...})
  19. const snapshotPlugin = viewer.addPluginSync(new CanvasSnapshotPlugin())
  20. // download a snapshot.
  21. await snapshotPlugin.downloadSnapshot('image.webp', { // all parameters are optional
  22. scale: 1, // scale the final image
  23. timeout: 0, // wait before taking the snapshot, in ms
  24. quality: 0.9, // quality of the image (0-1) only for jpeg and webp
  25. displayPixelRatio: 2, // render scale
  26. mimeType: 'image/webp', // mime type of the image
  27. waitForProgressive: true, // wait for progressive rendering to finish (ProgressivePlugin). true by default
  28. progressiveFrames: 64, // number of frames to wait for progressive rendering to finish (ProgressivePlugin). 64 by default
  29. rect: { // region to take snapshot. eg. crop center of the canvas
  30. height: viewer.canvas.clientHeight / 2,
  31. width: viewer.canvas.clientWidth / 2,
  32. x: viewer.canvas.clientWidth / 4,
  33. y: viewer.canvas.clientHeight / 4,
  34. },
  35. // tileRows: 3, // number of rows to tile the image. If more than one, a zip file will be exported
  36. // tileColumns: 3, // number of columns to tile the image
  37. })
  38. // get data url (string)
  39. const dataUrl: string = await snapshotPlugin.getDataUrl({ // all parameters are optional
  40. displayPixelRatio: 2, // render scale
  41. mimeType: 'image/webp', // mime type of the image
  42. })
  43. // get File
  44. const file: File = await snapshotPlugin.getFile('file.jpeg', { // all parameters are optional
  45. mimeType: 'image/jpeg', // mime type of the image
  46. })
  47. ```