From c74617a82deeab751f46d92b5da887a0500de995 Mon Sep 17 00:00:00 2001 From: Andrea Gargaro Date: Tue, 24 Sep 2024 21:52:36 +0200 Subject: [PATCH] Fix patch material (#9) Fixed exception thrown when material to patch used 'this' within onBeforeMaterial. --- src/objects/InstancedMesh2.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/objects/InstancedMesh2.ts b/src/objects/InstancedMesh2.ts index c965093..5257782 100644 --- a/src/objects/InstancedMesh2.ts +++ b/src/objects/InstancedMesh2.ts @@ -156,7 +156,7 @@ export class InstancedMesh2< protected patchMaterial(material: Material): void { if (material.isInstancedMeshPatched) throw new Error('Cannot reuse already patched material.'); - const onBeforeCompile = material.onBeforeCompile; + const onBeforeCompile = material.onBeforeCompile.bind(material); material.onBeforeCompile = (shader: WebGLProgramParametersWithUniforms, renderer) => { if (onBeforeCompile) onBeforeCompile(shader, renderer);