using Autodesk.AutoCAD.Geometry; namespace FurnitureExporter; /// /// Brep 面的 Surface 有时会被包装成 ExternalBoundedSurface/OffsetSurface 等“修剪/偏移”表面。 /// 这会导致直接用 `surface is Cylinder/Plane` 判断失效,从而漏检孔位/倒角等特征。 /// /// 这里提供一个统一的“剥壳”工具,把 Surface 还原为最底层的几何表面类型。 /// internal static class BrepSurfaceUtils { // 防御:最多剥 8 层,避免异常几何导致递归/循环 private const int MaxUnwrapDepth = 8; public static Surface Unwrap(Surface surface) { var current = surface; for (int i = 0; i < MaxUnwrapDepth; i++) { if (current == null) { break; } // 最常见:Brep Face 的表面是“修剪面”,真正的几何在 BaseSurface if (current is ExternalBoundedSurface ebs && ebs.BaseSurface != null) { current = ebs.BaseSurface; continue; } // 偏移面:原始几何在 OriginalSurface if (current is OffsetSurface os && os.OriginalSurface != null) { current = os.OriginalSurface; continue; } // 外部面:如果是 NativeSurface,则真实几何在 nativeSurface if (current is ExternalSurface es && es.IsNativeSurface && es.nativeSurface != null) { current = es.nativeSurface; continue; } break; } return current ?? surface; } }