-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStrikeTargetMarker.ts
More file actions
162 lines (139 loc) · 5.55 KB
/
Copy pathStrikeTargetMarker.ts
File metadata and controls
162 lines (139 loc) · 5.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
// SPDX-License-Identifier: AGPL-3.0-or-later
// Copyright (c) 2025-2026 Matthew Kissinger
import * as THREE from 'three';
import type { StrikeGateStatus } from './StrikeGates';
export const STRIKE_TARGET_MARKER_NAME = 'StrikeTargetMarker';
interface StrikeTargetMarkerOptions {
terrainHeightAt?: (x: number, z: number) => number;
}
const GROUND_OFFSET = 0.15;
const BEACON_HEIGHT = 5.5;
// Consistent colour roles with the HUD: GREEN valid, RED danger, AMBER
// pending-confirm/locked, GREY disabled/out-of-range/no-ground.
const COLOR_VALID = 0x5cb85c;
const COLOR_DANGER = 0xd6453d;
const COLOR_LOCKED = 0xe0a52c;
const COLOR_DISABLED = 0x9aa0a6;
function colorForStatus(status: StrikeGateStatus, locked: boolean): number {
if (locked) return COLOR_LOCKED;
switch (status) {
case 'valid': return COLOR_VALID;
case 'danger_close': return COLOR_DANGER;
default: return COLOR_DISABLED; // out_of_range / no_ground
}
}
/**
* Ground beacon the player sweeps onto the dirt during DESIGNATE. Mirrors
* `SquadCommandWorldMarker` (ring + fill + beacon, frustumCulled=false,
* toneMapped=false so it stays a flat HUD colour under AgX). The outer ring is
* sized to the strike's effect footprint; the colour tracks the gate status and
* pulses on danger-close / lock so the state reads at a glance.
*/
export class StrikeTargetMarker {
private readonly scene: THREE.Scene;
private readonly terrainHeightAt?: (x: number, z: number) => number;
private readonly group = new THREE.Group();
private readonly ringGeometry = new THREE.RingGeometry(0.82, 1.0, 48);
private readonly fillGeometry = new THREE.CircleGeometry(0.9, 32);
private readonly postGeometry = new THREE.CylinderGeometry(0.05, 0.05, BEACON_HEIGHT, 8);
private readonly capGeometry = new THREE.ConeGeometry(0.4, 0.9, 4);
private readonly ring: THREE.Mesh;
private readonly fill: THREE.Mesh;
private readonly ringMaterial = this.createMaterial(COLOR_VALID, 0.85);
private readonly fillMaterial = this.createMaterial(COLOR_VALID, 0.16);
private readonly postMaterial = this.createMaterial(COLOR_VALID, 0.4);
private readonly capMaterial = this.createMaterial(COLOR_VALID, 0.78);
private pulseClock = 0;
private pulsing = false;
constructor(scene: THREE.Scene, options: StrikeTargetMarkerOptions = {}) {
this.scene = scene;
this.terrainHeightAt = options.terrainHeightAt;
this.group.name = STRIKE_TARGET_MARKER_NAME;
this.group.visible = false;
this.group.userData.perfCategory = 'ui_command_marker';
this.ring = new THREE.Mesh(this.ringGeometry, this.ringMaterial);
this.ring.name = 'StrikeTargetMarker.Ring';
this.ring.rotation.x = -Math.PI / 2;
this.fill = new THREE.Mesh(this.fillGeometry, this.fillMaterial);
this.fill.name = 'StrikeTargetMarker.Fill';
this.fill.rotation.x = -Math.PI / 2;
this.fill.position.y = 0.02;
const post = new THREE.Mesh(this.postGeometry, this.postMaterial);
post.name = 'StrikeTargetMarker.Beacon';
post.position.y = BEACON_HEIGHT * 0.5;
const cap = new THREE.Mesh(this.capGeometry, this.capMaterial);
cap.name = 'StrikeTargetMarker.Cap';
cap.position.y = BEACON_HEIGHT + 0.3;
for (const object of [this.ring, this.fill, post, cap]) {
object.frustumCulled = false;
object.renderOrder = 42;
object.userData.perfCategory = 'ui_command_marker';
this.group.add(object);
}
this.scene.add(this.group);
}
/** Place + recolour the marker for the current pick. `radius` sizes the ring. */
setState(position: THREE.Vector3, status: StrikeGateStatus, locked: boolean, radius: number): void {
const color = colorForStatus(status, locked);
this.setColor(color);
const r = Math.max(2, radius);
this.ring.scale.set(r, r, 1);
this.fill.scale.set(r * 0.95, r * 0.95, 1);
this.group.position.set(position.x, this.resolveY(position), position.z);
this.group.visible = true;
this.pulsing = locked || status === 'danger_close';
if (!this.pulsing) {
this.pulseClock = 0;
this.ringMaterial.opacity = 0.85;
}
}
/** Animate the danger/lock pulse. Safe to call when hidden (no-op). */
tick(dt: number): void {
if (!this.group.visible || !this.pulsing) return;
this.pulseClock += dt;
// ~2 Hz opacity throb between 0.45 and 1.0.
const t = 0.5 + 0.5 * Math.sin(this.pulseClock * Math.PI * 4);
this.ringMaterial.opacity = 0.45 + 0.55 * t;
}
hide(): void {
this.group.visible = false;
this.pulsing = false;
}
isVisible(): boolean {
return this.group.visible;
}
dispose(): void {
this.scene.remove(this.group);
this.ringGeometry.dispose();
this.fillGeometry.dispose();
this.postGeometry.dispose();
this.capGeometry.dispose();
this.ringMaterial.dispose();
this.fillMaterial.dispose();
this.postMaterial.dispose();
this.capMaterial.dispose();
}
private createMaterial(color: number, opacity: number): THREE.MeshBasicMaterial {
return new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity,
depthWrite: false,
toneMapped: false,
fog: false,
});
}
private setColor(color: number): void {
this.ringMaterial.color.setHex(color);
this.fillMaterial.color.setHex(color);
this.postMaterial.color.setHex(color);
this.capMaterial.color.setHex(color);
}
private resolveY(position: THREE.Vector3): number {
const terrainY = this.terrainHeightAt?.(position.x, position.z);
if (terrainY !== undefined && Number.isFinite(terrainY)) {
return terrainY + GROUND_OFFSET;
}
return position.y + GROUND_OFFSET;
}
}