-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathscript.ts
More file actions
55 lines (46 loc) · 1.89 KB
/
script.ts
File metadata and controls
55 lines (46 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import {_testFinish, _testStart, downloadBlob, isWebpExportSupported, LoadingScreenPlugin, ThreeViewer} from 'threepipe'
import {createSimpleButtons} from '../examples-utils/simple-bottom-buttons.js'
const viewer = new ThreeViewer({
canvas: document.getElementById('mcanvas') as HTMLCanvasElement,
msaa: true,
plugins: [LoadingScreenPlugin],
})
// Note: see also: CanvasSnapshotPlugin
async function init() {
await viewer.setEnvironmentMap('https://samples.threepipe.org/minimal/venice_sunset_1k.hdr')
await viewer.load('https://samples.threepipe.org/demos/kira.glb', {
autoCenter: true,
autoScale: true,
})
async function downloadSnapshot(type = 'png') {
const blob = await viewer.getScreenshotBlob({mimeType: 'image/' + type, quality: 0.85})
// or to get data url:
// const dataUrl = await viewer.getScreenshotDataUrl({mimeType: 'image/' + type, quality: 0.85})
if (blob) downloadBlob(blob, 'snapshot.' + type)
else alert('Unable to get screenshot')
}
createSimpleButtons({
['Download snapshot (PNG)']: async(btn: HTMLButtonElement) => {
btn.disabled = true
await downloadSnapshot()
btn.disabled = false
},
['Download snapshot (JPEG)']: async(btn: HTMLButtonElement) => {
btn.disabled = true
await downloadSnapshot('jpeg')
btn.disabled = false
},
['Download snapshot (WEBP)']: async(btn: HTMLButtonElement) => {
btn.disabled = true
if (!isWebpExportSupported()) {
alert('WebP export is not supported in this browser, try the latest version of chrome, firefox or edge.')
btn.disabled = false
return
}
await downloadSnapshot('webp')
btn.disabled = false
},
})
}
_testStart()
init().finally(_testFinish)