Files
Aislo/D03_PlanAnalysis/D03_PlanAnalysis_UI_3D.ts
T
eomsangdonandClaude Opus 5.5 3c098dd8c1 feat(D 예정노선 · B05 3D): 3D 뷰어 여러 벌 덧 · 예정노선 3D = 노선망 전체 표준 횡단 한 번에 (PLAN 601-2 · 601-3 · 요구 463-21)
- B05 뷰어 setCorridors(builds[]) — 벌마다 노면 그룹 · 지형 잘림 = 벌마다 loftDesign 을 한 PSLG 로 합쳐 TIN 한 번 · setCorridor(한 벌) = 옛 길 그대로
- Tin 설계 꼴 outers · roads 칸(있으면 둘레 · 노면 띠 합집합) · 마커 renderRoutes(여러 선)
- D03 3D 모달 = 선 고름 걷음 · 본선 · 갈래 모두 예상 코리도(리핑암 · 산쪽 절토 · 일반 측구 · 계획고 = 지반고) · 갈래 머리 2.0 m 잘라 냄
- test_553_4 3D 단언 새 화면으로(선 고름 없음 · setCorridors)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 14:42:36 +09:00

177 lines
6.7 KiB
TypeScript

/* =============================================================================
* D03_PlanAnalysis_UI_3D.ts
* D03 [3D] 큰 모달(PLAN 530-3 · 563-1 · 601-3 · 요구 463-21) — 사업 전체 DEM + 노선망 전체(본선 · 갈래) 한 번에.
* 선마다 예상 코리도 = 측점 예상 단면(`logic/D03_PlanAnalysis_Expect` · 리핑암 · 산쪽 절토 · 일반 측구 ·
* 계획고 = 지반고) → B05 `buildCorridor` → 뷰어 `setCorridors`(벌마다 노면 · 지형 잘림 한 번) ·
* 갈래 머리 = 부모 노면만큼 잘라 냄 · 뷰어 = B05 `createRouteViewer` · 닫으면 버림(WebGL 문맥까지) · 보기만(저장 없음).
* ========================================================================== */
import "../B05_Profile/B05_Profile_UI_Style.css";
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 { buildCorridor } from "../B05_Profile/logic/B05_Profile_Corridor_Build";
import type { CorridorBuildResult } from "../B05_Profile/logic/B05_Profile_Corridor_Build";
import type { SectionStationMarker } from "../B05_Profile/B05_Profile_UI_Markers";
import { fetchSectionContext } from "../B06_Section/B06_Section_Api_Context";
import type { CrossSection } from "../B06_Section/B06_Section_Api_Types";
import type { Vertex } from "./logic/D03_PlanAnalysis_Plan";
import {
branchTrimM,
expectLine,
expectSections,
type ExpectStandard,
} from "./logic/D03_PlanAnalysis_Expect";
export interface Plan3dLine {
name: string;
line: Vertex[];
/** 갈래(다른 선에 붙은 선) — 머리를 부모 노면만큼 잘라 지음. */
branch: boolean;
}
/** 표준 횡단 기본값(config · 서버) — 못 받으면 null(선만). */
function loadExpectStandard(projectId: string): Promise<ExpectStandard | null> {
return fetchSectionContext(projectId).then(
(context) => ({
standard: context.standard_cross_section as ExpectStandard["standard"],
rockBoundaryM: context.rock_boundary_default_offset_m,
}),
() => null,
);
}
/** 격자 → 뷰어 상자(지형에 붙는 선 · 막대는 높이 원점과 무관 · 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[],
intervalM: number,
): void {
if (!lines.length) return void showToast("3D 로 볼 선이 없습니다.", "warning");
let viewer: RouteViewer | null = createRouteViewer();
const standard = loadExpectStandard(projectId);
const load = async (): Promise<void> => {
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<string, unknown> = { lines: lines.length, done: false };
(window as unknown as { __d03Plan3d?: unknown }).__d03Plan3d = stat;
try {
const [std] = await Promise.all([
standard,
viewer.loadSurface(projectId, surface.modelId, "dtm", true, 5, gridBounds(surface.grid)),
]);
if (!viewer) return;
stat.surfaceMs = Math.round(performance.now() - started);
viewer.markers.renderRoutes(lines.map((item) => item.line.map(([x, y]) => ({ x, y }))));
const built = performance.now();
const trim = std ? branchTrimM(std) : 0;
const markers: SectionStationMarker[] = [];
const builds: CorridorBuildResult[] = [];
const perLine: Array<Record<string, unknown>> = [];
lines.forEach((item, index) => {
const plan = expectLine(item.line, item.branch ? trim : 0, intervalM);
if (!plan) return;
const ground = sectionsGround(plan.line, plan.stations, surface.grid);
ground.stations.forEach((station, i) => {
const chainage = (plan.stations[i] ?? station.chainage_m) + plan.offsetM;
markers.push({
station_id: `${index}:${chainage}`,
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: chainage,
});
});
if (!std) return;
const sections = expectSections(
ground.stations,
std,
surface.grid,
) as unknown as CrossSection[];
const build = buildCorridor(
sections,
plan.line.map(([x, y]) => ({ x, y })),
);
if (build) {
build.sections = sections; // 지형 잘림이 읽음
builds.push(build);
}
perLine.push({
name: item.name,
branch: item.branch,
offsetM: plan.offsetM,
sections: sections.length,
corridor: !!build,
// 노면 중심(설계선 오프셋 0) − 측점 지반고
centerDelta: sections.map((c) =>
c.center_z === null ? null : (c.design?.design_elevation_m ?? NaN) - c.center_z,
),
});
});
viewer.renderStationLines(markers, 2.5);
viewer.setCorridors(builds);
Object.assign(stat, {
trimM: trim,
corridors: builds.length,
stations: markers.length,
buildMs: Math.round(performance.now() - built),
perLine,
});
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();
}
};
openModal({
title: "3D 보기 — 지형 + 노선망(표준 횡단)",
closeLabel: "닫기",
wide: true,
dialogClass: "d03-plan__3d-modal",
mount: (body) => {
body.classList.add("d03-plan__3d-body");
body.append(viewer!.root);
viewer!.setActive(true);
},
beforeClose: () => {
viewer?.dispose();
viewer = null;
return true;
},
});
void load();
}