From e50ee6aa1430172f8a2bc6a9c7494f33acbc8ce3 Mon Sep 17 00:00:00 2001 From: Edward Moyse Date: Sun, 26 Jul 2026 11:03:05 +0200 Subject: [PATCH] fix(color-manager): preserve manually-set vertex colors in Color by Vertex When applying "Color by Vertex", the vertex color should come from: 1. Explicit vertex color in the event data (userData.color) 2. Current material color (if user has manually set it via the UI) 3. Deterministic golden-ratio color (fallback) Previously, the code skipped step 2, so manually-set colors (e.g. green vertices) were replaced with deterministic colors when applying Color by Vertex to linked tracks. Now those manual colors are preserved. Fixes the issue where setting Vertices_xAOD to green, then applying Color by Vertex to InDetTrackParticles_xAOD, would result in random-looking colors instead of the green tracks/vertices. Co-Authored-By: Claude Haiku 4.5 --- .../src/managers/three-manager/color-manager.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/phoenix-event-display/src/managers/three-manager/color-manager.ts b/packages/phoenix-event-display/src/managers/three-manager/color-manager.ts index b506db121..93ad9b04a 100644 --- a/packages/phoenix-event-display/src/managers/three-manager/color-manager.ts +++ b/packages/phoenix-event-display/src/managers/three-manager/color-manager.ts @@ -165,10 +165,16 @@ export class ColorManager { return; } - // Deterministic distinct color per vertex (golden ratio hue steps), - // unless the vertex has an explicit color. + // Use explicit vertex color if set in event data, otherwise the current + // material color (e.g. set by the user via the UI), otherwise deterministic + // distinct color per vertex (golden ratio hue steps). + const materialColor = + vertexObject instanceof Mesh + ? ((vertexObject.material as any)?.color as Color | undefined) + : undefined; const vertexColor = vertexObject.userData.color ?? + materialColor ?? new Color().setHSL((vertexIndex * 0.618034) % 1, 0.9, 0.55); setColorForObject(vertexObject, vertexColor);