Files
speckle-server/packages/viewer/src/modules/legacy/example.js
T
2022-08-25 10:28:48 +03:00

72 lines
2.0 KiB
JavaScript

/* eslint-disable */
/**
* NOT PART OF THE ACTUAL LIBRARY, ONLY USED TO GENERATE THE EXAMPLE WEB BUILD
*/
import Viewer from './modules/Viewer'
setInterval(() => {
document.getElementById('info-mem').innerText =
'' + Math.round(performance.memory.usedJSHeapSize / 1024 / 1024)
}, 100)
let v = new Viewer({ container: document.getElementById('renderer'), showStats: true })
v.on('load-progress', (args) => {
document.getElementById('info-progress').innerText = `${
Math.round(1000 * args.progress) / 1000
}`
})
v.on('busy', (isBusy) => {
document.getElementById('info-busy').innerText = isBusy ? 'BUSY' : 'idle'
document.body.style.cursor = isBusy ? 'progress' : 'default'
})
window.v = v
window.addEventListener('load', () => {
v.onWindowResize()
const prevLoadUrl = localStorage.getItem('prevLoadUrl')
console.log(prevLoadUrl)
if (prevLoadUrl) document.getElementById('objectUrlInput').value = prevLoadUrl
})
window.loadData = async function LoadData(url) {
url = url || document.getElementById('objectUrlInput').value
localStorage.setItem('prevLoadUrl', url)
let t0 = Date.now()
await v.loadObject(url)
console.log(`Finished loading in: ${(Date.now() - t0) / 1000}`)
}
v.on('select', (info) => {
console.info(`Selection event.`)
})
v.on('object-doubleclicked', (info) => {
console.info(`Object double click event.`)
})
v.on('section-box', (status) => {
console.info(`Section box is now ${status ? 'on' : 'off'}.`)
})
window.viewerScreenshot = function () {
//@Alex: we can get rid of the whole example.js/html stuff (sandbox is the replacement)
//@Dim: Changed this to use the API
let data = v.screenshot() // transparent png.
let pop = window.open()
pop.document.title = 'super screenshot'
pop.document.body.style.backgroundColor = 'grey'
let img = new Image()
img.src = data
pop.document.body.appendChild(img)
}
window.zoomFast = function () {
//@Dim: This needs to use the API
// v.interactions.zoomExtents(0.95, false)
}