threepipe
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CanvasSnapshotPlugin.md 2.0KB

пре 1 година
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 and scaling the output image. Check out the interface [CanvasSnapshotOptions](https://threepipe.org/docs/interfaces/CanvasSnapshotOptions.html) for more details.
  15. ```typescript
  16. import {ThreeViewer, CanvasSnapshotPlugin} from 'threepipe'
  17. const viewer = new ThreeViewer({...})
  18. const snapshotPlugin = viewer.addPluginSync(new CanvasSnapshotPlugin())
  19. // download a snapshot.
  20. await snapshotPlugin.downloadSnapshot('image.webp', { // all parameters are optional
  21. scale: 1, // scale the final image
  22. timeout: 0, // wait before taking the snapshot, in ms
  23. quality: 0.9, // quality of the image (0-1) only for jpeg and webp
  24. displayPixelRatio: 2, // render scale
  25. mimeType: 'image/webp', // mime type of the image
  26. waitForProgressive: true, // wait for progressive rendering to finish (ProgressivePlugin). true by default
  27. rect: { // region to take snapshot. eg. crop center of the canvas
  28. height: viewer.canvas.clientHeight / 2,
  29. width: viewer.canvas.clientWidth / 2,
  30. x: viewer.canvas.clientWidth / 4,
  31. y: viewer.canvas.clientHeight / 4,
  32. },
  33. })
  34. // get data url (string)
  35. const dataUrl = await snapshotPlugin.getDataUrl({ // all parameters are optional
  36. displayPixelRatio: 2, // render scale
  37. mimeType: 'image/webp', // mime type of the image
  38. })
  39. // get File
  40. const file = await snapshotPlugin.getFile('file.jpeg', { // all parameters are optional
  41. mimeType: 'image/jpeg', // mime type of the image
  42. })
  43. ```