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

texture hmr

This commit is contained in:
Kevin Levron 2020-10-04 00:20:27 +02:00
parent a117df2e2e
commit de0761812a
4 changed files with 31 additions and 6 deletions

View File

@ -1,5 +1,5 @@
import { CubeTextureLoader } from 'three';
// import { watch } from 'vue';
import { watch } from 'vue';
export default {
inject: ['three'],
@ -15,14 +15,22 @@ export default {
onError: Function,
},
created() {
this.texture = new CubeTextureLoader()
.setPath(this.path)
.load(this.urls, this.onLoaded, this.onProgress, this.onError);
this.createTexture();
watch(() => this.path, this.refreshTexture);
watch(() => this.urls, this.refreshTexture);
},
unmounted() {
this.texture.dispose();
},
methods: {
createTexture() {
this.texture = new CubeTextureLoader()
.setPath(this.path)
.load(this.urls, this.onLoaded, this.onProgress, this.onError);
},
refreshTexture() {
this.createTexture();
},
onLoaded() {
if (this.onLoad) this.onLoad();
this.$emit('loaded');

View File

@ -1,5 +1,5 @@
import { TextureLoader } from 'three';
// import { watch } from 'vue';
import { watch } from 'vue';
export default {
inject: ['three'],
@ -11,12 +11,19 @@ export default {
onError: Function,
},
created() {
this.texture = new TextureLoader().load(this.src, this.onLoaded, this.onProgress, this.onError);
this.createTexture();
watch(() => this.src, this.refreshTexture);
},
unmounted() {
this.texture.dispose();
},
methods: {
createTexture() {
this.texture = new TextureLoader().load(this.src, this.onLoaded, this.onProgress, this.onError);
},
refreshTexture() {
this.createTexture();
},
onLoaded() {
if (this.onLoad) this.onLoad();
this.$emit('loaded');

View File

@ -9,5 +9,11 @@ export default {
unmounted() {
this.material.setEnvMap(null);
},
methods: {
refreshTexture() {
this.createTexture();
this.material.setEnvMap(this.texture);
},
},
__hmrId: 'EnvMap',
};

View File

@ -10,6 +10,10 @@ export default {
this.material.setMap(null);
},
methods: {
refreshTexture() {
this.createTexture();
this.material.setMap(this.texture);
},
},
__hmrId: 'Map',
};