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 },
|
||||
fragmentShader: { type: String, default: defaultFragmentShader },
|
||||
},
|
||||
provide() {
|
||||
return {
|
||||
material: this,
|
||||
};
|
||||
},
|
||||
created() {
|
||||
this.createMaterial();
|
||||
['vertexShader', 'fragmentShader'].forEach(p => {
|
||||
@ -29,7 +34,7 @@ export default {
|
||||
},
|
||||
},
|
||||
render() {
|
||||
return [];
|
||||
return this.$slots.default ? this.$slots.default() : [];
|
||||
},
|
||||
__hmrId: 'ShaderMaterial',
|
||||
};
|
||||
|
@ -25,7 +25,7 @@ export default {
|
||||
watch(() => this.src, this.refreshTexture);
|
||||
},
|
||||
unmounted() {
|
||||
this.material.setTexture(null, this.id);
|
||||
if (this.material && this.material.setTexture) this.material.setTexture(null, this.id);
|
||||
this.texture.dispose();
|
||||
},
|
||||
methods: {
|
||||
@ -38,7 +38,11 @@ export default {
|
||||
},
|
||||
refreshTexture() {
|
||||
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() {
|
||||
if (this.onLoad) this.onLoad();
|
||||
|
Loading…
Reference in New Issue
Block a user