fix(earth-bgp): consolidate visual constants and bump version to 0.22.12
This commit is contained in:
@@ -277,13 +277,39 @@ function blendHexColors(fromHex, toHex, ratio) {
|
||||
}
|
||||
|
||||
function getCollectorDistanceScale(marker, camera) {
|
||||
if (!marker || !camera) return 1;
|
||||
if (!marker || !camera || BGP_CONFIG.sizeStabilization?.enabled === false) return 1;
|
||||
|
||||
marker.getWorldPosition(collectorWorldPosition);
|
||||
const distanceToCamera = camera.position.distanceTo(collectorWorldPosition);
|
||||
const referenceDistance = CONFIG.defaultCameraZ - CONFIG.earthRadius + BGP_CONFIG.collectorAltitudeOffset;
|
||||
const referenceFovRad = (75 * Math.PI) / 180;
|
||||
const cameraFovRad = ((camera.fov || 75) * Math.PI) / 180;
|
||||
const min = Number(BGP_CONFIG.sizeStabilization?.collectorMin ?? 0.6);
|
||||
const max = Number(BGP_CONFIG.sizeStabilization?.collectorMax ?? 1.9);
|
||||
const worldPerPixel =
|
||||
distanceToCamera * Math.tan(cameraFovRad / 2);
|
||||
const referenceWorldPerPixel =
|
||||
referenceDistance * Math.tan(referenceFovRad / 2);
|
||||
|
||||
return clamp(distanceToCamera / referenceDistance, 0.6, 1.9);
|
||||
return clamp(worldPerPixel / referenceWorldPerPixel, min, max);
|
||||
}
|
||||
|
||||
function getEventDistanceScale(marker, camera) {
|
||||
if (!marker || !camera || BGP_CONFIG.sizeStabilization?.enabled === false) return 1;
|
||||
|
||||
marker.getWorldPosition(collectorWorldPosition);
|
||||
const distanceToCamera = camera.position.distanceTo(collectorWorldPosition);
|
||||
const referenceDistance = CONFIG.defaultCameraZ - CONFIG.earthRadius + BGP_CONFIG.altitudeOffset;
|
||||
const referenceFovRad = (75 * Math.PI) / 180;
|
||||
const cameraFovRad = ((camera.fov || 75) * Math.PI) / 180;
|
||||
const min = Number(BGP_CONFIG.sizeStabilization?.eventMin ?? 0.7);
|
||||
const max = Number(BGP_CONFIG.sizeStabilization?.eventMax ?? 1.9);
|
||||
const worldPerPixel =
|
||||
distanceToCamera * Math.tan(cameraFovRad / 2);
|
||||
const referenceWorldPerPixel =
|
||||
referenceDistance * Math.tan(referenceFovRad / 2);
|
||||
|
||||
return clamp(worldPerPixel / referenceWorldPerPixel, min, max);
|
||||
}
|
||||
|
||||
function orientCollectorMarkerToSurface(marker, position) {
|
||||
@@ -332,13 +358,13 @@ function getCollectorActivityProfile(markerData) {
|
||||
|
||||
const scaleBoost = clamp(1 + Math.log2(activityScore + 1) * 0.12, 1, 1.55);
|
||||
const haloScale =
|
||||
BGP_CONFIG.collectorHaloScale +
|
||||
BGP_CONFIG.halo.collectorScale +
|
||||
clamp(Math.log2(recent24h + prefixes + 1) * 2.2, 0, 12);
|
||||
const pulseHaloScale =
|
||||
BGP_CONFIG.collectorPulseHaloScale +
|
||||
BGP_CONFIG.halo.collectorPulseScale +
|
||||
clamp(Math.log2(recent24h + recent7d + 1) * 2.8, 0, 14);
|
||||
const coverageHaloScale =
|
||||
BGP_CONFIG.collectorCoverageHaloScale +
|
||||
BGP_CONFIG.halo.collectorCoverageScale +
|
||||
clamp(Math.log2(prefixes + origins + 1) * 3.4, 0, 18);
|
||||
|
||||
return {
|
||||
@@ -994,7 +1020,7 @@ function createCollectorMarker(markerData) {
|
||||
);
|
||||
|
||||
marker.position.copy(position);
|
||||
marker.scale.set(BGP_CONFIG.collectorScale * 0.88 * activity.scaleBoost, BGP_CONFIG.collectorScale * 1.08 * activity.scaleBoost, 1);
|
||||
marker.scale.set(BGP_CONFIG.marker.collectorBaseScale * 0.88 * activity.scaleBoost, BGP_CONFIG.marker.collectorBaseScale * 1.08 * activity.scaleBoost, 1);
|
||||
marker.renderOrder = 3;
|
||||
marker.visible = showBGP;
|
||||
orientCollectorMarkerToSurface(marker, position);
|
||||
@@ -1018,7 +1044,11 @@ function createCollectorMarker(markerData) {
|
||||
const statusCore = createOverlaySprite({
|
||||
color: activity.color,
|
||||
opacity: 0.0,
|
||||
scale: Math.max(BGP_CONFIG.collectorScale * 0.12, 1.2),
|
||||
scale: Math.max(
|
||||
BGP_CONFIG.marker.collectorBaseScale *
|
||||
BGP_CONFIG.marker.collectorStatusCoreBaseScale,
|
||||
BGP_CONFIG.marker.collectorStatusCoreMinScale,
|
||||
),
|
||||
});
|
||||
statusCore.position.set(0, 0, 0.02);
|
||||
statusCore.renderOrder = 4;
|
||||
@@ -1036,7 +1066,7 @@ function createCollectorMarker(markerData) {
|
||||
marker.userData = {
|
||||
type: "bgp_collector",
|
||||
state: "normal",
|
||||
baseScale: BGP_CONFIG.collectorScale * activity.scaleBoost,
|
||||
baseScale: BGP_CONFIG.marker.collectorBaseScale * activity.scaleBoost,
|
||||
baseColor,
|
||||
idleColor,
|
||||
pulseOffset: Math.random() * Math.PI * 2,
|
||||
@@ -1072,7 +1102,7 @@ function createAnomalyMarker(markerData) {
|
||||
CONFIG.earthRadius + BGP_CONFIG.altitudeOffset,
|
||||
);
|
||||
|
||||
const baseScale = BGP_CONFIG.baseScale * getSeverityScale(markerData.severity);
|
||||
const baseScale = BGP_CONFIG.marker.eventBaseScale * getSeverityScale(markerData.severity);
|
||||
sprite.position.copy(position);
|
||||
sprite.scale.setScalar(baseScale);
|
||||
sprite.renderOrder = 5;
|
||||
@@ -1097,7 +1127,7 @@ function createAnomalyMarker(markerData) {
|
||||
blending: THREE.AdditiveBlending,
|
||||
}),
|
||||
);
|
||||
ringA.scale.setScalar(baseScale * BGP_CONFIG.eventRingScaleA);
|
||||
ringA.scale.setScalar(baseScale * BGP_CONFIG.ring.scaleA);
|
||||
ringA.position.set(0, 0, -0.01);
|
||||
sprite.add(ringA);
|
||||
|
||||
@@ -1112,7 +1142,7 @@ function createAnomalyMarker(markerData) {
|
||||
blending: THREE.AdditiveBlending,
|
||||
}),
|
||||
);
|
||||
ringB.scale.setScalar(baseScale * BGP_CONFIG.eventRingScaleB);
|
||||
ringB.scale.setScalar(baseScale * BGP_CONFIG.ring.scaleB);
|
||||
ringB.position.set(0, 0, -0.02);
|
||||
sprite.add(ringB);
|
||||
|
||||
@@ -1338,7 +1368,7 @@ export function updateBGPVisualState(lockedObjectType, lockedObject, camera) {
|
||||
0.5 +
|
||||
0.5 *
|
||||
Math.sin(
|
||||
now * BGP_CONFIG.collectorPulseSpeed + marker.userData.pulseOffset,
|
||||
now * BGP_CONFIG.pulse.collectorSpeed + marker.userData.pulseOffset,
|
||||
);
|
||||
|
||||
let scale = marker.userData.baseScale * getCollectorDistanceScale(marker, camera);
|
||||
@@ -1411,7 +1441,11 @@ export function updateBGPVisualState(lockedObjectType, lockedObject, camera) {
|
||||
isLocked ? 0.58 : isHovered ? 0.4 : hasLockedLayer ? 0.0 : 0.18;
|
||||
marker.userData.statusCore.material.color.setHex(marker.userData.baseColor || BGP_CONFIG.collectorColor);
|
||||
marker.userData.statusCore.scale.setScalar(
|
||||
Math.max(BGP_CONFIG.collectorScale * 0.12, 1.2) * (isLocked ? 1.08 : isHovered ? 1.04 : 0.92),
|
||||
Math.max(
|
||||
BGP_CONFIG.marker.collectorBaseScale *
|
||||
BGP_CONFIG.marker.collectorStatusCoreBaseScale,
|
||||
BGP_CONFIG.marker.collectorStatusCoreMinScale,
|
||||
) * (isLocked ? 1.08 : isHovered ? 1.04 : 0.92),
|
||||
);
|
||||
}
|
||||
if (marker.userData.coverageHalo) {
|
||||
@@ -1433,33 +1467,35 @@ export function updateBGPVisualState(lockedObjectType, lockedObject, camera) {
|
||||
const isHovered = marker.userData.state === "hover";
|
||||
const pulse =
|
||||
0.5 +
|
||||
0.5 * Math.sin(now * BGP_CONFIG.pulseSpeed + marker.userData.pulseOffset);
|
||||
0.5 * Math.sin(now * BGP_CONFIG.pulse.eventSpeed + marker.userData.pulseOffset);
|
||||
|
||||
let scale = marker.userData.baseScale;
|
||||
const iconAnchorScale =
|
||||
marker.userData.baseScale * getEventDistanceScale(marker, camera);
|
||||
let scale = iconAnchorScale;
|
||||
let opacity = BGP_CONFIG.opacity.normal;
|
||||
let markerColor = marker.userData.baseColor || getSeverityColor(marker.userData.severity);
|
||||
const isIncidentMarker = marker.userData.source === "bgp_incident";
|
||||
let ringBaseOpacity = isIncidentMarker
|
||||
? BGP_CONFIG.eventRingOpacity
|
||||
: BGP_CONFIG.eventRingOpacity * 0.45;
|
||||
? BGP_CONFIG.ring.opacity
|
||||
: BGP_CONFIG.ring.opacity * 0.45;
|
||||
|
||||
if (isLocked || isLinkedCollectorLocked) {
|
||||
scale *= 1 + BGP_CONFIG.lockedPulseAmplitude * pulse;
|
||||
scale *= 1 + BGP_CONFIG.pulse.lockedAmplitude * pulse;
|
||||
opacity =
|
||||
BGP_CONFIG.opacity.lockedMin +
|
||||
(BGP_CONFIG.opacity.lockedMax - BGP_CONFIG.opacity.lockedMin) * pulse;
|
||||
ringBaseOpacity *= 1.2;
|
||||
} else if (isHovered) {
|
||||
scale *= BGP_CONFIG.hoverScale;
|
||||
scale *= BGP_CONFIG.marker.hoverScale;
|
||||
opacity = BGP_CONFIG.opacity.hover;
|
||||
ringBaseOpacity *= 1.05;
|
||||
} else if (isOtherLocked) {
|
||||
scale *= BGP_CONFIG.dimmedScale;
|
||||
scale *= BGP_CONFIG.marker.dimmedScale;
|
||||
opacity = 0.1;
|
||||
markerColor = 0x7d8ca3;
|
||||
ringBaseOpacity = 0.02;
|
||||
} else {
|
||||
scale *= 1 + BGP_CONFIG.normalPulseAmplitude * pulse;
|
||||
scale *= 1 + BGP_CONFIG.pulse.normalAmplitude * pulse;
|
||||
opacity = isIncidentMarker ? 0.7 : 0.62;
|
||||
}
|
||||
|
||||
@@ -1468,13 +1504,13 @@ export function updateBGPVisualState(lockedObjectType, lockedObject, camera) {
|
||||
marker.material.opacity = opacity;
|
||||
marker.visible = showBGP;
|
||||
|
||||
const ringPhaseA = (now * BGP_CONFIG.eventRingSpeed + marker.userData.pulseOffset) % 1;
|
||||
const ringPhaseA = (now * BGP_CONFIG.ring.speed + marker.userData.pulseOffset) % 1;
|
||||
const applyRingState = (ring, phase, maxScale) => {
|
||||
if (!ring) return;
|
||||
const progress = Math.max(0, Math.min(1, phase));
|
||||
const minScale = 1.28;
|
||||
const desiredWorldScale =
|
||||
marker.userData.baseScale * (minScale + progress * (maxScale - minScale));
|
||||
iconAnchorScale * (minScale + progress * (maxScale - minScale));
|
||||
const parentScale = Math.max(scale, 0.0001);
|
||||
const localRingScale = desiredWorldScale / parentScale;
|
||||
const fadeIn = Math.max(0, Math.min(1, (progress - 0.08) / 0.14));
|
||||
@@ -1486,7 +1522,7 @@ export function updateBGPVisualState(lockedObjectType, lockedObject, camera) {
|
||||
ring.visible = showBGP;
|
||||
};
|
||||
|
||||
applyRingState(marker.userData.ringA, ringPhaseA, BGP_CONFIG.eventRingScaleA);
|
||||
applyRingState(marker.userData.ringA, ringPhaseA, BGP_CONFIG.ring.scaleA);
|
||||
if (marker.userData.ringB) {
|
||||
marker.userData.ringB.material.opacity = 0;
|
||||
marker.userData.ringB.visible = false;
|
||||
|
||||
Reference in New Issue
Block a user