Skip to content

Commit

Permalink
feat: add stats.js
Browse files Browse the repository at this point in the history
  • Loading branch information
kmkzt committed Feb 3, 2020
1 parent 2d9abf3 commit bc9a9bc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
5 changes: 0 additions & 5 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,5 @@ export default class App {
public animate() {
this.example.animate()
this.renderer.render(this.scene, this.camera)
if (self.requestAnimationFrame) {
self.requestAnimationFrame(this.animate)
} else {
// Firefox
}
}
}
24 changes: 23 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,27 @@ import * as Comlink from 'comlink'
import App from './app'
import * as AppWorker from './app.worker'
import './shared/event.transferhandler'
import Stats from 'stats.js'

/**
* animation
* @param {() => void} cb animation update render
*/
const startAnmation = (update: () => void) => {
const stats = new Stats()
document.body.appendChild(stats.dom)
const animate = () => {
if (self.requestAnimationFrame) {
self.requestAnimationFrame(animate)
} else {
// Firefox
}
stats.begin()
update()
stats.end()
}
animate()
}

const init = async () => {
// Offscreen canvas
Expand All @@ -28,7 +49,7 @@ const init = async () => {
canvas: htmlCanvas,
pixelRatio: window.devicePixelRatio
})

startAnmation(app.animate)
return
}

Expand All @@ -55,6 +76,7 @@ const init = async () => {
[offscreen]
)
)
startAnmation(app.animate)

const eventType: Array<keyof GlobalEventHandlersEventMap> = [
'click',
Expand Down

0 comments on commit bc9a9bc

Please sign in to comment.