684 lines
21 KiB
JavaScript
684 lines
21 KiB
JavaScript
import { isLegendItemEnabled } from "./legend-filters.js";
|
|
// cables.js - Cable loading and rendering module
|
|
|
|
import * as THREE from "three";
|
|
import { createCableLineBatch, createLandingPointBatch } from "./cable-batches.js";
|
|
import { createSurfaceRibbonGeometry, createSurfaceRibbonMaterial } from "./surface-ribbon.js";
|
|
import { cableSurfacePoint, calculateGreatCirclePoints } from "./cable-surface.js";
|
|
import { configureColorTexture } from "./texture-colors.js";
|
|
|
|
import {
|
|
CONFIG,
|
|
CABLE_COLORS,
|
|
PATHS,
|
|
CABLE_STATE,
|
|
CABLE_CONFIG,
|
|
} from "./constants.js";
|
|
import { getSurfaceMarkerCameraScale } from "./utils.js";
|
|
import { setEarthStatValue, updateEarthStats, showStatusMessage } from "./ui.js";
|
|
import { setLegendItems, setLegendMode } from "./legend.js";
|
|
import { earthMessage } from "./i18n.js";
|
|
|
|
export let cableLines = [];
|
|
export let landingPoints = [];
|
|
export let lockedCable = null;
|
|
let cableSourceFeatureCount = 0;
|
|
let landingPointSourceFeatureCount = 0;
|
|
let cableIdMap = new Map();
|
|
let cableStates = new Map();
|
|
let cablesVisible = true;
|
|
let cableLineBatch = null;
|
|
let landingPointBatch = null;
|
|
let lockedCableRibbonMesh = null;
|
|
|
|
function clearLockedCableRibbon() {
|
|
if (!lockedCableRibbonMesh) return;
|
|
lockedCableRibbonMesh.parent?.remove?.(lockedCableRibbonMesh);
|
|
lockedCableRibbonMesh.geometry?.dispose?.();
|
|
lockedCableRibbonMesh.material?.dispose?.();
|
|
lockedCableRibbonMesh = null;
|
|
}
|
|
const _lpEarthWorldPos = new THREE.Vector3();
|
|
const _lpWorldPos = new THREE.Vector3();
|
|
const _lpCameraRel = new THREE.Vector3();
|
|
const _lpPointRel = new THREE.Vector3();
|
|
const _lpCameraToPoint = new THREE.Vector3();
|
|
const LANDING_POINT_SPRITE_HEIGHT = 3;
|
|
const LANDING_POINT_SPRITE_ASPECT = 1;
|
|
const LANDING_POINT_SIZE_REFERENCE_FOV = 75;
|
|
const LANDING_POINT_SIZE_SCALE_MIN = 0.16;
|
|
const LANDING_POINT_SIZE_SCALE_MAX = 3;
|
|
let landingPointTexture = null;
|
|
|
|
function getLandingPointDimColor() {
|
|
const dimColor = CABLE_CONFIG.landingPointVisual.dimmed.colorRGB;
|
|
const brightness = CABLE_CONFIG.landingPointVisual.dimBrightness;
|
|
const color = new THREE.Color().setRGB(
|
|
(dimColor.r * brightness) / 255,
|
|
(dimColor.g * brightness) / 255,
|
|
(dimColor.b * brightness) / 255,
|
|
...(THREE.SRGBColorSpace ? [THREE.SRGBColorSpace] : []),
|
|
);
|
|
return `#${color.getHexString()}`;
|
|
}
|
|
|
|
async function getLandingPointTexture() {
|
|
if (landingPointTexture) return landingPointTexture;
|
|
const source = new URL("../assets/icons/marker-landing-point.svg", import.meta.url).href;
|
|
landingPointTexture = await new THREE.TextureLoader().loadAsync(source);
|
|
configureColorTexture(landingPointTexture);
|
|
landingPointTexture.generateMipmaps = false;
|
|
landingPointTexture.minFilter = THREE.LinearFilter;
|
|
landingPointTexture.magFilter = THREE.LinearFilter;
|
|
return landingPointTexture;
|
|
}
|
|
|
|
function getLandingPointDistanceScale(camera) {
|
|
if (!camera) return 1;
|
|
return getSurfaceMarkerCameraScale(camera, {
|
|
altitudeOffset: CABLE_CONFIG.landingPoint.altitudeOffset,
|
|
referenceFov: LANDING_POINT_SIZE_REFERENCE_FOV,
|
|
min: LANDING_POINT_SIZE_SCALE_MIN,
|
|
max: LANDING_POINT_SIZE_SCALE_MAX,
|
|
});
|
|
}
|
|
|
|
function setLandingPointScale(point, camera = null, distanceScale = getLandingPointDistanceScale(camera)) {
|
|
const height = LANDING_POINT_SPRITE_HEIGHT * distanceScale;
|
|
const width = height * LANDING_POINT_SPRITE_ASPECT;
|
|
if (point.scale.x === width && point.scale.y === height && point.scale.z === 1) return;
|
|
point.scale.set(width, height, 1);
|
|
point.updateMatrix();
|
|
}
|
|
|
|
function setLandingPointMaterialState(point, { color, opacity }) {
|
|
point.material.color.set(color);
|
|
point.material.opacity = opacity;
|
|
}
|
|
|
|
function disposeMaterial(material) {
|
|
if (!material) return;
|
|
|
|
if (Array.isArray(material)) {
|
|
material.forEach(disposeMaterial);
|
|
return;
|
|
}
|
|
|
|
if (material.map && !material.userData?.sharedMap) {
|
|
material.map.dispose();
|
|
}
|
|
material.dispose();
|
|
}
|
|
|
|
function disposeObject(object, parent) {
|
|
if (!object) return;
|
|
const owner = parent || object.parent;
|
|
if (owner) {
|
|
owner.remove(object);
|
|
}
|
|
if (object.geometry && !object.userData?.sharedGeometry) {
|
|
object.geometry.dispose();
|
|
}
|
|
if (object.material) {
|
|
disposeMaterial(object.material);
|
|
}
|
|
}
|
|
|
|
function getCableColor(properties) {
|
|
if (properties.color) {
|
|
if (
|
|
typeof properties.color === "string" &&
|
|
properties.color.startsWith("#")
|
|
) {
|
|
return parseInt(properties.color.substring(1), 16);
|
|
}
|
|
if (typeof properties.color === "number") {
|
|
return properties.color;
|
|
}
|
|
}
|
|
|
|
const cableName =
|
|
properties.Name ||
|
|
properties.name ||
|
|
properties.cableName ||
|
|
properties.shortname ||
|
|
"";
|
|
if (cableName.includes("Americas II")) {
|
|
return CABLE_COLORS["Americas II"];
|
|
}
|
|
if (cableName.includes("AU Aleutian A")) {
|
|
return CABLE_COLORS["AU Aleutian A"];
|
|
}
|
|
if (cableName.includes("AU Aleutian B")) {
|
|
return CABLE_COLORS["AU Aleutian B"];
|
|
}
|
|
|
|
return CABLE_COLORS.default;
|
|
}
|
|
|
|
function createCableLine(points, color, properties) {
|
|
if (points.length < 2) return null;
|
|
color = new THREE.Color(CABLE_CONFIG.visual.normalTint)
|
|
.lerp(new THREE.Color(color), CABLE_CONFIG.visual.sourceColorWeight).getHex();
|
|
|
|
const lineGeometry = new THREE.BufferGeometry().setFromPoints(points);
|
|
lineGeometry.computeBoundingSphere();
|
|
|
|
const lineMaterial = new THREE.LineBasicMaterial({
|
|
color,
|
|
linewidth: CABLE_CONFIG.line.lineWidth,
|
|
transparent: true,
|
|
opacity: CABLE_CONFIG.line.opacity,
|
|
depthTest: true,
|
|
depthWrite: true,
|
|
});
|
|
|
|
const cableLine = new THREE.Line(lineGeometry, lineMaterial);
|
|
// Cable vertices are already in Earth-local space; only the parent rotates.
|
|
cableLine.matrixAutoUpdate = false;
|
|
cableLine.updateMatrix();
|
|
const cableId =
|
|
properties.cable_id ||
|
|
properties.id ||
|
|
properties.Name ||
|
|
properties.name ||
|
|
Math.random().toString(36);
|
|
cableLine.userData = {
|
|
type: "cable",
|
|
cableId,
|
|
source_id: properties.source_id,
|
|
name:
|
|
properties.Name ||
|
|
properties.name ||
|
|
properties.cableName ||
|
|
properties.shortname ||
|
|
"Unknown",
|
|
owner: properties.owner || properties.owners || "-",
|
|
status: properties.status || "-",
|
|
length: properties.length || "-",
|
|
coords: "-",
|
|
rfs: properties.rfs || "-",
|
|
originalColor: color,
|
|
localCenter:
|
|
lineGeometry.boundingSphere?.center?.clone() || new THREE.Vector3(),
|
|
};
|
|
cableLine.renderOrder = CABLE_CONFIG.line.renderOrder;
|
|
cableLine.visible = cablesVisible && isLegendItemEnabled("cables", cableLine.userData.name);
|
|
cableLine.userData.legend_filtered = !isLegendItemEnabled("cables", cableLine.userData.name);
|
|
|
|
if (!cableIdMap.has(cableId)) {
|
|
cableIdMap.set(cableId, []);
|
|
}
|
|
cableIdMap.get(cableId).push(cableLine);
|
|
|
|
return cableLine;
|
|
}
|
|
|
|
export function clearCableLines(earthObj = null) {
|
|
cableLineBatch?.dispose();
|
|
cableLineBatch = null;
|
|
cableLines.forEach((line) => disposeObject(line, earthObj));
|
|
cableLines = [];
|
|
cableSourceFeatureCount = 0;
|
|
cableIdMap = new Map();
|
|
cableStates.clear();
|
|
}
|
|
|
|
export function clearLandingPoints(earthObj = null) {
|
|
landingPointBatch?.dispose();
|
|
landingPointBatch = null;
|
|
landingPoints.forEach((point) => disposeObject(point, earthObj));
|
|
landingPoints = [];
|
|
landingPointSourceFeatureCount = 0;
|
|
}
|
|
|
|
export function clearCableData(earthObj = null) {
|
|
clearCableSelection();
|
|
clearCableLines(earthObj);
|
|
clearLandingPoints(earthObj);
|
|
}
|
|
|
|
export async function loadGeoJSONFromPath(scene, earthObj, options = {}) {
|
|
const { silent = false } = options;
|
|
if (!silent) {
|
|
showStatusMessage(earthMessage("loading.cableData"), "warning");
|
|
}
|
|
|
|
const response = await fetch(PATHS.cablesApi, { cache: "no-store" });
|
|
if (!response.ok) {
|
|
throw new Error(`电缆接口返回 HTTP ${response.status}`);
|
|
}
|
|
|
|
const data = await response.json();
|
|
if (!data.features || !Array.isArray(data.features)) {
|
|
throw new Error("无效的电缆 GeoJSON 格式");
|
|
}
|
|
|
|
clearCableLines(earthObj);
|
|
cableSourceFeatureCount = data.features.length;
|
|
|
|
for (const feature of data.features) {
|
|
const geometry = feature.geometry;
|
|
const properties = feature.properties || {};
|
|
|
|
if (!geometry || !geometry.coordinates) continue;
|
|
|
|
const color = getCableColor(properties);
|
|
|
|
if (geometry.type === "MultiLineString") {
|
|
for (const lineCoords of geometry.coordinates) {
|
|
if (!lineCoords || lineCoords.length < 2) continue;
|
|
|
|
const points = [];
|
|
for (let i = 0; i < lineCoords.length - 1; i++) {
|
|
const lon1 = lineCoords[i][0];
|
|
const lat1 = lineCoords[i][1];
|
|
const lon2 = lineCoords[i + 1][0];
|
|
const lat2 = lineCoords[i + 1][1];
|
|
|
|
const segment = calculateGreatCirclePoints(
|
|
lat1,
|
|
lon1,
|
|
lat2,
|
|
lon2,
|
|
CONFIG.earthRadius + CABLE_CONFIG.line.altitudeOffset,
|
|
CABLE_CONFIG.line.greatCircleSegments,
|
|
);
|
|
points.push(...(i === 0 ? segment : segment.slice(1)));
|
|
}
|
|
|
|
const line = createCableLine(points, color, properties);
|
|
if (line) {
|
|
cableLines.push(line);
|
|
earthObj.add(line);
|
|
}
|
|
}
|
|
} else if (geometry.type === "LineString") {
|
|
const points = [];
|
|
for (let i = 0; i < geometry.coordinates.length - 1; i++) {
|
|
const lon1 = geometry.coordinates[i][0];
|
|
const lat1 = geometry.coordinates[i][1];
|
|
const lon2 = geometry.coordinates[i + 1][0];
|
|
const lat2 = geometry.coordinates[i + 1][1];
|
|
|
|
const segment = calculateGreatCirclePoints(
|
|
lat1,
|
|
lon1,
|
|
lat2,
|
|
lon2,
|
|
CONFIG.earthRadius + CABLE_CONFIG.line.altitudeOffset,
|
|
CABLE_CONFIG.line.greatCircleSegments,
|
|
);
|
|
points.push(...(i === 0 ? segment : segment.slice(1)));
|
|
}
|
|
|
|
const line = createCableLine(points, color, properties);
|
|
if (line) {
|
|
cableLines.push(line);
|
|
earthObj.add(line);
|
|
}
|
|
}
|
|
}
|
|
|
|
cableLineBatch = createCableLineBatch(cableLines);
|
|
if (cableLineBatch) {
|
|
cableLineBatch.object.visible = cablesVisible;
|
|
earthObj.add(cableLineBatch.object);
|
|
}
|
|
const cableCount = data.features.length;
|
|
const inServiceCount = data.features.filter(
|
|
(feature) =>
|
|
feature.properties &&
|
|
(feature.properties.status === "active" ||
|
|
feature.properties.status === "In Service"),
|
|
).length;
|
|
|
|
const statusEl = document.getElementById("cable-status-summary");
|
|
setEarthStatValue("cable-count", `${cableCount}个`);
|
|
if (statusEl) statusEl.textContent = `${inServiceCount}/${cableCount} 运行中`;
|
|
|
|
updateEarthStats({
|
|
cableCount: cableLines.length,
|
|
landingPointCount: landingPoints.length,
|
|
terrainOn: false,
|
|
textureQuality: "8K 卫星图",
|
|
});
|
|
|
|
if (!silent) {
|
|
showStatusMessage(earthMessage("status.loadedCables", { count: cableLines.length }), "success");
|
|
}
|
|
return cableLines.length;
|
|
}
|
|
|
|
export async function loadLandingPoints(scene, earthObj, options = {}) {
|
|
const { silent = false } = options;
|
|
|
|
const response = await fetch(PATHS.landingPointsApi, { cache: "no-store" });
|
|
if (!response.ok) {
|
|
throw new Error(`登陆点接口返回 HTTP ${response.status}`);
|
|
}
|
|
|
|
const data = await response.json();
|
|
if (!data.features || !Array.isArray(data.features)) {
|
|
throw new Error("无效的登陆点 GeoJSON 格式");
|
|
}
|
|
|
|
clearLandingPoints(earthObj);
|
|
landingPointSourceFeatureCount = data.features.length;
|
|
|
|
const markerTexture = await getLandingPointTexture();
|
|
|
|
for (const feature of data.features) {
|
|
if (!feature.geometry || !feature.geometry.coordinates) continue;
|
|
|
|
const [lon, lat] = feature.geometry.coordinates;
|
|
const properties = feature.properties || {};
|
|
|
|
if (
|
|
typeof lon !== "number" ||
|
|
typeof lat !== "number" ||
|
|
Number.isNaN(lon) ||
|
|
Number.isNaN(lat) ||
|
|
Math.abs(lat) > 90 ||
|
|
Math.abs(lon) > 180
|
|
) {
|
|
continue;
|
|
}
|
|
|
|
const position = cableSurfacePoint(lat, lon);
|
|
if (
|
|
Number.isNaN(position.x) ||
|
|
Number.isNaN(position.y) ||
|
|
Number.isNaN(position.z)
|
|
) {
|
|
continue;
|
|
}
|
|
|
|
const marker = new THREE.Sprite(
|
|
new THREE.SpriteMaterial({
|
|
map: markerTexture,
|
|
color: CABLE_CONFIG.landingPoint.color,
|
|
transparent: true,
|
|
opacity: CABLE_CONFIG.landingPoint.opacity,
|
|
depthTest: false,
|
|
depthWrite: false,
|
|
alphaTest: 0.01,
|
|
}),
|
|
);
|
|
marker.material.userData.sharedMap = true;
|
|
marker.renderOrder = CABLE_CONFIG.landingPoint.renderOrder;
|
|
marker.center.set(0.5, 0.5);
|
|
marker.position.copy(position);
|
|
marker.userData = {
|
|
type: "landingPoint",
|
|
source_id: properties.source_id,
|
|
name: properties.name || "未知登陆点",
|
|
cableNames: properties.cable_names || [],
|
|
country: properties.country || "未知国家",
|
|
status: properties.status || "未知",
|
|
latitude: lat,
|
|
longitude: lon,
|
|
landing_visual_state: "normal",
|
|
};
|
|
setLandingPointScale(marker);
|
|
// Scale changes explicitly update the local matrix. Parent-world updates
|
|
// still run, so rotating the globe and picking keep the same coordinates.
|
|
marker.matrixAutoUpdate = false;
|
|
|
|
earthObj.add(marker);
|
|
landingPoints.push(marker);
|
|
}
|
|
|
|
landingPointBatch = createLandingPointBatch(landingPoints, markerTexture);
|
|
if (landingPointBatch) {
|
|
landingPointBatch.object.visible = cablesVisible;
|
|
earthObj.add(landingPointBatch.object);
|
|
}
|
|
const validCount = landingPoints.length;
|
|
|
|
applyCableLegendFilter();
|
|
setEarthStatValue("landing-point-count", `${validCount}个`);
|
|
|
|
if (!silent) {
|
|
showStatusMessage(earthMessage("status.loadedLandingPoints", { count: validCount }), "success");
|
|
}
|
|
return validCount;
|
|
}
|
|
|
|
export function handleCableClick(cable) {
|
|
clearLockedCableRibbon();
|
|
lockedCable = cable;
|
|
|
|
if (cable) {
|
|
const cableId = cable.userData?.id;
|
|
const segments = (cableId ? getCablesById(cableId) : [cable]).filter(Boolean);
|
|
const polylines = [];
|
|
for (const line of segments) {
|
|
const posAttr = line?.geometry?.attributes?.position;
|
|
if (!posAttr || posAttr.count < 2) continue;
|
|
const pts = [];
|
|
for (let i = 0; i < posAttr.count; i += 1) {
|
|
pts.push(new THREE.Vector3(posAttr.getX(i), posAttr.getY(i), posAttr.getZ(i)));
|
|
}
|
|
if (pts.length >= 2) polylines.push(pts);
|
|
}
|
|
const parent = cable.parent || cableLineBatch?.object?.parent;
|
|
if (parent && polylines.length > 0) {
|
|
const color = cable.userData?.originalColor ?? 0x38bdf8;
|
|
const ribbonGeo = createSurfaceRibbonGeometry(polylines);
|
|
const ribbonMat = createSurfaceRibbonMaterial({
|
|
color,
|
|
halfWidthPx: 4.8,
|
|
opacity: 0.92,
|
|
pulseSpeed: 0.65,
|
|
pulseFreq: 2.6,
|
|
pulseIntensity: 0.68,
|
|
additive: true,
|
|
});
|
|
lockedCableRibbonMesh = new THREE.Mesh(ribbonGeo, ribbonMat);
|
|
lockedCableRibbonMesh.name = "locked-cable-glow-ribbon";
|
|
lockedCableRibbonMesh.renderOrder = (CABLE_CONFIG.lineRenderOrder || 1.1) + 0.08;
|
|
lockedCableRibbonMesh.raycast = () => {};
|
|
lockedCableRibbonMesh.visible = cablesVisible;
|
|
const startedAt = typeof performance !== "undefined" ? performance.now() : Date.now();
|
|
lockedCableRibbonMesh.onBeforeRender = () => {
|
|
const now = typeof performance !== "undefined" ? performance.now() : Date.now();
|
|
ribbonMat.uniforms.uTime.value = (now - startedAt) * 0.001;
|
|
};
|
|
parent.add(lockedCableRibbonMesh);
|
|
}
|
|
}
|
|
|
|
setLegendItems("cables", getCableLegendItems());
|
|
|
|
setLegendMode("cables");
|
|
}
|
|
|
|
export function clearCableSelection() {
|
|
clearLockedCableRibbon();
|
|
lockedCable = null;
|
|
setLegendItems("cables", getCableLegendItems());
|
|
}
|
|
|
|
export function getCableLines() {
|
|
return cableLines;
|
|
}
|
|
|
|
export function getCableLegendItems() {
|
|
const legendMap = new Map();
|
|
|
|
cableLines.forEach((cable) => {
|
|
const color = cable.userData?.originalColor;
|
|
const label = cable.userData?.name || "未知线缆";
|
|
|
|
if (typeof color === "number" && !legendMap.has(label)) {
|
|
legendMap.set(label, {
|
|
label,
|
|
color: `#${color.toString(16).padStart(6, "0")}`,
|
|
});
|
|
}
|
|
});
|
|
|
|
if (legendMap.size === 0) {
|
|
return [{ label: "其他电缆", color: "#ffff44" }];
|
|
}
|
|
|
|
const items = Array.from(legendMap.values()).sort((a, b) =>
|
|
a.label.localeCompare(b.label, "zh-CN"),
|
|
);
|
|
|
|
const selectedName = lockedCable?.userData?.name;
|
|
if (!selectedName) {
|
|
return items;
|
|
}
|
|
|
|
const selectedIndex = items.findIndex((item) => item.label === selectedName);
|
|
if (selectedIndex <= 0) {
|
|
return items;
|
|
}
|
|
|
|
const [selectedItem] = items.splice(selectedIndex, 1);
|
|
items.unshift(selectedItem);
|
|
return items;
|
|
}
|
|
|
|
export function getCablesById(cableId) {
|
|
return cableIdMap.get(cableId) || [];
|
|
}
|
|
|
|
export function getLandingPoints() {
|
|
return landingPoints;
|
|
}
|
|
|
|
export function getCableSourceRecordCount() {
|
|
return cableSourceFeatureCount + landingPointSourceFeatureCount;
|
|
}
|
|
|
|
export function getCableState(cableId) {
|
|
return cableStates.get(cableId) || CABLE_STATE.NORMAL;
|
|
}
|
|
|
|
export function setCableState(cableId, state) {
|
|
cableStates.set(cableId, state);
|
|
}
|
|
|
|
export function clearAllCableStates() {
|
|
cableStates.clear();
|
|
}
|
|
|
|
|
|
|
|
|
|
function isFacingCamera(lp, camera) {
|
|
_lpWorldPos.copy(lp.position);
|
|
if (lp.parent) {
|
|
_lpWorldPos.applyMatrix4(lp.parent.matrixWorld);
|
|
_lpEarthWorldPos.setFromMatrixPosition(lp.parent.matrixWorld);
|
|
} else {
|
|
_lpEarthWorldPos.set(0, 0, 0);
|
|
}
|
|
|
|
_lpCameraRel.copy(camera.position).sub(_lpEarthWorldPos);
|
|
_lpPointRel.copy(_lpWorldPos).sub(_lpEarthWorldPos);
|
|
_lpCameraToPoint.subVectors(_lpPointRel, _lpCameraRel);
|
|
|
|
const distanceSq = _lpCameraToPoint.lengthSq();
|
|
if (distanceSq <= 0) return true;
|
|
|
|
const distance = Math.sqrt(distanceSq);
|
|
_lpCameraToPoint.multiplyScalar(1 / distance);
|
|
|
|
// Sprite rendering keeps the full pin visible. Hide it when the anchor point
|
|
// is occluded by the globe so back-side landing points do not bleed through.
|
|
const occlusionRadius =
|
|
CONFIG.earthRadius + CABLE_CONFIG.landingPoint.altitudeOffset * 0.45;
|
|
const cameraProjection = _lpCameraRel.dot(_lpCameraToPoint);
|
|
const cameraRadiusSq = _lpCameraRel.lengthSq();
|
|
const discriminant =
|
|
cameraProjection * cameraProjection -
|
|
(cameraRadiusSq - occlusionRadius * occlusionRadius);
|
|
|
|
if (discriminant < 0) return true;
|
|
|
|
const nearestIntersection = -cameraProjection - Math.sqrt(discriminant);
|
|
return nearestIntersection <= 0 || nearestIntersection >= distance;
|
|
}
|
|
|
|
export function applyLandingPointVisualState(lockedCableName, dimAll = false, camera = null) {
|
|
// Parent transforms and view-dependent sizes are shared by the whole batch.
|
|
landingPoints[0]?.parent?.updateWorldMatrix(true, false);
|
|
const distanceScale = getLandingPointDistanceScale(camera);
|
|
const dimColor = getLandingPointDimColor();
|
|
const relatedNames = Array.isArray(lockedCableName)
|
|
? lockedCableName.filter(Boolean)
|
|
: lockedCableName
|
|
? [lockedCableName]
|
|
: [];
|
|
landingPoints.forEach((lp) => {
|
|
const isVisible = cablesVisible && isLandingPointLegendVisible(lp) && (camera ? isFacingCamera(lp, camera) : true);
|
|
const isRelated =
|
|
!dimAll &&
|
|
Array.isArray(lp.userData.cableNames) &&
|
|
lp.userData.cableNames.some((name) => relatedNames.includes(name));
|
|
|
|
lp.visible = isVisible;
|
|
setLandingPointScale(lp, camera, distanceScale);
|
|
|
|
if (isRelated) {
|
|
setLandingPointMaterialState(lp, {
|
|
color: CABLE_CONFIG.landingPoint.color,
|
|
opacity: CABLE_CONFIG.landingPoint.opacity,
|
|
});
|
|
lp.userData.landing_visual_state = "related";
|
|
} else {
|
|
setLandingPointMaterialState(lp, {
|
|
color: dimColor,
|
|
opacity: CABLE_CONFIG.landingPointVisual.dimmed.opacity,
|
|
});
|
|
lp.userData.landing_visual_state = isVisible ? "dimmed" : "hidden";
|
|
}
|
|
});
|
|
}
|
|
|
|
export function resetLandingPointVisualState(camera = null) {
|
|
landingPoints[0]?.parent?.updateWorldMatrix(true, false);
|
|
const distanceScale = getLandingPointDistanceScale(camera);
|
|
landingPoints.forEach((lp) => {
|
|
const isVisible = cablesVisible && isLandingPointLegendVisible(lp) && (camera ? isFacingCamera(lp, camera) : true);
|
|
lp.visible = isVisible;
|
|
setLandingPointScale(lp, camera, distanceScale);
|
|
setLandingPointMaterialState(lp, {
|
|
color: CABLE_CONFIG.landingPoint.color,
|
|
opacity: CABLE_CONFIG.landingPoint.opacity,
|
|
});
|
|
lp.userData.landing_visual_state = isVisible ? "normal" : "hidden";
|
|
});
|
|
}
|
|
|
|
export function toggleCables(show) {
|
|
cablesVisible = show;
|
|
if (cableLineBatch) cableLineBatch.object.visible = show;
|
|
if (landingPointBatch) landingPointBatch.object.visible = show;
|
|
if (lockedCableRibbonMesh) lockedCableRibbonMesh.visible = Boolean(show);
|
|
cableLines.forEach((cable) => {
|
|
cable.visible = cablesVisible && isLegendItemEnabled("cables", cable.userData?.name || "未知线缆");
|
|
});
|
|
landingPoints.forEach((lp) => {
|
|
lp.visible = cablesVisible && isLandingPointLegendVisible(lp);
|
|
});
|
|
}
|
|
|
|
export function getShowCables() {
|
|
return cablesVisible;
|
|
}
|
|
|
|
function isLandingPointLegendVisible(marker) {
|
|
const names = marker.userData?.cableNames;
|
|
return !names?.length || names.some(name => isLegendItemEnabled("cables", name));
|
|
}
|
|
export function applyCableLegendFilter() {
|
|
toggleCables(cablesVisible);
|
|
cableLines.forEach(line => { line.userData.legend_filtered = !line.visible; });
|
|
landingPoints.forEach(marker => { marker.userData.legend_filtered = !isLandingPointLegendVisible(marker); });
|
|
}
|