From c75bf91b741e1fdb5c90424627d23fb7d249a9c6 Mon Sep 17 00:00:00 2001 From: Vatroslav Vrbanic Date: Mon, 20 Jun 2022 04:00:49 +0200 Subject: [PATCH] `Mesh` fix `material.needsUpdate` flag on `props` object change Fixed / refactored due to `SvelthreeProps` changes after closing #102 -> `mat.needsUpdate` removed from `Propeller`. --- src/components/Mesh.svelte | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/components/Mesh.svelte b/src/components/Mesh.svelte index aaa859b..4de50f7 100644 --- a/src/components/Mesh.svelte +++ b/src/components/Mesh.svelte @@ -429,7 +429,16 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` // TODO MULTIPLE MATERIALS: this works only with single Material atm, multiple Materials are not implemented yet. /** **shorthand** attribute for setting properties of a `Material` using key-value pairs in an `Object`. */ export let mat: { [P in keyof AnyMaterialProps]: AnyMaterialProps[P] } = undefined - $: if (mat && sMat) sMat.update(mat) + + $: if (mat && sMat) { + const updated_keys: string[] = sMat.update(mat) + if (updated_keys.length) material_needs_update() + } + + function material_needs_update(): void { + const current_single_material = material as Material + current_single_material.needsUpdate = true + } /** ☝️ `matrix` **shorthand** attribute overrides ( *are ignored* ) `pos`, `rot`, `quat`, `scale` and `lookAt` 'shorthand' attributes! */ export let matrix: Matrix4 | Parameters = undefined