1
0
mirror of https://github.com/troisjs/trois.git synced 2024-11-24 20:32:02 +08:00
trois/src/core/Texture.js

36 lines
708 B
JavaScript
Raw Normal View History

2020-10-04 06:07:10 +08:00
import { TextureLoader } from 'three';
2020-10-04 06:20:27 +08:00
import { watch } from 'vue';
2020-10-04 06:07:10 +08:00
export default {
inject: ['three'],
emits: ['loaded'],
props: {
src: String,
onLoad: Function,
onProgress: Function,
onError: Function,
},
created() {
2020-10-04 06:20:27 +08:00
this.createTexture();
watch(() => this.src, this.refreshTexture);
2020-10-04 06:07:10 +08:00
},
unmounted() {
this.texture.dispose();
},
methods: {
2020-10-04 06:20:27 +08:00
createTexture() {
this.texture = new TextureLoader().load(this.src, this.onLoaded, this.onProgress, this.onError);
},
refreshTexture() {
this.createTexture();
},
2020-10-04 06:07:10 +08:00
onLoaded() {
if (this.onLoad) this.onLoad();
this.$emit('loaded');
},
},
render() {
return [];
},
};