Bugfix: update sketch mode colors on theme change (#3849)

* Update client-side scene mesh base colors properly

* Add E2E test

* Remove use of `as`
This commit is contained in:
Frank Noirot
2024-09-10 13:30:39 -04:00
committed by GitHub
parent 5b2738f826
commit 900bac999c
3 changed files with 93 additions and 2 deletions

View File

@ -102,7 +102,7 @@ import {
getRectangleCallExpressions,
updateRectangleSketch,
} from 'lib/rectangleTool'
import { getThemeColorForThreeJs } from 'lib/theme'
import { getThemeColorForThreeJs, Themes } from 'lib/theme'
import { err, reportRejection, trap } from 'lib/trap'
import { CSS2DObject } from 'three/examples/jsm/renderers/CSS2DRenderer'
import { Point3d } from 'wasm-lib/kcl/bindings/Point3d'
@ -1473,6 +1473,25 @@ export class SceneEntities {
to,
})
}
/**
* Update the base color of each of the THREEjs meshes
* that represent each of the sketch segments, to get the
* latest value from `sceneInfra._theme`
*/
updateSegmentBaseColor(newColor: Themes.Light | Themes.Dark) {
const newColorThreeJs = getThemeColorForThreeJs(newColor)
Object.values(this.activeSegments).forEach((group) => {
group.userData.baseColor = newColorThreeJs
group.traverse((child) => {
if (
child instanceof Mesh &&
child.material instanceof MeshBasicMaterial
) {
child.material.color.set(newColorThreeJs)
}
})
})
}
removeSketchGrid() {
if (this.axisGroup) this.scene.remove(this.axisGroup)
}