1
0
mirror of https://github.com/troisjs/trois.git synced 2024-11-24 04:12:02 +08:00

new stats component

This commit is contained in:
Sander Moolin 2021-04-06 10:28:04 -04:00
parent bd733970af
commit 2fe99ca3ff
2 changed files with 48 additions and 0 deletions

View File

@ -22,6 +22,7 @@
"gsap": "^3.5.1",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-vue": "^6.0.0-beta.11",
"stats.js": "0.17.0",
"three": "^0.127",
"vite": "^2.1.5",
"vue": "^3.0.11"

View File

@ -0,0 +1,47 @@
import Stats from 'stats.js';
import { inject } from 'vue';
export default {
props: {
noSetup: { type: Boolean, default: false }
},
emits: ['created'],
inject: ['rendererComponent'],
setup({ noSetup }) {
const stats = new Stats();
if (!noSetup) {
stats.showPanel(0); // 0: fps, 1: ms, 2: mb, 3+: custom
document.body.appendChild(stats.dom);
}
return { stats };
},
mounted() {
if (!this.noSetup) {
this.rendererComponent.onBeforeRender(this.begin);
this.rendererComponent.onAfterRender(this.end);
}
this.$emit('created', { stats: this.stats });
},
methods: {
begin() {
if (this.stats) {
this.stats.begin();
}
},
end() {
if (this.stats) {
this.stats.end();
}
}
},
unmounted() {
if (this.stats && this.stats.dom) {
this.stats.dom.parentElement.removeChild(this.stats.dom);
}
this.rendererComponent.offBeforeRender(this.begin);
this.rendererComponent.offAfterRender(this.end);
},
render() {
return this.$slots.default ? this.$slots.default() : [];
},
};