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 { CubeTextureLoader } from 'three';
|
||||||
// import { watch } from 'vue';
|
import { watch } from 'vue';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
inject: ['three'],
|
inject: ['three'],
|
||||||
@ -15,14 +15,22 @@ export default {
|
|||||||
onError: Function,
|
onError: Function,
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
this.texture = new CubeTextureLoader()
|
this.createTexture();
|
||||||
.setPath(this.path)
|
watch(() => this.path, this.refreshTexture);
|
||||||
.load(this.urls, this.onLoaded, this.onProgress, this.onError);
|
watch(() => this.urls, this.refreshTexture);
|
||||||
},
|
},
|
||||||
unmounted() {
|
unmounted() {
|
||||||
this.texture.dispose();
|
this.texture.dispose();
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
createTexture() {
|
||||||
|
this.texture = new CubeTextureLoader()
|
||||||
|
.setPath(this.path)
|
||||||
|
.load(this.urls, this.onLoaded, this.onProgress, this.onError);
|
||||||
|
},
|
||||||
|
refreshTexture() {
|
||||||
|
this.createTexture();
|
||||||
|
},
|
||||||
onLoaded() {
|
onLoaded() {
|
||||||
if (this.onLoad) this.onLoad();
|
if (this.onLoad) this.onLoad();
|
||||||
this.$emit('loaded');
|
this.$emit('loaded');
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { TextureLoader } from 'three';
|
import { TextureLoader } from 'three';
|
||||||
// import { watch } from 'vue';
|
import { watch } from 'vue';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
inject: ['three'],
|
inject: ['three'],
|
||||||
@ -11,12 +11,19 @@ export default {
|
|||||||
onError: Function,
|
onError: Function,
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
this.texture = new TextureLoader().load(this.src, this.onLoaded, this.onProgress, this.onError);
|
this.createTexture();
|
||||||
|
watch(() => this.src, this.refreshTexture);
|
||||||
},
|
},
|
||||||
unmounted() {
|
unmounted() {
|
||||||
this.texture.dispose();
|
this.texture.dispose();
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
createTexture() {
|
||||||
|
this.texture = new TextureLoader().load(this.src, this.onLoaded, this.onProgress, this.onError);
|
||||||
|
},
|
||||||
|
refreshTexture() {
|
||||||
|
this.createTexture();
|
||||||
|
},
|
||||||
onLoaded() {
|
onLoaded() {
|
||||||
if (this.onLoad) this.onLoad();
|
if (this.onLoad) this.onLoad();
|
||||||
this.$emit('loaded');
|
this.$emit('loaded');
|
||||||
|
@ -9,5 +9,11 @@ export default {
|
|||||||
unmounted() {
|
unmounted() {
|
||||||
this.material.setEnvMap(null);
|
this.material.setEnvMap(null);
|
||||||
},
|
},
|
||||||
|
methods: {
|
||||||
|
refreshTexture() {
|
||||||
|
this.createTexture();
|
||||||
|
this.material.setEnvMap(this.texture);
|
||||||
|
},
|
||||||
|
},
|
||||||
__hmrId: 'EnvMap',
|
__hmrId: 'EnvMap',
|
||||||
};
|
};
|
||||||
|
@ -10,6 +10,10 @@ export default {
|
|||||||
this.material.setMap(null);
|
this.material.setMap(null);
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
refreshTexture() {
|
||||||
|
this.createTexture();
|
||||||
|
this.material.setMap(this.texture);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
__hmrId: 'Map',
|
__hmrId: 'Map',
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user