mirror of
https://github.com/troisjs/trois.git
synced 2024-11-24 04:12:02 +08:00
texture hmr
This commit is contained in:
parent
a117df2e2e
commit
de0761812a
@ -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');
|
||||
|
@ -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');
|
||||
|
@ -9,5 +9,11 @@ export default {
|
||||
unmounted() {
|
||||
this.material.setEnvMap(null);
|
||||
},
|
||||
methods: {
|
||||
refreshTexture() {
|
||||
this.createTexture();
|
||||
this.material.setEnvMap(this.texture);
|
||||
},
|
||||
},
|
||||
__hmrId: 'EnvMap',
|
||||
};
|
||||
|
@ -10,6 +10,10 @@ export default {
|
||||
this.material.setMap(null);
|
||||
},
|
||||
methods: {
|
||||
refreshTexture() {
|
||||
this.createTexture();
|
||||
this.material.setMap(this.texture);
|
||||
},
|
||||
},
|
||||
__hmrId: 'Map',
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user