diff --git a/src/materials/ShaderMaterial.js b/src/materials/ShaderMaterial.js index a2ce939..4627cf0 100644 --- a/src/materials/ShaderMaterial.js +++ b/src/materials/ShaderMaterial.js @@ -1,10 +1,11 @@ import { ShaderMaterial } from 'three' +import { watch } from 'vue'; import { propsValues, defaultFragmentShader, defaultVertexShader } from '../tools.js'; export default { inject: ['three', 'mesh'], props: { - uniforms: Object, + uniforms: { type: Object, default: () => { } }, vertexShader: { type: String, default: defaultVertexShader }, fragmentShader: { type: String, default: defaultFragmentShader }, }, @@ -20,6 +21,16 @@ export default { createMaterial() { this.material = new ShaderMaterial(propsValues(this.$props)); }, + addWatchers() { + ['uniforms', 'vertexShader', 'fragmentShader'].forEach(p => { + watch(() => this[p], (value) => { + this.material[p] = value; + }, + // only watch deep on uniforms + { deep: p === 'uniforms' } + ); + }); + }, }, render() { return [];