mirror of
https://github.com/troisjs/trois.git
synced 2024-11-24 04:12:02 +08:00
Shader texture proof of concept
This commit is contained in:
parent
bf597573b2
commit
3f40a59b73
@ -9,6 +9,11 @@ export default {
|
|||||||
vertexShader: { type: String, default: defaultVertexShader },
|
vertexShader: { type: String, default: defaultVertexShader },
|
||||||
fragmentShader: { type: String, default: defaultFragmentShader },
|
fragmentShader: { type: String, default: defaultFragmentShader },
|
||||||
},
|
},
|
||||||
|
provide() {
|
||||||
|
return {
|
||||||
|
material: this,
|
||||||
|
};
|
||||||
|
},
|
||||||
created() {
|
created() {
|
||||||
this.createMaterial();
|
this.createMaterial();
|
||||||
['vertexShader', 'fragmentShader'].forEach(p => {
|
['vertexShader', 'fragmentShader'].forEach(p => {
|
||||||
@ -29,7 +34,7 @@ export default {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
render() {
|
render() {
|
||||||
return [];
|
return this.$slots.default ? this.$slots.default() : [];
|
||||||
},
|
},
|
||||||
__hmrId: 'ShaderMaterial',
|
__hmrId: 'ShaderMaterial',
|
||||||
};
|
};
|
||||||
|
@ -25,7 +25,7 @@ export default {
|
|||||||
watch(() => this.src, this.refreshTexture);
|
watch(() => this.src, this.refreshTexture);
|
||||||
},
|
},
|
||||||
unmounted() {
|
unmounted() {
|
||||||
this.material.setTexture(null, this.id);
|
if (this.material && this.material.setTexture) this.material.setTexture(null, this.id);
|
||||||
this.texture.dispose();
|
this.texture.dispose();
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
@ -38,7 +38,11 @@ export default {
|
|||||||
},
|
},
|
||||||
refreshTexture() {
|
refreshTexture() {
|
||||||
this.createTexture();
|
this.createTexture();
|
||||||
this.material.setTexture(this.texture, this.id);
|
if (this.material && this.material.setTexture) { this.material.setTexture(this.texture, this.id); }
|
||||||
|
else if (this.material && this.material.material.type === "ShaderMaterial") {
|
||||||
|
const id = this.id === 'map' ? this.src.replace(/\..*/, '') : this.id;
|
||||||
|
this.material.uniforms[id] = { value: this.texture };
|
||||||
|
}
|
||||||
},
|
},
|
||||||
onLoaded() {
|
onLoaded() {
|
||||||
if (this.onLoad) this.onLoad();
|
if (this.onLoad) this.onLoad();
|
||||||
|
Loading…
Reference in New Issue
Block a user