/* ============================================================================= * D03_PlanAnalysis_UI_3D.ts * D03 [3D] 큰 모달(PLAN 530-3 · 563-1) — 사업 전체 DEM + 그은 선 하나(지반에 붙임) + 측점 막대. * 선 고름 = 모달 위 칸(본선 · 갈래) · 뷰어 = B05 `createRouteViewer` 그대로 · 닫으면 버림(WebGL 문맥까지). * 예상 코리도 없음(꺾은선 · 계획고 = 지반고라 절성토 0 — 요구서 389 3장 11). * ========================================================================== */ import "../B05_Profile/B05_Profile_UI_Style.css"; import { createSelectField } from "@ui/ui_template_input"; import { openModal } from "@ui/ui_template_modal"; import { createProgressCircle } from "@ui/ui_template_progress"; import { showToast } from "@ui/ui_template_elements"; import type { DtmGrid } from "../common_util/common_util_surface_sampler"; import { createRouteViewer, type RouteViewer } from "../B05_Profile/B05_Profile_UI_Viewer"; import { sectionsGround } from "../B05_Profile/logic/B05_Profile_Sections_Ground"; import type { Vertex } from "./logic/D03_PlanAnalysis_Plan"; export interface Plan3dLine { name: string; line: Vertex[]; /** 선 위 측점 누가(선마다 No.0 부터). */ stations: number[]; } /** 격자 → 뷰어 상자(지형에 붙는 선 · 막대는 높이 원점과 무관 · x · y 만 메시와 맞으면 됨). */ function gridBounds(grid: DtmGrid): { x: [number, number]; y: [number, number]; z: [number, number]; } { let low = Infinity; let high = -Infinity; for (const z of grid.z) { if (!Number.isFinite(z)) continue; if (z < low) low = z; if (z > high) high = z; } return { x: [grid.x[0], grid.x[grid.x.length - 1]], y: [grid.y[0], grid.y[grid.y.length - 1]], z: [low, high], }; } export function openPlan3d( projectId: string, surface: { modelId: number; grid: DtmGrid }, lines: Plan3dLine[], ): void { if (!lines.length) return void showToast("3D 로 볼 선이 없습니다.", "warning"); let viewer: RouteViewer | null = createRouteViewer(); let loaded = false; const pick = createSelectField({ options: lines.map((item, i) => ({ value: String(i), text: item.name })), value: "0", size: 28, ariaLabel: "선", }).select; pick.classList.add("d03-plan__3d-year"); const top = document.createElement("div"); top.className = "d03-plan__3d-top"; top.append(pick); const load = async (index: number): Promise => { const item = lines[index] ?? lines[0]; if (!viewer) return; const progress = createProgressCircle({ label: "3D 지형을 불러오는 중…", overlay: true }); progress.set(null); viewer.root.append(progress.root); const started = performance.now(); const stat: Record = { line: item.name, done: false }; (window as unknown as { __d03Plan3d?: unknown }).__d03Plan3d = stat; try { if (!loaded) { await viewer.loadSurface( projectId, surface.modelId, "dtm", true, 5, gridBounds(surface.grid), ); loaded = true; } if (!viewer) return; viewer.markers.renderRoute(item.line.map(([x, y]) => ({ x, y }))); const ground = sectionsGround(item.line, item.stations, surface.grid); viewer.renderStationLines( ground.stations.map((station, i) => ({ station_id: String(item.stations[i] ?? station.chainage_m), center_x: station.center_x, center_y: station.center_y, center_z: station.center_z, frame: { left_xy: station.left_xy }, kind: "regular", chainage_m: item.stations[i] ?? station.chainage_m, })), 2.5, ); stat.stations = ground.stations.length; viewer.setView("iso"); } catch (error) { showToast(error instanceof Error ? error.message : "3D 지형을 불러오지 못했습니다.", "error"); } finally { stat.done = true; stat.totalMs = Math.round(performance.now() - started); progress.remove(); } }; pick.addEventListener("change", () => void load(Number(pick.value))); openModal({ title: "3D 보기 — 지형 + 그은 선", closeLabel: "닫기", wide: true, dialogClass: "d03-plan__3d-modal", mount: (body) => { body.classList.add("d03-plan__3d-body"); body.append(top, viewer!.root); viewer!.setActive(true); }, beforeClose: () => { viewer?.dispose(); viewer = null; return true; }, }); void load(0); }