fix: restore live V2X signal and vehicle fidelity in Cesium preview
The ported overlay used the correct REST paths but lost the data handling
from the source dashboard's live-intersection view (HologramCross), so
signals rendered permanently red and vehicles often never appeared.
- Lamp status codes now follow the dashboard dictionary (11/21/22/23/31).
The previous 2/3 reading made every real push fall through to red. The
dictionary lives only in the overlay; the preview consumes normalized
{nodeKeys, color, countDown} entries so the two copies cannot drift.
- Bind V2X phases to native signal heads geometrically. The runtime
document has no phaseNo, so the old lookup fell back to signal.id and
never matched, leaving the dynamic assembly dark. Travel heading is
recovered as faceHeadingDegrees + 180, per the generator's
mast = travel - 90 / face = travel + 180. Verified 7/7 exact matches
against the fengshu-er-road runtime document.
- A phase now lights every approach it drives; the phase -> single entity
map silently overwrote all but the last.
- Drive the countdown assets from the push's countDown field.
- All three sockets heartbeat every 30s and reconnect with backoff,
replaying their subscription frame. Without this the service dropped
the connection and the scene emptied after about a minute.
- The OBU socket sends its bounds frame on connect and on camera move;
it previously sent nothing at all.
- Vehicles are swept when a push goes stale and their slots reused, so
they no longer accumulate as ghosts. Models follow the dashboard's
car_obu.glb / ${type}${subType}.glb naming.
- Parse vehicle pushes leniently, since the dashboard uses saferEval and
the payload is not guaranteed to be strict JSON. Failures are counted
and surfaced rather than dropped; no eval is introduced.
- Drop FlowTravelRatio/queryListWeek, which is not part of this view.
Also corrects a stale spec rule that required vehicleModelNames to be
empty. Live V2X vehicles need packaged models; the real invariant is no
generated routes or traffic simulation.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -54,11 +54,19 @@
|
||||
setLoadingMessage("Loading model", config.glbName || "");
|
||||
const assets = await loadSceneAssets(viewer, metadata, placement);
|
||||
const trafficStart = Cesium.JulianDate.now();
|
||||
const trafficSignals = addTrafficSignals(viewer, signalData, trafficStart, assets);
|
||||
const trafficSignals = createLiveTrafficSignals(signalData, assets);
|
||||
hideUnconfirmedSignalAssets(assets);
|
||||
const cruise = createLiveVehicleState();
|
||||
const cameras = createCameraPresets(viewer, metadata, placement, cruise);
|
||||
const v2xOverlay = typeof window.createV2xCesiumOverlay === "function"
|
||||
? window.createV2xCesiumOverlay({ viewer, metadata, placement, config })
|
||||
? window.createV2xCesiumOverlay({
|
||||
viewer,
|
||||
metadata,
|
||||
placement,
|
||||
config,
|
||||
nativeSignals: (signalData && signalData.signals) || [],
|
||||
setSignalState: (entries) => trafficSignals.update(entries),
|
||||
})
|
||||
: null;
|
||||
|
||||
buildAssetToggles(assets);
|
||||
@@ -611,6 +619,78 @@
|
||||
};
|
||||
}
|
||||
|
||||
function hideUnconfirmedSignalAssets(assets) {
|
||||
assets.filter((asset) => asset.category === "dynamic" || asset.category === "countdown")
|
||||
.forEach((asset) => { if (asset.model) asset.model.show = false; });
|
||||
}
|
||||
|
||||
// Driven entirely by live V2X lamp state. The overlay has already resolved
|
||||
// phaseNo -> native node keys and normalized the lamp status, so this only
|
||||
// paints; it never re-interprets status codes.
|
||||
function createLiveTrafficSignals(signalData, assets) {
|
||||
const dynamic = assets.find((asset) => asset.category === "dynamic" && asset.model);
|
||||
const countdownModels = new Map(assets
|
||||
.filter((asset) => asset.category === "countdown" && asset.model)
|
||||
.map((asset) => [Number(asset.phaseGroup), asset.model]));
|
||||
const signals = (signalData?.signals || []).filter((signal) => signal && signal.id);
|
||||
const phaseGroupByNodeKey = new Map(signals.map((signal) => [String(signal.nodeKey || signal.id), Number(signal.phaseGroup)]));
|
||||
const state = { live: false };
|
||||
|
||||
function paintLamp(nodeKey, color) {
|
||||
let changed = false;
|
||||
["red", "yellow", "green"].forEach((lamp) => {
|
||||
let node = null;
|
||||
try { node = dynamic.model.getNode(`TrafficSignalDynamic_${nodeKey}_${lamp}`); } catch (_) { return; }
|
||||
if (node && node.show !== (lamp === color)) { node.show = lamp === color; changed = true; }
|
||||
});
|
||||
return changed;
|
||||
}
|
||||
|
||||
function paintCountdown(nodeKey, countDown, color) {
|
||||
const model = countdownModels.get(phaseGroupByNodeKey.get(String(nodeKey)));
|
||||
if (!model) return false;
|
||||
// Only two digits are modelled; anything outside 00-19 shows nothing.
|
||||
const visible = Number.isFinite(countDown) && countDown >= 0 && countDown < 20
|
||||
? String(countDown).padStart(2, "0")
|
||||
: null;
|
||||
let changed = false;
|
||||
for (let value = 0; value < 20; value += 1) {
|
||||
const label = String(value).padStart(2, "0");
|
||||
let node = null;
|
||||
try { node = model.getNode(`TrafficSignalDynamic_${nodeKey}_countdown_${label}`); } catch (_) { continue; }
|
||||
if (node && node.show !== (label === visible)) { node.show = label === visible; changed = true; }
|
||||
}
|
||||
if (visible !== null && typeof signalBaseColor === "function") {
|
||||
model.color = signalBaseColor(color);
|
||||
model.colorBlendMode = Cesium.ColorBlendMode.REPLACE;
|
||||
model.colorBlendAmount = 1.0;
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
function update(entries) {
|
||||
if (!dynamic?.model) return;
|
||||
const list = Array.isArray(entries) ? entries : [];
|
||||
let changed = false;
|
||||
let painted = 0;
|
||||
list.forEach((entry) => {
|
||||
const nodeKeys = Array.isArray(entry?.nodeKeys) ? entry.nodeKeys : [];
|
||||
nodeKeys.forEach((nodeKey) => {
|
||||
painted += 1;
|
||||
if (paintLamp(nodeKey, entry.color)) changed = true;
|
||||
if (paintCountdown(nodeKey, entry.countDown, entry.color)) changed = true;
|
||||
});
|
||||
});
|
||||
// Only show the dynamic assembly once a lamp actually resolved to a head.
|
||||
state.live = painted > 0;
|
||||
dynamic.model.show = state.live;
|
||||
countdownModels.forEach((model) => { model.show = state.live; });
|
||||
if (changed) dynamic.model.scene?.requestRender?.();
|
||||
}
|
||||
|
||||
return { count: signals.length, state, update, set show(value) { if (dynamic?.model) dynamic.model.show = Boolean(value && state.live); } };
|
||||
}
|
||||
|
||||
function addTrafficSignals(viewer, signalData, start, assets) {
|
||||
const dynamic = assets.find((asset) => asset.category === "dynamic" && asset.model);
|
||||
const countdownModels = new Map(assets
|
||||
@@ -1416,8 +1496,9 @@
|
||||
|
||||
main().catch((error) => {
|
||||
console.error(error);
|
||||
setStatus("Failed to load Cesium preview: " + error.message);
|
||||
const detail = error && error.message ? error.message : String(error);
|
||||
setStatus("Failed to load Cesium preview: " + detail);
|
||||
document.body.classList.add("scene-error");
|
||||
setLoadingMessage("Failed to load scene", error.message);
|
||||
setLoadingMessage("Failed to load scene", detail + " (see Safari Develop > Show JavaScript Console)");
|
||||
});
|
||||
}());
|
||||
|
||||
Reference in New Issue
Block a user