From e9e2ac7bce621a77971f6dc87bb745d1eb6c8954 Mon Sep 17 00:00:00 2001 From: Sander Moolin Date: Fri, 12 Mar 2021 09:55:30 -0500 Subject: [PATCH] Uniforms working correctly --- src/materials/ShaderMaterial.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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 [];