Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3556e25e96 | ||
|
|
e27fd17eb8 | ||
|
|
34afaa6941 | ||
|
|
d00b4e3316 | ||
|
|
ac08c129bd |
+1
-6
@@ -2,15 +2,10 @@
|
||||
bin/
|
||||
obj/
|
||||
publish/
|
||||
Publish/ # publish-winapp 打包產物(大小寫明確,Linux/CI 也忽略)
|
||||
*.user
|
||||
.vs/
|
||||
|
||||
# secret/ 全部忽略,但保留 README 與範本
|
||||
secret/*
|
||||
!secret/README.md
|
||||
!secret/*.example
|
||||
!secret/.gitkeep
|
||||
|
||||
# AI 協作素材不入 git
|
||||
For_AI/
|
||||
|
||||
|
||||
+27
-14
@@ -65,8 +65,11 @@ STEP(`.stp` / `.step`)檔案做確認與量測,不需要安裝 SolidWorks
|
||||
|
||||
資料流:`*.stp → CADability B-rep → 三角網格(渲染) + B-rep 參照(量測) → Helix Viewport`
|
||||
|
||||
每個 Face 對應一個 `GeometryModel3D`,並登錄到 `Dictionary<GeometryModel3D, FaceInfo>`,
|
||||
HitTest 命中後可反查回 B-rep Face / Edge 做精確量測。
|
||||
每個 Face 對應一個 `GeometryModel3D`(`FacesContent`,剖面模式渲染用),並登錄到 `_faceMap` 反查 B-rep Face / Edge。
|
||||
|
||||
效能:非剖面(瀏覽+量測)渲染**整零件合併網格**(`MergedContent`,每檔 1 個 model),量測 HitTest 改打合併網格、
|
||||
用命中三角形的頂點 index 經 `_mergedFaceRanges` 二分搜尋(`ResolveMergedFace`)反查回是哪個面 —
|
||||
量測模式不再掛數萬個逐面 model,大組件量測下轉動視角與瀏覽同樣流暢(v0.3.2)。
|
||||
|
||||
---
|
||||
|
||||
@@ -78,17 +81,12 @@ STPViewer/
|
||||
├── CLAUDE.md # 專案記憶 & 給 Claude 的指令
|
||||
├── README.md # 快速上手
|
||||
├── ARCHITECTURE.md # 本文件
|
||||
├── .gitignore # 含 secret/ 與 For_AI/ 規則
|
||||
├── .gitignore # For_AI/ + *.stp/*.step(客戶料號)規則
|
||||
│
|
||||
├── docs/
|
||||
│ ├── decisions/ # 技術決策紀錄(ADR)
|
||||
│ └── runbooks/ # 操作手冊
|
||||
│
|
||||
├── secret/ # 🚫 gitignored(README.md / *.example 除外)
|
||||
│ ├── README.md
|
||||
│ ├── run-STPViewer.ps1.example
|
||||
│ └── run-STPViewer.sh.example
|
||||
│
|
||||
├── For_AI/ # 🚫 gitignored — AI 協作素材 + 測試模型 *.stp(客戶料號不入 git)
|
||||
│
|
||||
├── STPViewer.sln
|
||||
@@ -203,12 +201,9 @@ class MeasurementResult
|
||||
|
||||
## Security Considerations
|
||||
|
||||
- 純離線桌面工具,無網路、無帳號、無資料庫
|
||||
- 本專案目前無任何 runtime secret;`secret/` 仍依專案慣例建立:
|
||||
- `secret/*` 全部 gitignore,僅 `README.md`、`*.example` 進 git
|
||||
- `run-STPViewer.*.example` 為啟動腳本範本(本專案無 DB/ApiKey,腳本僅做 build+run)
|
||||
- 無 compile-time secret → 不需 `publish-*.example` 腳本
|
||||
- `For_AI/` 收 AI 協作素材(截圖、筆記),整夾 gitignore
|
||||
- 純離線桌面工具,無網路、無帳號、無資料庫、無任何 runtime / compile-time secret(故未建 `secret/` 資料夾)
|
||||
- `For_AI/` 收 AI 協作素材(截圖、筆記)+ 測試模型 `*.stp`(客戶料號),整夾 gitignore
|
||||
- `*.stp` / `*.step` 全域 gitignore:客戶 CAD 料號檔不入 git,避免外流
|
||||
|
||||
---
|
||||
|
||||
@@ -344,6 +339,24 @@ NuGet 相依(自動還原):`CADability`、`HelixToolkit.Wpf`、`CommunityT
|
||||
|
||||
---
|
||||
|
||||
## Development Phases — 第四輪(效能,全部完成)
|
||||
|
||||
### Phase 12 — 大組件量測流暢度(工作量:M)
|
||||
|
||||
**問題:** 大檔(39MB / 64k 面)瀏覽轉動順,但一進量測模式轉動就嚴重卡頓。
|
||||
**根因:** 量測模式渲染逐面(每個 B-rep 面 1 個 `GeometryModel3D`),64k 面 = 64k draw call,
|
||||
WPF retained-mode 每幀重走 visual tree → frame rate 崩。瀏覽模式因渲染合併網格(每檔 1 個 model)所以順。
|
||||
|
||||
- [x] 量測拾取改打**合併網格** + 三角形頂點 index 反查面(`_mergedFaceRanges` + `ResolveMergedFace` 二分搜尋)
|
||||
- [x] `ApplyRenderMode()` 改為:非剖面(瀏覽+量測)→ 合併網格;剖面 → 逐面。量測模式不再掛數萬個逐面 model
|
||||
- [x] `BuildMergedMesh` 依面序串接(無焊接共用頂點),匯入時同步記錄每面頂點起始邊界 + `FaceInfo`
|
||||
- [x] 相機暫停事件改訂 `HelixViewport3D.CameraChanged`(控制項層級)+ `Camera.Changed` 保底,避免相機實例被換掉時訂閱孤兒化
|
||||
- [x] 驗證:WPF 3D hit-test 純幾何不剔背面 → 打單面合併網格仍命中孔內壁;圓/面/邊/角度/面距/剖面量測數值與逐面一致
|
||||
|
||||
**驗收:** 大組件量測模式下轉動視角與瀏覽同樣流暢;圓孔/面/邊/角度/面距量測精度不變;剖面模式量測仍正常
|
||||
|
||||
---
|
||||
|
||||
## Future Extensions(下一輪)
|
||||
|
||||
- 剖切面封口(cap)填實(目前剖開處可見內部背面材質)
|
||||
|
||||
@@ -27,11 +27,16 @@ dotnet publish src/STPViewer -c Release -o publish/STPViewer
|
||||
## 開發慣例
|
||||
|
||||
- MVVM:邏輯寫 ViewModel/Service,code-behind 只做純 View 事件(滑鼠拾取轉發)
|
||||
- 一個 B-rep Face = 一個 `GeometryModel3D`,用 `Dictionary<Model3D, FaceInfo>` 反查(量測拾取靠這個,**不可移除逐面結構**)
|
||||
- 渲染雙模式(降 draw call):每個 leaf 同時持有 `FacesContent`(逐面,量測用)與 `MergedContent`(整零件合併成 1 個 `GeometryModel3D`,瀏覽用)。
|
||||
`ApplyRenderMode()` 依狀態切 `BodyVisual.Content`:**瀏覽(None)且未剖面 → 合併網格**;量測模式或剖面 → 逐面。
|
||||
合併網格只代表「未剖切、目前位置」幾何;平移後呼叫 `RebuildMerged(leaf)` 同步。`_faceMap`/量測/剖面/干涉一律走 `FacesContent`,與目前顯示哪種內容無關
|
||||
- 合併網格的 `BackMaterial`:封閉實體(`SolidCount≥1` 且 `HasBrep`)**不設**(WPF 兩面渲染成本砍半);開放殼/STL 才設。逐面 `FacesContent` 一律保留 BackMaterial(剖切要看內部)
|
||||
- 一個 B-rep Face = 一個 `GeometryModel3D`,用 `Dictionary<Model3D, FaceInfo>` (`_faceMap`) 反查(剖面模式逐面拾取靠這個,**不可移除逐面結構**)
|
||||
- 渲染雙模式(降 draw call):每個 leaf 同時持有 `FacesContent`(逐面,剖面用)與 `MergedContent`(整零件合併成 1 個 `GeometryModel3D`)。
|
||||
`ApplyRenderMode()` 依狀態切 `BodyVisual.Content`:**非剖面(瀏覽+量測皆是)→ 合併網格**;**剖面 → 逐面**(要顯示各面裁切後幾何)。
|
||||
合併網格只代表「未剖切、目前位置」幾何;平移後呼叫 `RebuildMerged(leaf)` 同步。剖面/干涉/`RebuildMerged` 一律走 `FacesContent`,與目前顯示哪種內容無關
|
||||
- ⚡ **量測拾取打合併網格、用三角形頂點 index 反查面**(`_mergedFaceRanges`:合併 Model → (每面頂點起始邊界, FaceInfo[]))。
|
||||
`BuildMergedMesh` 依面序串接(`baseIdx += positions.Count`,無焊接共用頂點),故命中 `RayHit.VertexIndex1` 可二分搜尋(`ResolveMergedFace`)回是哪個面。
|
||||
**這是 v0.3.2 修大檔量測卡頓的關鍵**:量測模式不再掛數萬個逐面 `GeometryModel3D`(64k 面實測 = 64k draw call,轉動/停下重繪爆量)→ 改成每檔 1 個 model,量測模式 orbit 與瀏覽同樣順。
|
||||
邊界由面頂點數決定、平移不改 → 永久有效,`RebuildMerged` 不需重算。**不要因為「量測要逐面」而把渲染改回逐面**
|
||||
- 合併網格的 `BackMaterial`:封閉實體(`SolidCount≥1` 且 `HasBrep`)**不設**(WPF 兩面渲染成本砍半);開放殼/STL 才設。
|
||||
**拾取不受材質影響**(WPF 3D hit-test 純幾何、不剔背面),故打合併網格仍命中孔內壁等背向面。逐面 `FacesContent` 一律保留 BackMaterial(剖切要看內部)
|
||||
- 量測值以 B-rep 為準(圓半徑、邊長、角度),面積/面距用網格近似
|
||||
- 量測文字一律 `Func<UnitSystem,string>` 延後產生(mm⇄inch 即時切換);內部數值永遠存 mm
|
||||
- 裝配樹節點(`ModelNodeViewModel`)的可見性/邊線/顏色向下 cascade
|
||||
@@ -72,8 +77,9 @@ dotnet publish src/STPViewer -c Release -o publish/STPViewer
|
||||
- 邊線採「**一檔一條合併 `LinesVisual3D`**」(掛在 root `EdgeVisual`,由 `RefreshRootEdges` 收集各 leaf `OriginalEdgePoints` 重建)。
|
||||
**不要改回逐 leaf 一條** — 裝配樹零件多時,N 條線每幀重建會嚴重卡頓(實測主因)。leaf 只保留邊線「資料」,渲染統一在 root;
|
||||
可見性/ShowEdges/剖面/平移變更時呼叫 `RefreshRootEdges(root)` 重組合併線
|
||||
- 互動中暫停邊線:`Attach` 掛 `Camera.Changed` → `OnCameraMoved` 隱藏邊線、`_interactionTimer`(180ms) 停下後 `ResumeEdges` 顯示;
|
||||
`_edgesSuspended` 為真時 `RefreshRootEdges` 不把線掛回。轉動/縮放/平移時不付邊線重建成本
|
||||
- 互動中暫停邊線:`Attach` 掛 **`HelixViewport3D.CameraChanged`(控制項層級 routed event)+ `Camera.Changed`(保底)** → `OnCameraMoved` 隱藏邊線、`_interactionTimer`(180ms) 停下後 `ResumeEdges` 顯示;
|
||||
`_edgesSuspended` 為真時 `RefreshRootEdges` 不把線掛回。轉動/縮放/平移時不付邊線重建成本。
|
||||
**只訂 `Camera.Changed` 不夠**:`Attach` 在建構式呼叫,相機實例若被 Helix 換掉訂閱會孤兒化 → 暫停永不觸發;故加訂控制項層級事件保底(重複觸發 `OnCameraMoved` 無害,有 guard)
|
||||
- CADability `ImportStep` 對少數 AP242 檔案支援不完整;匯入失敗要 catch 顯示訊息,不可閃退
|
||||
- IGES 無 reader;STL 無 B-rep(FaceInfo.BrepFace == null 的分支要保留)
|
||||
- 不寫入原始檔(唯讀工具);WPF 限 Windows,不要嘗試移植 vbox/Linux
|
||||
@@ -82,8 +88,7 @@ dotnet publish src/STPViewer -c Release -o publish/STPViewer
|
||||
`--align-test`(三點對齊剛體變換 + ModOp↔Matrix3D 一致性)、`--make-dxf`(產測試檔)
|
||||
- **絕不要用 PowerShell regex/Set-Content 改 .cs 檔** — Windows PowerShell 5.1 預設編碼會把 UTF-8 中文弄成亂碼(已踩過,靠反編譯 DLL 救回)。文字取代一律用 Edit 工具
|
||||
|
||||
## secret/ 與 For_AI/
|
||||
## For_AI/
|
||||
|
||||
- `secret/`:本機敏感資料集中地,`secret/*` gitignored(`README.md`、`*.example` 除外)。
|
||||
本專案無 runtime secret,僅有啟動腳本範本。
|
||||
- `For_AI/`:AI 協作素材(截圖、草稿),整夾 gitignored。
|
||||
- `For_AI/`:AI 協作素材(截圖、草稿)+ 測試模型 `*.stp`(客戶料號),整夾 gitignored。
|
||||
- 本專案無 runtime secret(離線桌面工具,無 DB/ApiKey),故未保留 `secret/` 資料夾。
|
||||
|
||||
@@ -1,71 +1,199 @@
|
||||
# STPViewer
|
||||
|
||||
STP/STEP 3D 檢視器(Windows 桌面程式,C# .NET 8 WPF)— 多檔匯入、圖層管理、點/距離/邊/面/圓量測。
|
||||
[](README.md) [](README.zh-TW.md)
|
||||
|
||||
  
|
||||
> A Windows desktop 3D viewer for STP/STEP CAD files — multi-file import, assembly tree, and point / distance / edge / face / circle measurement. Built with C# .NET 8 WPF.
|
||||
|
||||
## 功能
|
||||
   
|
||||
|
||||
- **多檔匯入**:STEP / STL / DXF — 工具列匯入(可複選)、拖放到視窗、或命令列 `STPViewer.exe a.stp b.stl`
|
||||
- **裝配樹**:STEP product structure 還原成樹(組件→零件),逐節點 顯示/隱藏、換色(cascade)、Zoom-to;檔案層級可移除、開關輪廓邊線
|
||||
- **量測**(工具列切換模式,點擊模型):
|
||||
| 模式 | 輸出 |
|
||||
---
|
||||
|
||||
## 📖 Table of Contents
|
||||
|
||||
- [✨ Features](#-features)
|
||||
- [💻 System Requirements](#-system-requirements)
|
||||
- [📥 Installation](#-installation)
|
||||
- [🚀 Quick Start](#-quick-start)
|
||||
- [📚 Usage Guide](#-usage-guide)
|
||||
- [🔨 Building from Source](#-building-from-source)
|
||||
- [📁 Project Structure](#-project-structure)
|
||||
- [⚠️ Known Limitations](#️-known-limitations)
|
||||
- [🤝 Contributing](#-contributing)
|
||||
- [📜 Version History](#-version-history)
|
||||
- [🙏 Acknowledgments](#-acknowledgments)
|
||||
|
||||
---
|
||||
|
||||
## ✨ Features
|
||||
|
||||
Open mechanical STEP parts for quick review and measurement without a heavyweight CAD suite (SolidWorks / Creo).
|
||||
|
||||
- **Multi-file import** — STEP / STL / DXF, via the toolbar (multi-select), drag-and-drop, or command line: `STPViewer.exe a.stp b.stl`
|
||||
- **Assembly tree** — STEP product structure restored as a tree (assembly → part); per-node show/hide, recolor (cascades to children), zoom-to; file-level remove and outline-edge toggle
|
||||
- **Measurement** (toolbar mode toggle, then click the model):
|
||||
|
||||
| Mode | Output |
|
||||
|---|---|
|
||||
| 📍 點 | XYZ 座標(自動吸附鄰近 B-rep 頂點) |
|
||||
| 📏 距離 | 兩點直線距離 + ΔX/ΔY/ΔZ |
|
||||
| 📐 邊 | 直線長 / 曲線長 / 圓弧長+半徑 |
|
||||
| ⬛ 面 | 面積(網格近似)+ 曲面類型(平面法向量、圓柱半徑/軸向) |
|
||||
| ⭕ 圓 | 圓心 / 半徑 / 直徑 / 周長 |
|
||||
| ∠ 角度 | 兩面(法向量)/ 兩直線邊 夾角 + 補角 |
|
||||
| ⇔ 面距 | 面到面最短距離(網格近似)+ 最近點對 |
|
||||
| ⤚ 對齊 | 點「要移動零件」一點 + 目標點 → 純平移該檔案使兩點貼合(B-rep 整體位移) |
|
||||
| 🎯 三點 | 來源檔 3 特徵點 + 目標檔 3 對應點 → 旋轉+平移一次貼合(方向不同也能對) |
|
||||
- **旋轉**:樹面板選檔案 + 工具列 ↻X/↻Y/↻Z 繞中心 +90°(擺正方向用,連按累加)
|
||||
- **拖曳** 🖐:手形游標模式,左鍵按住零件沿螢幕平面拖動、放開定位(粗定位用;精確貼合用對齊);右鍵轉視角不受影響
|
||||
- **操作器** ⊹:樹面板選檔案 → 顯示 XYZ 三色箭頭 + 旋轉環(Fusion 360 風格);拖箭頭沿該軸移動(與視角無關,適合沿插合軸推進)、拖環繞軸轉任意角度,放開即定位。操作器永遠浮在最上層、不被實體遮擋
|
||||
- **干涉檢查** 🧩:勾選剛好 2 個可見檔案 → 相交時顯示紅色干涉交線 + 相交三角形對數;無相交時回報最小間隙 gap(gap≈0 即為配合 match,共面貼合不算干涉)
|
||||
- **剖面**:✂ 開關 + X/Y/Z 軸 + 位置滑桿 + 反向;CPU 網格裁切,原始幾何保留(量測不受影響)
|
||||
- **單位**:mm ⇄ inch 一鍵切換,既有量測(清單與 3D 標籤)即時換算
|
||||
- **匯出**:量測結果 CSV(Excel 中文不亂碼)、3D 視圖 PNG 截圖(2x 解析度)
|
||||
- **視角**:右鍵旋轉、滾輪縮放、中鍵平移、ViewCube
|
||||
| 📍 Point | XYZ coordinate (auto-snaps to nearby B-rep vertex) |
|
||||
| 📏 Distance | Straight-line distance + ΔX/ΔY/ΔZ |
|
||||
| 📐 Edge | Line length / curve length / arc length + radius |
|
||||
| ⬛ Face | Area (mesh approximation) + surface type (plane normal, cylinder radius/axis) |
|
||||
| ⭕ Circle | Center / radius / diameter / circumference |
|
||||
| ∠ Angle | Angle between two faces (normals) or two straight edges + supplement |
|
||||
| ⇔ Face distance | Shortest face-to-face distance (mesh approximation) + closest point pair |
|
||||
| ⤚ Align (2-pt) | Pick a point on the moving part + a target point → pure translation so the two points coincide |
|
||||
| 🎯 Align (3-pt) | 3 source points + 3 target points → rotation + translation in one shot |
|
||||
|
||||
## 快速開始
|
||||
- **Rotate** — select a file in the tree, then ↻X / ↻Y / ↻Z to rotate +90° about its center (for re-orienting; repeat to accumulate)
|
||||
- **Drag** 🖐 — hand-cursor mode; hold the left button to drag a part along the screen plane, release to place (right-button view orbit unaffected)
|
||||
- **Gizmo** ⊹ — select a file → XYZ tri-color arrows + rotation rings (Fusion 360 style); drag an arrow to move along that axis (view-independent), drag a ring to rotate. Always floats on top, never occluded
|
||||
- **Interference check** 🧩 — with exactly 2 visible files, shows red intersection curves + intersecting triangle-pair count; otherwise reports the minimum gap (gap ≈ 0 means a fit/match; coplanar contact is not interference)
|
||||
- **Section plane** ✂ — X/Y/Z axis + position slider + flip; CPU mesh clipping, original geometry preserved (measurement stays exact)
|
||||
- **Units** — one-click mm ⇄ inch; existing measurements (list + 3D labels) convert live
|
||||
- **Export** — measurement results to CSV (UTF-8 BOM, no mojibake in Excel) and a 2× PNG screenshot of the 3D view
|
||||
- **View** — right-button orbit, wheel zoom, middle-button pan, ViewCube
|
||||
|
||||
Measurement principle: edge length, circle radius and angles use **exact B-rep values**; area is a triangle-mesh sum approximation (triangulation precision adapts to model size, 0.02–0.5 mm).
|
||||
|
||||
---
|
||||
|
||||
## 💻 System Requirements
|
||||
|
||||
| Item | Requirement |
|
||||
|------|-------------|
|
||||
| OS | Windows 10 / 11 (x64) |
|
||||
| Runtime | .NET 8 Desktop Runtime (framework-dependent build) — or none for the portable build |
|
||||
| Build SDK | .NET 8 SDK (only to build from source) |
|
||||
|
||||
---
|
||||
|
||||
## 📥 Installation
|
||||
|
||||
Download a release build and run it — no install required.
|
||||
|
||||
- **Framework-dependent** (smaller): requires the .NET 8 Desktop Runtime. Run `STPViewer v0.3.2.exe`.
|
||||
- **Portable** (self-contained): runtime bundled, no install / admin. Run `STPViewer v0.3.2.exe`.
|
||||
|
||||
Or build from source (see below).
|
||||
|
||||
```bash
|
||||
git clone https://github.com/ETWen/STPViewer.git
|
||||
cd STPViewer
|
||||
dotnet build STPViewer.sln
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🚀 Quick Start
|
||||
|
||||
```bash
|
||||
# Build and run
|
||||
dotnet build STPViewer.sln
|
||||
dotnet run --project src/STPViewer
|
||||
|
||||
# 發佈免安裝資料夾
|
||||
# Publish a no-install folder
|
||||
dotnet publish src/STPViewer -c Release -o publish/STPViewer
|
||||
```
|
||||
|
||||
無 UI 匯入管線與幾何數學驗證:
|
||||
Then import a `.stp` file (toolbar **Import**, drag-and-drop, or command-line argument), pick a measurement mode, and click the model.
|
||||
|
||||
---
|
||||
|
||||
## 📚 Usage Guide
|
||||
|
||||
1. **Import** one or more CAD files. Each file becomes a root in the assembly tree and the view zooms to fit.
|
||||
2. **Navigate** the tree — toggle visibility, recolor, zoom to a node, or remove a file.
|
||||
3. **Measure** — pick a mode on the toolbar (Point / Distance / Edge / Face / Circle / Angle / Face-distance), then click the model. Results appear in the right-hand panel; delete individually or clear all.
|
||||
4. **Assemble** — use Align (2-pt / 3-pt), Rotate, Drag, or the Gizmo to position parts; then run the Interference check to verify fit.
|
||||
5. **Section** — toggle ✂, choose an axis, and slide to cut through the model; measurement stays exact on the original geometry.
|
||||
6. **Export** — save measurements to CSV or capture a 2× PNG of the view.
|
||||
|
||||
Headless import-pipeline and geometry-math verification (no UI):
|
||||
|
||||
```bash
|
||||
dotnet run --project tools/SmokeTest -- "path\to\model.stp" # 匯入 + 裝配樹
|
||||
dotnet run --project tools/SmokeTest -- --clip-test # 剖切裁切數學
|
||||
dotnet run --project tools/SmokeTest -- --interference-test # 干涉 相交/分離/貼合
|
||||
dotnet run --project tools/SmokeTest -- --align-test # 三點對齊剛體變換數學
|
||||
dotnet run --project tools/SmokeTest -- "path\to\model.stp" # import + assembly tree
|
||||
dotnet run --project tools/SmokeTest -- --clip-test # section clipping math
|
||||
dotnet run --project tools/SmokeTest -- --interference-test # interference: intersect / separate / contact
|
||||
dotnet run --project tools/SmokeTest -- --align-test # 3-point rigid-transform math
|
||||
```
|
||||
|
||||
## 技術棧
|
||||
---
|
||||
|
||||
| 元件 | 用途 |
|
||||
|---|---|
|
||||
| [CADability](https://github.com/SOFAgh/CADability)(純 C#) | STEP 匯入、B-rep 幾何核心、面三角化 |
|
||||
| [HelixToolkit.Wpf](https://github.com/helix-toolkit/helix-toolkit) | 3D viewport、相機操作、HitTest |
|
||||
| CommunityToolkit.Mvvm | MVVM |
|
||||
## 🔨 Building from Source
|
||||
|
||||
量測原則:邊長、圓半徑等取 **B-rep 精確值**;面積為三角網格加總近似(三角化精度依模型尺寸自適應 0.02–0.5 mm)。
|
||||
```bash
|
||||
dotnet build STPViewer.sln -c Debug
|
||||
dotnet run --project src/STPViewer
|
||||
dotnet publish src/STPViewer -c Release -o publish/STPViewer
|
||||
```
|
||||
|
||||
## 已知限制
|
||||
NuGet dependencies (restored automatically): `CADability`, `HelixToolkit.Wpf`, `CommunityToolkit.Mvvm`.
|
||||
|
||||
- 大型 STEP(數千面)匯入需數十秒(CADability 解析成本),匯入期間 UI 有進度提示不凍結
|
||||
- 輪廓邊線超過 30,000 線段的檔案預設關閉邊線(WPF LinesVisual3D 轉動視角時效能限制),可在樹面板手動開啟
|
||||
- **IGES 不支援**(CADability 無 IGES reader);STL 無 B-rep,僅支援 點/距離/角度/面距 量測;DXF 為線架構檢視
|
||||
- 剖切面無封口(cap),剖開處顯示內部背面材質(深灰)
|
||||
- 面積與面距為三角網格近似值;邊長/圓半徑/角度為 B-rep 精確值
|
||||
- 少數 AP242 檔案 CADability 支援不完整,匯入失敗會提示訊息(不閃退)
|
||||
- 唯讀檢視器,不寫入/修改原始檔案
|
||||
---
|
||||
|
||||
詳細設計與開發 Phase 見 [ARCHITECTURE.md](ARCHITECTURE.md)。
|
||||
## 📁 Project Structure
|
||||
|
||||
```
|
||||
STPViewer/
|
||||
├── ARCHITECTURE.md # Design, data flow, development phases
|
||||
├── CLAUDE.md # Project memory & engineering conventions
|
||||
├── STPViewer.sln
|
||||
├── src/STPViewer/
|
||||
│ ├── STPViewer.csproj # net8.0-windows, UseWPF, single-source <Version>
|
||||
│ ├── MainWindow.xaml / .cs # Layout + mouse-pick forwarding
|
||||
│ ├── Models/ # FaceInfo, MeasureMode, MeasurementResult, UnitSystem
|
||||
│ ├── Services/ # StepImport, Measurement, Interference, Section, RigidAlign
|
||||
│ └── ViewModels/ # MainViewModel, ModelNodeViewModel (assembly tree)
|
||||
└── tools/SmokeTest/ # Headless import + geometry-math verification
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## ⚠️ Known Limitations
|
||||
|
||||
- Large STEP files (thousands of faces) take tens of seconds to import (CADability parse cost); a progress indicator keeps the UI responsive.
|
||||
- Files with more than 30,000 outline segments disable edges by default (WPF `LinesVisual3D` cost while orbiting); re-enable per file in the tree.
|
||||
- **IGES is not supported** (CADability has no IGES reader). STL has no B-rep (point / distance / angle / face-distance only). DXF is wireframe view.
|
||||
- Section cuts have no cap fill — the opened face shows the interior back material (dark gray).
|
||||
- Area and face-distance are mesh approximations; edge length / circle radius / angle are exact B-rep values.
|
||||
- A few AP242 files are incompletely supported by CADability; failed imports show a message (no crash).
|
||||
- Read-only viewer — never writes to or modifies the source file.
|
||||
|
||||
---
|
||||
|
||||
## 🤝 Contributing
|
||||
|
||||
1. Fork and create a feature branch: `git checkout -b feature/your-feature`
|
||||
2. Follow [Conventional Commits](https://www.conventionalcommits.org/): `feat(scope): summary`
|
||||
3. Push and open a Pull Request
|
||||
|
||||
---
|
||||
|
||||
## 📜 Version History
|
||||
|
||||
### v0.3.2
|
||||
|
||||
- **Perf:** large-assembly measurement no longer lags while orbiting. Measurement modes now render the merged mesh (one model per file) and resolve the picked face from the hit triangle's vertex index, instead of rendering tens of thousands of per-face models. Per-face rendering is kept only for section mode.
|
||||
- Camera-interaction suspension now also subscribes to `HelixViewport3D.CameraChanged` so it can't be orphaned if the camera instance is replaced.
|
||||
|
||||
### v0.3.1
|
||||
|
||||
- Gizmo always-on-top overlay (manipulator floats above parts, never occluded).
|
||||
|
||||
### v0.3.0
|
||||
|
||||
- Rotation alignment: axis rotate (↻X/↻Y/↻Z), 3-point align, and the unified `TransformRoot` rigid-transform path.
|
||||
|
||||
### v0.2.x
|
||||
|
||||
- Drag mode, 2-point align, interference check, section plane, angle / face-distance measurement, assembly tree, STL / DXF support, mm ⇄ inch.
|
||||
|
||||
---
|
||||
|
||||
## 🙏 Acknowledgments
|
||||
|
||||
- [CADability](https://github.com/SOFAgh/CADability) — pure-C# CAD kernel: STEP import, B-rep geometry, face triangulation
|
||||
- [HelixToolkit.Wpf](https://github.com/helix-toolkit/helix-toolkit) — 3D viewport, camera control, hit testing
|
||||
- [CommunityToolkit.Mvvm](https://github.com/CommunityToolkit/dotnet) — MVVM
|
||||
|
||||
See [ARCHITECTURE.md](ARCHITECTURE.md) for the full design and development phases.
|
||||
|
||||
+199
@@ -0,0 +1,199 @@
|
||||
# STPViewer
|
||||
|
||||
[](README.md) [](README.zh-TW.md)
|
||||
|
||||
> STP/STEP 3D 檢視器(Windows 桌面程式,C# .NET 8 WPF)— 多檔匯入、裝配樹、點/距離/邊/面/圓量測。
|
||||
|
||||
   
|
||||
|
||||
---
|
||||
|
||||
## 📖 目錄
|
||||
|
||||
- [✨ 功能特色](#-功能特色)
|
||||
- [💻 系統需求](#-系統需求)
|
||||
- [📥 安裝](#-安裝)
|
||||
- [🚀 快速開始](#-快速開始)
|
||||
- [📚 使用指南](#-使用指南)
|
||||
- [🔨 從原始碼建置](#-從原始碼建置)
|
||||
- [📁 專案結構](#-專案結構)
|
||||
- [⚠️ 已知限制](#️-已知限制)
|
||||
- [🤝 貢獻](#-貢獻)
|
||||
- [📜 版本紀錄](#-版本紀錄)
|
||||
- [🙏 致謝](#-致謝)
|
||||
|
||||
---
|
||||
|
||||
## ✨ 功能特色
|
||||
|
||||
快速開啟機構件 STEP 檔做確認與量測,不需安裝 SolidWorks / Creo 等重量級 CAD。
|
||||
|
||||
- **多檔匯入** — STEP / STL / DXF,工具列匯入(可複選)、拖放到視窗,或命令列 `STPViewer.exe a.stp b.stl`
|
||||
- **裝配樹** — STEP product structure 還原成樹(組件→零件);逐節點 顯示/隱藏、換色(cascade)、Zoom-to;檔案層級可移除、開關輪廓邊線
|
||||
- **量測**(工具列切換模式,點擊模型):
|
||||
|
||||
| 模式 | 輸出 |
|
||||
|---|---|
|
||||
| 📍 點 | XYZ 座標(自動吸附鄰近 B-rep 頂點) |
|
||||
| 📏 距離 | 兩點直線距離 + ΔX/ΔY/ΔZ |
|
||||
| 📐 邊 | 直線長 / 曲線長 / 圓弧長 + 半徑 |
|
||||
| ⬛ 面 | 面積(網格近似)+ 曲面類型(平面法向量、圓柱半徑/軸向) |
|
||||
| ⭕ 圓 | 圓心 / 半徑 / 直徑 / 周長 |
|
||||
| ∠ 角度 | 兩面(法向量)/ 兩直線邊 夾角 + 補角 |
|
||||
| ⇔ 面距 | 面到面最短距離(網格近似)+ 最近點對 |
|
||||
| ⤚ 對齊(兩點) | 點「要移動零件」一點 + 目標點 → 純平移使兩點貼合 |
|
||||
| 🎯 對齊(三點) | 來源檔 3 點 + 目標檔 3 對應點 → 旋轉+平移一次貼合 |
|
||||
|
||||
- **旋轉** — 樹面板選檔案 + 工具列 ↻X/↻Y/↻Z 繞中心 +90°(擺正方向用,連按累加)
|
||||
- **拖曳** 🖐 — 手形游標模式,左鍵按住零件沿螢幕平面拖動、放開定位(右鍵轉視角不受影響)
|
||||
- **操作器** ⊹ — 樹面板選檔案 → XYZ 三色箭頭 + 旋轉環(Fusion 360 風格);拖箭頭沿該軸移動(與視角無關)、拖環繞軸轉。永遠浮在最上層、不被實體遮擋
|
||||
- **干涉檢查** 🧩 — 勾選剛好 2 個可見檔案 → 相交時顯示紅色干涉交線 + 相交三角形對數;無相交時回報最小間隙 gap(gap≈0 即為配合 match,共面貼合不算干涉)
|
||||
- **剖面** ✂ — X/Y/Z 軸 + 位置滑桿 + 反向;CPU 網格裁切,原始幾何保留(量測仍精確)
|
||||
- **單位** — mm ⇄ inch 一鍵切換,既有量測(清單與 3D 標籤)即時換算
|
||||
- **匯出** — 量測結果 CSV(UTF-8 BOM,Excel 中文不亂碼)、3D 視圖 2× PNG 截圖
|
||||
- **視角** — 右鍵旋轉、滾輪縮放、中鍵平移、ViewCube
|
||||
|
||||
量測原則:邊長、圓半徑、角度取 **B-rep 精確值**;面積為三角網格加總近似(三角化精度依模型尺寸自適應 0.02–0.5 mm)。
|
||||
|
||||
---
|
||||
|
||||
## 💻 系統需求
|
||||
|
||||
| 項目 | 需求 |
|
||||
|------|------|
|
||||
| 作業系統 | Windows 10 / 11(x64) |
|
||||
| 執行階段 | .NET 8 Desktop Runtime(框架相依版)— Portable 版則免裝 |
|
||||
| 建置 SDK | .NET 8 SDK(僅從原始碼建置時需要) |
|
||||
|
||||
---
|
||||
|
||||
## 📥 安裝
|
||||
|
||||
下載發佈版直接執行,免安裝。
|
||||
|
||||
- **框架相依版**(檔案較小):需 .NET 8 Desktop Runtime,執行 `STPViewer v0.3.2.exe`。
|
||||
- **Portable 版**(self-contained):內含 runtime,免安裝 / 免系統管理員,執行 `STPViewer v0.3.2.exe`。
|
||||
|
||||
或從原始碼建置(見下)。
|
||||
|
||||
```bash
|
||||
git clone https://github.com/ETWen/STPViewer.git
|
||||
cd STPViewer
|
||||
dotnet build STPViewer.sln
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🚀 快速開始
|
||||
|
||||
```bash
|
||||
# 建置並執行
|
||||
dotnet build STPViewer.sln
|
||||
dotnet run --project src/STPViewer
|
||||
|
||||
# 發佈免安裝資料夾
|
||||
dotnet publish src/STPViewer -c Release -o publish/STPViewer
|
||||
```
|
||||
|
||||
接著匯入 `.stp` 檔(工具列「匯入」、拖放、或命令列帶檔),選一個量測模式,點擊模型即可。
|
||||
|
||||
---
|
||||
|
||||
## 📚 使用指南
|
||||
|
||||
1. **匯入** 一個或多個 CAD 檔,每個檔案成為裝配樹的一個 root,視角自動 Zoom 到全景。
|
||||
2. **操作樹** — 顯示/隱藏、換色、Zoom-to 某節點,或移除檔案。
|
||||
3. **量測** — 工具列選模式(點 / 距離 / 邊 / 面 / 圓 / 角度 / 面距),點擊模型;結果顯示於右側面板,可單筆刪除或全部清除。
|
||||
4. **裝配** — 用 對齊(兩點/三點)、旋轉、拖曳、操作器擺位,再用干涉檢查驗證配合。
|
||||
5. **剖面** — 開啟 ✂、選軸向、滑動剖切;量測仍以原始幾何精確計算。
|
||||
6. **匯出** — 量測結果存 CSV,或截 2× PNG。
|
||||
|
||||
無 UI 匯入管線與幾何數學驗證:
|
||||
|
||||
```bash
|
||||
dotnet run --project tools/SmokeTest -- "path\to\model.stp" # 匯入 + 裝配樹
|
||||
dotnet run --project tools/SmokeTest -- --clip-test # 剖切裁切數學
|
||||
dotnet run --project tools/SmokeTest -- --interference-test # 干涉 相交/分離/貼合
|
||||
dotnet run --project tools/SmokeTest -- --align-test # 三點對齊剛體變換數學
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🔨 從原始碼建置
|
||||
|
||||
```bash
|
||||
dotnet build STPViewer.sln -c Debug
|
||||
dotnet run --project src/STPViewer
|
||||
dotnet publish src/STPViewer -c Release -o publish/STPViewer
|
||||
```
|
||||
|
||||
NuGet 相依(自動還原):`CADability`、`HelixToolkit.Wpf`、`CommunityToolkit.Mvvm`。
|
||||
|
||||
---
|
||||
|
||||
## 📁 專案結構
|
||||
|
||||
```
|
||||
STPViewer/
|
||||
├── ARCHITECTURE.md # 設計、資料流、開發 Phase
|
||||
├── CLAUDE.md # 專案記憶 & 開發慣例
|
||||
├── STPViewer.sln
|
||||
├── src/STPViewer/
|
||||
│ ├── STPViewer.csproj # net8.0-windows、UseWPF、單一版號來源 <Version>
|
||||
│ ├── MainWindow.xaml / .cs # 版面 + 滑鼠拾取轉發
|
||||
│ ├── Models/ # FaceInfo、MeasureMode、MeasurementResult、UnitSystem
|
||||
│ ├── Services/ # StepImport、Measurement、Interference、Section、RigidAlign
|
||||
│ └── ViewModels/ # MainViewModel、ModelNodeViewModel(裝配樹)
|
||||
└── tools/SmokeTest/ # 無 UI 匯入 + 幾何數學驗證
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## ⚠️ 已知限制
|
||||
|
||||
- 大型 STEP(數千面)匯入需數十秒(CADability 解析成本),匯入期間有進度提示、UI 不凍結。
|
||||
- 輪廓邊線超過 30,000 線段的檔案預設關閉邊線(WPF `LinesVisual3D` 轉動視角時效能限制),可在樹面板手動開啟。
|
||||
- **IGES 不支援**(CADability 無 IGES reader);STL 無 B-rep,僅支援 點/距離/角度/面距 量測;DXF 為線架構檢視。
|
||||
- 剖切面無封口(cap),剖開處顯示內部背面材質(深灰)。
|
||||
- 面積與面距為三角網格近似值;邊長/圓半徑/角度為 B-rep 精確值。
|
||||
- 少數 AP242 檔案 CADability 支援不完整,匯入失敗會提示訊息(不閃退)。
|
||||
- 唯讀檢視器,不寫入/修改原始檔案。
|
||||
|
||||
---
|
||||
|
||||
## 🤝 貢獻
|
||||
|
||||
1. Fork 並建立 feature 分支:`git checkout -b feature/your-feature`
|
||||
2. 遵循 [Conventional Commits](https://www.conventionalcommits.org/):`feat(scope): summary`
|
||||
3. Push 後開 Pull Request
|
||||
|
||||
---
|
||||
|
||||
## 📜 版本紀錄
|
||||
|
||||
### v0.3.2
|
||||
|
||||
- **效能:** 大組件量測模式下轉動視角不再卡頓。量測模式改為渲染合併網格(每檔 1 個 model),並用命中三角形的頂點 index 反查回是哪個面,不再掛數萬個逐面 model;逐面渲染只保留給剖面模式。
|
||||
- 相機互動暫停事件加訂 `HelixViewport3D.CameraChanged`,避免相機實例被換掉時訂閱失效。
|
||||
|
||||
### v0.3.1
|
||||
|
||||
- 操作器 always-on-top 疊圖層(永遠浮在零件上、不被實體遮擋)。
|
||||
|
||||
### v0.3.0
|
||||
|
||||
- 旋轉對齊:軸向旋轉(↻X/↻Y/↻Z)、三點對齊,以及統一的 `TransformRoot` 剛體變換路徑。
|
||||
|
||||
### v0.2.x
|
||||
|
||||
- 拖曳模式、兩點對齊、干涉檢查、剖面、角度/面距量測、裝配樹、STL/DXF 支援、mm ⇄ inch。
|
||||
|
||||
---
|
||||
|
||||
## 🙏 致謝
|
||||
|
||||
- [CADability](https://github.com/SOFAgh/CADability) — 純 C# CAD kernel:STEP 匯入、B-rep 幾何、面三角化
|
||||
- [HelixToolkit.Wpf](https://github.com/helix-toolkit/helix-toolkit) — 3D viewport、相機操作、HitTest
|
||||
- [CommunityToolkit.Mvvm](https://github.com/CommunityToolkit/dotnet) — MVVM
|
||||
|
||||
詳細設計與開發 Phase 見 [ARCHITECTURE.md](ARCHITECTURE.md)。
|
||||
@@ -0,0 +1,56 @@
|
||||
# v0.3.1 — First public release: 3D STEP viewer with measurement & assembly fit-check
|
||||
|
||||
A lightweight Windows desktop viewer for STEP / STL / DXF — open a part, measure it,
|
||||
and check how two parts fit together, without firing up a heavyweight CAD suite.
|
||||
|
||||
## ✨ New features
|
||||
|
||||
**View & assembly tree**
|
||||
* Import multiple CAD files at once (STEP / STL / DXF) via the toolbar, drag-and-drop,
|
||||
or the command line (`STPViewer.exe a.stp b.stp`).
|
||||
* STEP product structure is rebuilt into an **assembly tree** — toggle visibility, recolor
|
||||
(cascades to children), and zoom-to any node; whole-file remove and outline-edge toggle.
|
||||
* Smooth orbit / zoom / pan even on large assemblies (hundreds of thousands of triangles).
|
||||
|
||||
**Measurement** (pick a mode, click the model)
|
||||
* Point (snaps to nearby vertices), two-point distance + ΔX/ΔY/ΔZ, edge length
|
||||
(line / curve / arc with radius), face area + surface type, circle center / radius /
|
||||
diameter / circumference, angle between two faces or edges, and face-to-face minimum gap.
|
||||
* Edge length, radius and angle use **exact B-rep values**; area and gap are mesh-based.
|
||||
* Switch units **mm ⇄ inch** anytime — existing measurements and 3D labels convert live.
|
||||
|
||||
**Assembly fit-check** (mate a male/female pair and verify)
|
||||
* **Two-point align** — click a point on the part to move, then the target point, to slide
|
||||
the whole file into place.
|
||||
* **Three-point align** — pick 3 feature points on each file to solve a full rotate+translate
|
||||
in one shot, for parts that aren't already oriented the same way.
|
||||
* **Axis rotate** — rotate the selected file ±90° about X / Y / Z to square it up.
|
||||
* **Drag mode** (hand cursor) — left-press a part and drag it along the screen plane.
|
||||
* **Gizmo** — XYZ arrows to move along an axis (independent of view angle, ideal for pushing
|
||||
along a mating axis) and rings to rotate any angle. The gizmo always renders on top, so it
|
||||
is never hidden inside a solid part.
|
||||
* **Interference check** — for two visible files, shows red intersection lines where they
|
||||
collide, or the minimum gap when they don't (gap ≈ 0 means a clean fit).
|
||||
|
||||
**Section & export**
|
||||
* Section view along X / Y / Z with a position slider and flip, to inspect mating internals.
|
||||
* Export measurements to CSV (opens cleanly in Excel) and save a 2× PNG screenshot of the view.
|
||||
|
||||
## 📦 Downloads
|
||||
|
||||
Two builds are produced:
|
||||
|
||||
| Build | Needs .NET 8 Desktop Runtime? | Notes |
|
||||
|-------|-------------------------------|-------|
|
||||
| **Standard** (`STPViewer_v0.3.1`) | ✅ Yes | Smaller; for machines that already have the runtime |
|
||||
| **Portable** (`STPViewer_v0.3.1_portable`) | ❌ No | Runtime bundled — unzip and run, no install / admin needed |
|
||||
|
||||
Run `STPViewer v0.3.1.exe`.
|
||||
|
||||
## 🔗 Links
|
||||
* Overview & usage:
|
||||
[README.md](https://github.com/ETWen/STPViewer/blob/main/README.md)
|
||||
* Architecture & design:
|
||||
[ARCHITECTURE.md](https://github.com/ETWen/STPViewer/blob/main/ARCHITECTURE.md)
|
||||
|
||||
**Full changelog:** first public release — [commit history](https://github.com/ETWen/STPViewer/commits/v0.3.1)
|
||||
@@ -1,24 +0,0 @@
|
||||
# secret/ — 本機敏感資料集中地
|
||||
|
||||
本資料夾除 `README.md` 與 `*.example` 外全部 gitignored(規則見根目錄 `.gitignore`)。
|
||||
|
||||
## 內含物件
|
||||
|
||||
| 檔案 | git | 用途 |
|
||||
|---|---|---|
|
||||
| `README.md` | ✅ committed | 本說明 |
|
||||
| `run-STPViewer.ps1.example` | ✅ committed | Windows 啟動腳本範本 |
|
||||
| `run-STPViewer.sh.example` | ✅ committed | Git Bash 啟動腳本範本 |
|
||||
| `run-STPViewer.ps1` / `.sh` | 🚫 ignored | 從範本複製後的本機實值版 |
|
||||
|
||||
> STPViewer 為離線桌面工具,目前**沒有任何 DB 密碼 / ApiKey**;
|
||||
> 腳本僅做 build + run。未來若加入需要 secret 的功能(雲端授權、回報伺服器等),
|
||||
> 依範本內註解加上 env var 注入。
|
||||
|
||||
## 第一次使用
|
||||
|
||||
```powershell
|
||||
cd secret
|
||||
Copy-Item run-STPViewer.ps1.example run-STPViewer.ps1
|
||||
.\run-STPViewer.ps1
|
||||
```
|
||||
@@ -1,31 +0,0 @@
|
||||
# ══════════════════════════════════════════════════════════════════
|
||||
# run-STPViewer.ps1 範本
|
||||
#
|
||||
# 第一次 clone 下來:
|
||||
# cd secret
|
||||
# Copy-Item run-STPViewer.ps1.example run-STPViewer.ps1
|
||||
# .\run-STPViewer.ps1
|
||||
#
|
||||
# 若 PowerShell 擋執行 script,執行一次:
|
||||
# Set-ExecutionPolicy -Scope CurrentUser RemoteSigned
|
||||
#
|
||||
# secret/ 下除 README.md 和 .example 外皆已 gitignore。
|
||||
# ══════════════════════════════════════════════════════════════════
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
# ─── secret(本專案目前無 DB / ApiKey;未來需要時在此加 env var) ──
|
||||
# $env:SomeService__ApiKey = '__CHANGE_ME__'
|
||||
|
||||
# ══════════════════════════════════════════════════════════════════
|
||||
|
||||
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
$RepoRoot = Resolve-Path (Join-Path $ScriptDir '..')
|
||||
|
||||
Push-Location $RepoRoot
|
||||
try {
|
||||
dotnet run --project src/STPViewer
|
||||
}
|
||||
finally {
|
||||
Pop-Location
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# ══════════════════════════════════════════════════════════════════
|
||||
# run-STPViewer.sh 範本(Git Bash on Windows)
|
||||
#
|
||||
# 第一次 clone 下來:
|
||||
# cd secret
|
||||
# cp run-STPViewer.sh.example run-STPViewer.sh
|
||||
# chmod +x run-STPViewer.sh
|
||||
# ./run-STPViewer.sh
|
||||
#
|
||||
# secret/ 下除 README.md 和 .example 外皆已 gitignore。
|
||||
# ══════════════════════════════════════════════════════════════════
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# ─── secret(本專案目前無 DB / ApiKey;未來需要時在此 export) ────
|
||||
# export SomeService__ApiKey="__CHANGE_ME__"
|
||||
|
||||
# ══════════════════════════════════════════════════════════════════
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
REPO_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
|
||||
|
||||
cd "${REPO_ROOT}"
|
||||
exec dotnet run --project src/STPViewer
|
||||
@@ -4,7 +4,7 @@
|
||||
xmlns:h="http://helix-toolkit.org/wpf"
|
||||
xmlns:conv="clr-namespace:STPViewer.Converters"
|
||||
xmlns:vm="clr-namespace:STPViewer.ViewModels"
|
||||
Title="STPViewer V0.3.1 — STP/STEP 3D 檢視器"
|
||||
Title="STPViewer — STP/STEP 3D 檢視器"
|
||||
Height="820" Width="1320"
|
||||
WindowStartupLocation="CenterScreen"
|
||||
AllowDrop="True" Drop="Window_Drop" DragOver="Window_DragOver">
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using STPViewer.Services;
|
||||
@@ -13,6 +14,9 @@ public partial class MainWindow : Window
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
// 版號單一來源 = csproj <Version>;標題執行時讀,避免寫死
|
||||
var v = Assembly.GetExecutingAssembly().GetName().Version!;
|
||||
Title = $"STPViewer V{v.Major}.{v.Minor}.{v.Build} — STP/STEP 3D 檢視器";
|
||||
DataContext = _vm;
|
||||
_vm.Attach(viewport);
|
||||
_vm.AttachOverlay(gizmoOverlay);
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<UseWPF>true</UseWPF>
|
||||
<Version>0.3.2</Version> <!-- 單一版號來源:標題與 publish-winapp 打包資料夾都讀這個 -->
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -30,6 +30,11 @@ public partial class MainViewModel : ObservableObject
|
||||
/// <summary>合併網格 → leaf 反查表(拖曳模式在瀏覽渲染下 hit-test 用)</summary>
|
||||
private readonly Dictionary<Model3D, ModelNodeViewModel> _mergedMap = new();
|
||||
|
||||
/// <summary>合併網格 → (每面頂點起始邊界, 對應 FaceInfo)。命中合併網格時用三角形頂點 index 二分搜尋反查回是哪個面,
|
||||
/// 讓量測模式也能 render 合併網格(62 個 model)而非逐面(數萬個 model)。starts 長度 = faces+1,最後一格為總頂點數。
|
||||
/// 邊界由匯入時依面序串接而成,與 BuildMergedMesh 串接順序一致;平移不改各面頂點數,故邊界永久有效。</summary>
|
||||
private readonly Dictionary<Model3D, (int[] Starts, FaceInfo[] Faces)> _mergedFaceRanges = new();
|
||||
|
||||
// 拖曳模式:暫時 Transform 跟著滑鼠,放開才一次性烘進 B-rep(TranslateRoot)
|
||||
private ModelNodeViewModel? _dragRoot;
|
||||
private Point3D _dragAnchor; // 命中點(世界座標),拖曳平面的錨點
|
||||
@@ -107,7 +112,13 @@ public partial class MainViewModel : ObservableObject
|
||||
public void Attach(HelixViewport3D viewport)
|
||||
{
|
||||
_viewport = viewport;
|
||||
// 相機一動就暫停邊線(轉動/縮放/平移皆觸發),停下 180ms 再恢復
|
||||
// 相機一動就暫停邊線/逐面(轉動/縮放/平移皆觸發),停下 180ms 再恢復。
|
||||
// 兩個事件都訂閱,互補保底:
|
||||
// 1) viewport.CameraChanged(控制項層級 routed event)— 相機實例若被 Helix 內部換掉也接得住;
|
||||
// 2) Camera.Changed(Freezable,相機 Position/方向一被改就觸發)— 確保每次移動都收到。
|
||||
// 舊寫法只訂 Camera.Changed 且包在 null 檢查裡,萬一相機實例被換就永久失聯 → 暫停機制全失效。
|
||||
// 重複觸發 OnCameraMoved 無害(idempotent,內部有 _edgesSuspended guard)。
|
||||
viewport.CameraChanged += (_, _) => OnCameraMoved();
|
||||
if (viewport.Camera is not null)
|
||||
viewport.Camera.Changed += (_, _) => OnCameraMoved();
|
||||
}
|
||||
@@ -274,30 +285,42 @@ public partial class MainViewModel : ObservableObject
|
||||
backMat.Freeze();
|
||||
vm.SharedMaterial = diffuse;
|
||||
|
||||
// 一個 B-rep Face = 一個 GeometryModel3D,登錄反查表(量測拾取用)
|
||||
// 一個 B-rep Face = 一個 GeometryModel3D,登錄反查表(剖面模式逐面拾取用)。
|
||||
// 同時依面序記錄每面頂點起始邊界 + 對應 FaceInfo,供「命中合併網格反查面」(量測模式拾取用)。
|
||||
var group = new Model3DGroup();
|
||||
foreach (ImportedFace f in n.Faces)
|
||||
var faceInfos = new FaceInfo[n.Faces.Count];
|
||||
var vertStarts = new int[n.Faces.Count + 1];
|
||||
int vacc = 0;
|
||||
for (int i = 0; i < n.Faces.Count; i++)
|
||||
{
|
||||
ImportedFace f = n.Faces[i];
|
||||
var gm = new GeometryModel3D(f.Mesh, matGroup) { BackMaterial = backMat };
|
||||
group.Children.Add(gm);
|
||||
_faceMap[gm] = new FaceInfo { BrepFace = f.BrepFace, Mesh = f.Mesh, Owner = vm };
|
||||
var info = new FaceInfo { BrepFace = f.BrepFace, Mesh = f.Mesh, Owner = vm };
|
||||
_faceMap[gm] = info;
|
||||
faceInfos[i] = info;
|
||||
vertStarts[i] = vacc;
|
||||
vacc += f.Mesh.Positions.Count;
|
||||
}
|
||||
vertStarts[n.Faces.Count] = vacc;
|
||||
vm.FacesContent = group;
|
||||
|
||||
// 合併網格:整零件所有面併成 1 個 GeometryModel3D(瀏覽時只 1 個 draw call)
|
||||
// 合併網格:整零件所有面併成 1 個 GeometryModel3D(draw call 從每面 1 個降為每檔 1 個)。
|
||||
// BuildMergedMesh 依 n.Faces 同序串接(baseIdx += positions.Count),與上面 vertStarts 對齊 → 命中頂點 index 可反查回面。
|
||||
var mergedModel = new GeometryModel3D(BuildMergedMesh(n.Faces), matGroup);
|
||||
// 封閉實體背面不可見 → 不設 BackMaterial(WPF 兩面渲染成本砍半);開放殼/STL 仍需背面
|
||||
// 封閉實體背面不可見 → 不設 BackMaterial(WPF 兩面渲染成本砍半);開放殼/STL 仍需背面。
|
||||
// 拾取不受材質影響(WPF 3D hit-test 純幾何、不剔背面),故孔內壁仍可命中。
|
||||
if (n.SolidCount == 0 || !n.HasBrep)
|
||||
mergedModel.BackMaterial = backMat;
|
||||
vm.MergedContent = new Model3DGroup();
|
||||
vm.MergedContent.Children.Add(mergedModel);
|
||||
_mergedMap[mergedModel] = vm;
|
||||
_mergedFaceRanges[mergedModel] = (vertStarts, faceInfos);
|
||||
|
||||
// 預設瀏覽模式 → 顯示合併網格(量測模式時由 ApplyRenderMode 換回逐面)
|
||||
// 非剖面一律顯示合併網格(瀏覽/量測都是,量測靠 _mergedFaceRanges 反查面);只有剖面才逐面(裁切後幾何)
|
||||
vm.BodyVisual = new ModelVisual3D
|
||||
{
|
||||
Content = (CurrentMode is MeasureMode.None or MeasureMode.Drag && !SectionEnabled)
|
||||
? vm.MergedContent : group,
|
||||
Content = SectionEnabled ? group : vm.MergedContent,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -409,15 +432,17 @@ public partial class MainViewModel : ObservableObject
|
||||
|
||||
/// <summary>
|
||||
/// 依目前狀態切換每個 leaf 的渲染內容:
|
||||
/// 瀏覽(None)且未剖面 → 合併網格(快);量測模式或剖面 → 逐面(拾取/裁切需要)。
|
||||
/// 非剖面(瀏覽 + 量測皆是)→ 合併網格(每檔 1 個 model,快);量測拾取靠命中合併網格反查面(_mergedFaceRanges)。
|
||||
/// 剖面 → 逐面(要顯示各面裁切後的幾何)。
|
||||
/// </summary>
|
||||
private void ApplyRenderMode()
|
||||
{
|
||||
bool browse = CurrentMode is MeasureMode.None or MeasureMode.Drag && !SectionEnabled;
|
||||
// 量測不再需要逐面渲染(拾取打合併網格反查面)→ 只有剖面才逐面。永不在量測模式掛數萬個 GeometryModel3D。
|
||||
bool merged = !SectionEnabled;
|
||||
foreach (ModelNodeViewModel leaf in Roots.SelectMany(r => r.Leaves()))
|
||||
{
|
||||
if (leaf.BodyVisual is null) continue;
|
||||
Model3DGroup? target = browse ? leaf.MergedContent : leaf.FacesContent;
|
||||
Model3DGroup? target = merged ? leaf.MergedContent : leaf.FacesContent;
|
||||
if (target is not null && !ReferenceEquals(leaf.BodyVisual.Content, target))
|
||||
leaf.BodyVisual.Content = target;
|
||||
}
|
||||
@@ -454,7 +479,10 @@ public partial class MainViewModel : ObservableObject
|
||||
_faceMap.Remove(m);
|
||||
if (leaf.MergedContent is not null)
|
||||
foreach (Model3D m in leaf.MergedContent.Children)
|
||||
{
|
||||
_mergedMap.Remove(m);
|
||||
_mergedFaceRanges.Remove(m);
|
||||
}
|
||||
}
|
||||
if (root.EdgeVisual is not null)
|
||||
_viewport.Children.Remove(root.EdgeVisual);
|
||||
@@ -467,7 +495,7 @@ public partial class MainViewModel : ObservableObject
|
||||
partial void OnCurrentModeChanged(MeasureMode value)
|
||||
{
|
||||
CancelPending();
|
||||
ApplyRenderMode(); // None → 合併網格(快);量測模式 → 逐面(可拾取)
|
||||
ApplyRenderMode(); // 非剖面一律合併網格(量測拾取靠反查面);不再因切量測模式而掛逐面
|
||||
StatusText = value switch
|
||||
{
|
||||
MeasureMode.None => "瀏覽模式(右鍵旋轉、滾輪縮放、中鍵或 Shift+左鍵拖曳平移)",
|
||||
@@ -503,13 +531,23 @@ public partial class MainViewModel : ObservableObject
|
||||
Vector3D hitNormal = default;
|
||||
foreach (var h in hits)
|
||||
{
|
||||
if (h.Model is not null && _faceMap.TryGetValue(h.Model, out FaceInfo? f))
|
||||
if (h.Model is null) continue;
|
||||
// 剖面模式:渲染逐面 → 直接查 _faceMap
|
||||
if (_faceMap.TryGetValue(h.Model, out FaceInfo? f))
|
||||
{
|
||||
fi = f;
|
||||
hitPoint = h.Position;
|
||||
hitNormal = h.Normal;
|
||||
fi = f; hitPoint = h.Position; hitNormal = h.Normal;
|
||||
break;
|
||||
}
|
||||
// 量測/瀏覽模式:渲染合併網格 → 用命中三角形頂點 index 反查回是哪個面
|
||||
if (h.RayHit is not null && _mergedFaceRanges.TryGetValue(h.Model, out var range))
|
||||
{
|
||||
FaceInfo? mf = ResolveMergedFace(range, h.RayHit.VertexIndex1);
|
||||
if (mf is not null)
|
||||
{
|
||||
fi = mf; hitPoint = h.Position; hitNormal = h.Normal;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (fi is null)
|
||||
{
|
||||
@@ -527,6 +565,23 @@ public partial class MainViewModel : ObservableObject
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>命中合併網格的某頂點 index → 反查回是哪個面(依面序的頂點起始邊界二分搜尋)。</summary>
|
||||
private static FaceInfo? ResolveMergedFace((int[] Starts, FaceInfo[] Faces) range, int vertexIndex)
|
||||
{
|
||||
int[] starts = range.Starts;
|
||||
FaceInfo[] faces = range.Faces;
|
||||
if (vertexIndex < 0 || faces.Length == 0 || vertexIndex >= starts[faces.Length]) return null;
|
||||
// 找最大的 k 使 starts[k] <= vertexIndex(face k 佔頂點 [starts[k], starts[k+1]))
|
||||
int lo = 0, hi = faces.Length - 1, ans = 0;
|
||||
while (lo <= hi)
|
||||
{
|
||||
int mid = (lo + hi) / 2;
|
||||
if (starts[mid] <= vertexIndex) { ans = mid; lo = mid + 1; }
|
||||
else hi = mid - 1;
|
||||
}
|
||||
return faces[ans];
|
||||
}
|
||||
|
||||
private void HandleMeasureClick(FaceInfo fi, Point3D hit, Vector3D hitNormal)
|
||||
{
|
||||
double diag = SceneDiagonal();
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
// One-shot diagnostic: print per-leaf world-space bounding boxes so we can
|
||||
// figure out each connector's mating-face normal (axis the guide posts / holes point).
|
||||
using STPViewer.Services;
|
||||
|
||||
namespace SmokeTest;
|
||||
|
||||
internal static class BBoxDump
|
||||
{
|
||||
public static int Run(string path)
|
||||
{
|
||||
var svc = new StepImportService();
|
||||
ImportedFileData data = svc.Import(path);
|
||||
System.Console.WriteLine($"=== {System.IO.Path.GetFileName(path)} ===");
|
||||
Print(data.Root, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static void Print(ImportedNode n, int depth)
|
||||
{
|
||||
var b = n.Bounds;
|
||||
string box = b.IsEmpty
|
||||
? "(empty)"
|
||||
: $"X[{b.X,8:F1}..{b.X + b.SizeX,8:F1}] Y[{b.Y,8:F1}..{b.Y + b.SizeY,8:F1}] Z[{b.Z,8:F1}..{b.Z + b.SizeZ,8:F1}] " +
|
||||
$"size {b.SizeX,7:F1} x {b.SizeY,7:F1} x {b.SizeZ,7:F1}";
|
||||
System.Console.WriteLine($"{new string(' ', depth * 2)}{n.Name,-28} {box}");
|
||||
foreach (ImportedNode c in n.Children) Print(c, depth + 1);
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,9 @@ if (args[0] == "--interference-test")
|
||||
if (args[0] == "--align-test")
|
||||
return SmokeTest.AlignTest.Run() == 0 ? 0 : 2;
|
||||
|
||||
if (args[0] == "--bbox")
|
||||
return SmokeTest.BBoxDump.Run(args[1]);
|
||||
|
||||
var service = new StepImportService { Progress = s => Console.WriteLine($" [階段] {s}") };
|
||||
int failed = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user