From 0a078a3fc7b0ea3e4bbfcd8ab30a2c660879e14b Mon Sep 17 00:00:00 2001 From: Alexandru Popovici Date: Tue, 27 Feb 2024 17:32:31 +0200 Subject: [PATCH] WBX-8 Viewer fixes (#2083) * Fixed WBX-341 * Fixed WBX-342 --- packages/viewer/src/modules/batching/MeshBatch.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/viewer/src/modules/batching/MeshBatch.ts b/packages/viewer/src/modules/batching/MeshBatch.ts index 23dabc9a9..f1771ad2e 100644 --- a/packages/viewer/src/modules/batching/MeshBatch.ts +++ b/packages/viewer/src/modules/batching/MeshBatch.ts @@ -26,6 +26,7 @@ import Logger from 'js-logger' import { ObjectLayers } from '../../IViewer' import { DrawGroup } from './InstancedMeshBatch' import Materials from '../materials/Materials' +import SpeckleStandardColoredMaterial from '../materials/SpeckleStandardColoredMaterial' export default class MeshBatch implements Batch { public id: string @@ -247,6 +248,16 @@ export default class MeshBatch implements Batch { minGradientIndex = Math.min(minGradientIndex, minMaxIndices.minIndex) maxGradientIndex = Math.max(maxGradientIndex, minMaxIndices.maxIndex) } + /** We need to update the texture here, because each batch uses it's own clone for any material we use on it + * because otherwise three.js won't properly update our custom uniforms + */ + if (range[k].materialOptions.rampTexture !== undefined) { + if (range[k].material instanceof SpeckleStandardColoredMaterial) { + ;(range[k].material as SpeckleStandardColoredMaterial).setGradientTexture( + range[k].materialOptions.rampTexture + ) + } + } } } if (minGradientIndex < Infinity && maxGradientIndex > 0) @@ -485,7 +496,7 @@ export default class MeshBatch implements Batch { }) .slice() - this.geometry.groups.sort((a, b) => { + groups.sort((a, b) => { const materialA: Material = (this.mesh.material as Array)[ a.materialIndex ]