Prechádzať zdrojové kódy

3d:故障部件高亮改为原色↔故障色闪烁(500ms)

18922397810 2 týždňov pred
rodič
commit
fb5291a0bf
1 zmenil súbory, kde vykonal 29 pridanie a 2 odobranie
  1. 29 2
      3d/frontend/src/three/Viewer.ts

+ 29 - 2
3d/frontend/src/three/Viewer.ts

@@ -81,6 +81,8 @@ export class Viewer {
 
   private selectedIds = new Set<string>()
   private faultColors = new Map<string, string>()
+  private faultBlinkOn = true
+  private faultBlinkTimer: ReturnType<typeof setInterval> | undefined
   private prevSelected = new Set<string>()
   private hoveredId: string | null = null
   private lastPick = 0
@@ -230,6 +232,7 @@ export class Viewer {
     this.parts = []
     this.byId.clear()
     this.selectedIds.clear()
+    this.stopFaultBlink()
     this.faultColors.clear()
     this.prevSelected = new Set()
     this.hoveredId = null
@@ -549,24 +552,47 @@ export class Viewer {
     this.applyDisplay(id)
   }
 
-  /** 故障高亮:临时显示层(不写入部件自身配色、不持久化)。 */
+  private startFaultBlink(): void {
+    this.stopFaultBlink()
+    this.faultBlinkOn = true
+    this.faultBlinkTimer = setInterval(() => {
+      this.faultBlinkOn = !this.faultBlinkOn
+      this.faultColors.forEach((_color, id) => this.applyDisplay(id))
+    }, 500)
+  }
+
+  private stopFaultBlink(): void {
+    if (this.faultBlinkTimer) {
+      clearInterval(this.faultBlinkTimer)
+      this.faultBlinkTimer = undefined
+    }
+    this.faultBlinkOn = true
+  }
+
+  /** 故障高亮:临时显示层(原色↔故障色闪烁,不写入部件自身配色、不持久化)。 */
   setFaultColors(entries: Record<string, string>): void {
     const changed = new Set<string>([...this.faultColors.keys(), ...Object.keys(entries)])
     this.faultColors = new Map(Object.entries(entries))
     changed.forEach((id) => this.applyDisplay(id))
+    if (this.faultColors.size) this.startFaultBlink()
+    else this.stopFaultBlink()
   }
 
   clearFaultColors(): void {
     if (!this.faultColors.size) return
     const ids = [...this.faultColors.keys()]
     this.faultColors.clear()
+    this.stopFaultBlink()
     ids.forEach((id) => this.applyDisplay(id))
   }
 
   private applyDisplay(id: string): void {
     const handle = this.byId.get(id)
     if (!handle) return
-    const base = this.faultColors.get(id) ?? handle.colorHex ?? handle.defaults[0]
+    const fault = this.faultColors.get(id)
+    const base = fault !== undefined && this.faultBlinkOn
+      ? fault
+      : handle.colorHex ?? handle.defaults[0]
     if (handle.inst && handle.instanceId !== undefined) {
       const c = new THREE.Color(base)
       if (this.selectedIds.has(id)) c.lerp(HIGHLIGHT, 0.45)
@@ -587,6 +613,7 @@ export class Viewer {
 
   dispose(): void {
     this.animating = false
+    this.stopFaultBlink()
     window.removeEventListener('resize', this.updateAspect)
     const el = this.renderer.domElement
     el.removeEventListener('pointermove', this.onPointerMove)