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 [];
|
|
|
|
},
|
|
|
|
};
|