feat(dwg): 补齐 3D 多段线/多边形网格与 3DSOLID 线框出图
Build & Test / build-and-test (push) Canceled after 0s
VDE Build & Test / build-and-test (push) Canceled after 0s
Build & Test / python-bindings (push) Canceled after 0s

POLYLINE_3D/POLYLINE_MESH/VERTEX_3D/VERTEX_MESH 原生解码(按 LibreDWG/ACadSharp 双实现校核);3DSOLID 线框与网格顶点映射为 3D 折线。语料直出 580/582 件、372485 图元,无可绘制 36→2(余 2 件为无几何模板)。
This commit is contained in:
hm
2026-10-19 09:04:52 +08:00
parent 8119ab0770
commit d06823ec08
8 changed files with 301 additions and 21 deletions
@@ -66,7 +66,7 @@
| # | 缺口 | 现状 | 对标 | 归属 |
|---|------|------|------|------|
| G-1 | **DWG 原生读写** | 读:M3.1–M3.5 已落地(容器 582/582、位流 0 失败、546 件直出 311671 图元);缺 R12(pre-R13)、3DSOLID/BODY/REGION 的 ACIS 载荷。写:仅 AC1015 往返 6/6,`export_dwg` 通道仍走 DXF 转换器 | 全部四大内核 + OCCT 皆原生支持 | WS-3 |
| G-1 | **DWG 原生读写** | 读:M3.1–M3.5 已落地(容器 582/582、位流 0 失败、580 件直出 372485 图元;3DSOLID 线框与 3D 多段线/网格已出图;剩 2 件无几何模板);缺 R12(pre-R13)、ACIS 载荷的表面重建。写:仅 AC1015 往返 6/6,`export_dwg` 通道仍走 DXF 转换器 | 全部四大内核 + OCCT 皆原生支持 | WS-3 |
| G-2 | **圆角网络整圈求解** | `corner_blend`(多角汇聚)与 `blend_network`(每边独立半径)已在 `advanced_blend.h`;缺**整圈变半径网络自动求解 + 三圆角相切过渡 + 冲突检测** | Parasolid / CGM 的长期护城河 | WS-2 |
| G-3 | **配置管理 / 族表** | 特征树已有(E4 FeatureTree + `vde::param` + UndoStack 回滚);**变体配置、族表、参数驱动多配置**没有 | GRANITE(PTC)独家强项 | WS-4 |
| G-4 | **CUDA BVH 构建** | 其余 GPU kernel(SDF/AABB 批相交/视锥剔除/tri-tri)已落地,仅 BVH 构建待实现 | Parasolid GPU + 集群 | WS-5 |
+18 -8
View File
@@ -78,7 +78,7 @@ Circular / ConicRho / CurvatureContinuous)、`chordal_blend`、`tritangent_ble
| **M3.2 R2000 对象解码** | AC1015 对象位流解码:HEADER 变量、CLASSES、表(LAYER/LTYPE/STYLE/BLOCK)、实体(LINE/CIRCLE/ARC/LWPOLYLINE/POLYLINE/TEXT/MTEXT/INSERT) | `dwg_object` 解码器 | AC1015 语料 1/1 全实体一致;与同内容 DXF 交叉校验 | ✅ 2026-10-18 |
| **M3.3 R2004+ 对象解码** | 压缩数据段 + 位级对象编码(AC1018/AC1021/AC1027/AC1032) | 同上 | 145 件中 ≥90% 全实体解码;每件与 libredwg `dwgread` 输出交叉校验 | ✅ 2026-10-18(145/145 件、256630 对象残差 0;2026-10-19 补齐 3DSOLID/BODY/REGION 的 ACIS 段,见下) |
| **M3.4 原生写入** | R2000 写入(兼容性最好);R2018 写入(对齐主流) | `dwg_writer` | 写出文件可被 AutoCAD / ODA / libredwg 打开;往返(写→读)实体 100% 一致 | 🟡 2026-10-18(AC1015 写入 + 自有解码器往返 6/6;R2018 写入待办,外部 CAD 交叉校验待验证) |
| **M3.5 替换通道** | 原生路径优先,外部转换器降级为可选 | 版本/能力协商 | 无外部工具时 582 件全部可读 | 🟡 2026-10-18(原生通道已接入:582/582 走原生、0 解码失败;546 件直出图元,36 件仅含 3DSOLID 等非图元对象,见下) |
| **M3.5 替换通道** | 原生路径优先,外部转换器降级为可选 | 版本/能力协商 | 无外部工具时 582 件全部可读 | 🟡 2026-10-19(原生通道已接入:582/582 走原生、0 解码失败;580 件直出图元,2 件为无几何模板〔仅表/视口对象〕,见下) |
| **M3.6 R12 原生容器** | pre-R13 布局(AC1009):固定偏移头 + 三实体段,无节定位器体系 | `dwg_r12` 解析器 | R12 语料 0 件(本轮实测)→ 用外部生成的 R12 夹具验收;结构解析 100%、`file_size` 一致 | 待办(当前如实报错,不假实现) |
### 技术路线与许可策略
@@ -137,17 +137,27 @@ AC1032×64 共 **145 件**、**256630 个对象**,同样要求数据流残差
会缺 102 bit。载荷还原(v1 逐块 `0x9F-byte` 解混淆 SAT、v2 自定界 SAB/SAT)落在
`DwgAcis`,不做表面重建;R2013+ 的载荷在独立 AcDs 流,本层不跨流读取,如实留空。
修复后 145 件 R2004+ 与 437 件 AC1015 全部残差 0。
- **显示级几何补全(2026-10-19)**:`3DSOLID/BODY/REGION` 的线框/等值线段
(`WIRESTRUCT`:`BL num_points` + N×`3BD` + 可选变换矩阵)此前整段丢弃,
现收集进 `DwgAcis::wires` 并在导入层映射为 3D `POLYLINE`——仅有 3DSOLID 的
文件由此恢复可出图。`POLYLINE_3D`(16)/`POLYLINE_MESH`(30)/`VERTEX_3D`(11)/
`VERTEX_MESH`(12) 原无解码分支(残差本已为 0,属"假未实现"),按 LibreDWG
`POLYLINE_3D`/`VERTEX_*` 与 ACadSharp `readPolyline3D`/`readVertex3D` 双实现
校核补齐:3D 多段线为 `RC curve_type + RC flags`(无宽度/标高/拉伸方向),
网格为 6×`BS`(flags/curve/M/N/density);R13–R2000 用 first/last 顶点句柄、
R2004+ 用对象内 `BL num_owned` + 句柄向量。导入层把网格按 M×N 生成行列 3D
折线(显示级线框,不伪造曲面)。效果:直出图元 **578→580 件、
311671→372485 个**(模型空间 233556 + 块定义内 138929);`无可绘制` **36→2 件**。
**M3.5 实测口径(2026-10-19)**:`tests/foundation/test_dwg.cpp` 的
`RealCorpusImportsNativelyWithoutConverter` 清空 `VDE_DWG_READ_CMD/WRITE_CMD` 后逐件调用
`import_dwg()`,断言 **`converter_used/plugin_used` 恒为假**(原生路径排在转换器之前)、
**0 件原生位流解码失败**。结果:**582/582 走原生**;**546 件直出 DXF 图元、合计
311671 个**(模型空间 178601 + 块定义内 133070),其中 **INSERT 引用 6591 个**
(AC1015 405/437、AC1018 26/26、AC1021 13/14、AC1027 38/41、AC1032 64/64);其余
36 件解码成功但全文没有可绘制图元——只有 `3DSOLID`/`BODY`/`REGION` 等 ACIS 实体或
纯参照块。DXF 图元层没有三维实体的对应物,消息显式报告"无可绘制图元"并按类型列出
跳过项(如 `3DSOLID×1`),不伪造几何。该 36 件是**内容限制**而非解码失败;要转成
实体需要 ACIS/SAT 解析内核(独立课题,不在 M3.5 范围内)。
**0 件原生位流解码失败**。结果:**582/582 走原生**;**580 件直出 DXF 图元、合计
372485 个**(模型空间 233556 + 块定义内 138929),其中 **INSERT 引用 6591 个**
(AC1015 435/437、AC1018 26/26、AC1021 14/14、AC1027 41/41、AC1032 64/64);其余
2 件为同名 `机械制图模板.dwg`(两个目录各一份),全文只有 APPID/DICTIONARY/
DIMSTYLE/VPORT/VIEWPORT 等表与视口对象,**文件本身不含任何几何**——属内容限制
而非解码失败,消息如实报告"解码成功但无可绘制图元",不伪造几何。
「无图元」判定口径本轮修正:模型空间为空**不等于**文件无几何——块库、尺寸匿名块
(`*D`)的可绘制图元只存在于块定义内。判定改为「全文(模型空间 + 全部块定义)可绘制
+18
View File
@@ -213,6 +213,24 @@ const long long kSteinerBudget = 8000;
> AC1015 **437/437 件、200558 个对象**,R2004+ **145/145 件、256630 个对象**,
> 582 件 0 失败、数据流残差全 0;此前 4 件 −52/−28 bit 全部归零。
> 2026-10-19 复核(续,WS-3 M3.5 显示级几何):
> **① ACIS 线框落地**——`3DSOLID/BODY/REGION` 的 `WIRESTRUCT`(`BL num_points` +
> N×`3BD` + 可选变换矩阵)此前整段跳过,现收集进 `DwgAcis::wires`,导入层按
> 3D `DxfPolyline` 输出;仅有 3DSOLID 的文件恢复可出图(无可绘制 36→4)。
> **② 3D 多段线/网格补齐**——`POLYLINE_3D`(16)/`POLYLINE_MESH`(30)/`VERTEX_3D`(11)/
> `VERTEX_MESH`(12) 原无 `decode_entity_data` 分支(数据流残差本已为 0,属"假未实现");
> 布局按 LibreDWG `POLYLINE_3D`/`VERTEX_3D`/`VERTEX_MESH` 与 ACadSharp
> `readPolyline3D`/`readVertex3D` 双实现校核:3D 多段线 `RC curve_type + RC flags`
> (无宽度/标高/拉伸方向),网格 `6×BS`(flags/curve/M/N/density);R13–R2000 读
> first/last 顶点句柄、R2004+ 读对象内 `BL num_owned` + 句柄向量。导入层把网格按
> M×N 生成行列 3D 折线(显示级线框,不伪造曲面)。
> 验收:`test_dwg_object` **8/8 PASSED**(新增类型全部通过整语料残差 0 断言);
> `test_dwg` **15/15 PASSED**——**582/582 走原生、0 解码失败**,**580 件直出
> 372485 个图元**(模型空间 233556 + 块定义内 138929;AC1015 435/437、
> AC1018 26/26、AC1021 14/14、AC1027 41/41、AC1032 64/64);剩余 **2 件**为同名
> `机械制图模板.dwg`(两个目录各一份),仅含 APPID/DICTIONARY/DIMSTYLE/VPORT/
> VIEWPORT,**文件本身无任何几何**,如实报告"无可绘制图元"。
> 2026-10-15 复核移出本清单:
> - `MeshRobust.Hole_*` 2 例(`Hole_SingleTriangleIsBoundary` / `Hole_BoundaryEdgeChain`)
> 原记为"既有失败",**已复核全部通过**:`test_mesh_robustness` 现为 **145/145 PASSED**
+2 -2
View File
@@ -58,8 +58,8 @@
> | 原生对象解码(R2004+) | ✅ | M3.3:AC1018/AC1021/AC1027/AC1032 共 145 件、256630 个对象残差 0(含 R2007+ 字符串流口径与 AC1021 节表 7×u64 页记录修正) |
> | 原生写入(AC1015 / R2000) | ✅ | M3.4:`dwg_writer`;图层 + LINE/CIRCLE/ARC/POINT/TEXT;写→读回逐字段一致(6/6),残余 0 |
> | 原生写入(R2018 / AC1032) | ⏳ | M3.4 后续:对齐主流版本;当前仅 AC1015,外部 CAD 交叉校验待验证 |
> | 原生导入(无外部工具) | ✅ | M3.5:`import_dwg()` 原生路径优先,转换器降级兜底;582/582 真实 DWG 走原生、0 解码失败,546 件直出 311671 个图元(模型空间 178601 + 块定义内 133070,INSERT 引用 6591 个;含 SPLINE 2773、HATCH 2930、ATTRIB/ATTDEF、DIMENSION×7 子类;其余 36 件全文仅含 3DSOLID 等非图元对象,按类型如实报告) |
> | ACIS 模型几何(3DSOLID/BODY/REGION) | 🟡 | 位流段已完整解码(R13–R2010 分块 SAT/自定界 SAB + 线框 + 材质;R2013+ 材质表 + 修订块),582 件语料残差 0;仅还原载荷,表面重建待 ACIS 解析层;R2013+ 载荷在独立 AcDs 流,当前如实留空 |
> | 原生导入(无外部工具) | ✅ | M3.5:`import_dwg()` 原生路径优先,转换器降级兜底;582/582 真实 DWG 走原生、0 解码失败,580 件直出 372485 个图元(模型空间 233556 + 块定义内 138929,INSERT 引用 6591 个;含 SPLINE 2773、HATCH 2930、ATTRIB/ATTDEF、DIMENSION×7 子类、3DSOLID 线框、3D 多段线/多边形网格;其余 2 件为无几何模板〔仅表/视口对象〕,按类型如实报告) |
> | ACIS 模型几何(3DSOLID/BODY/REGION) | 🟡 | 位流段已完整解码(R13–R2010 分块 SAT/自定界 SAB + 线框 + 材质;R2013+ 材质表 + 修订块),582 件语料残差 0;线框/等值线段已映射为显示级 3D 折线,实体表面重建待 ACIS 解析层;R2013+ 载荷在独立 AcDs 流,当前如实留空 |
---
+36 -1
View File
@@ -348,6 +348,38 @@ struct DwgVertex2D {
double tangent = 0.0;
};
/// POLYLINE(3D,类型 16):无宽度/标高字段,顶点为绝对 WCS 坐标
struct DwgPolyline3D {
std::uint16_t flags = 0;
std::uint16_t curve_type = 0;
std::uint64_t first_vertex = 0; ///< R13–R2000:首个 VERTEX 句柄
std::uint64_t last_vertex = 0; ///< R13–R2000:末个 VERTEX 句柄
std::uint64_t seqend = 0;
std::uint32_t num_owned = 0; ///< R2004+:顶点句柄数
std::vector<std::uint64_t> vertex_handles; ///< R2004+ 顶点句柄向量
};
/// VERTEX(3D / 网格,类型 11/12):`location` 为绝对 WCS 坐标
struct DwgVertex3D {
std::uint8_t flags = 0;
DwgPoint3 location;
};
/// POLYLINE(多边形网格,类型 30)
struct DwgPolylineMesh {
std::uint16_t flags = 0;
std::uint16_t curve_type = 0;
std::uint32_t num_m_verts = 0;
std::uint32_t num_n_verts = 0;
std::uint16_t m_density = 0;
std::uint16_t n_density = 0;
std::uint64_t first_vertex = 0; ///< R13–R2000:首个 VERTEX 句柄
std::uint64_t last_vertex = 0; ///< R13–R2000:末个 VERTEX 句柄
std::uint64_t seqend = 0;
std::uint32_t num_owned = 0; ///< R2004+:顶点句柄数
std::vector<std::uint64_t> vertex_handles; ///< R2004+ 顶点句柄向量
};
/// TEXT(类型 1)
struct DwgText {
double elevation = 0.0;
@@ -471,8 +503,10 @@ struct DwgAttrib {
struct DwgAcis {
std::uint16_t acis_version = 0; ///< 70:1 = SAT 文本块,2 = 自定界载荷
bool is_binary = false; ///< version 2 且载荷以 "ACIS BinaryFile" 开头
bool has_wireframe = false; ///< 线框/轮廓数据存在(已跳过,仅记录)
bool has_wireframe = false; ///< 线框/轮廓数据存在
std::string data; ///< SAT 文本或 SAB 原始字节(已截到结束标记)
/// 线框/等值线折线(文件自带的显示级几何,非 B-Rep 拓扑)
std::vector<std::vector<DwgPoint3>> wires;
};
/// BLOCK(类型 4,图元)
@@ -572,6 +606,7 @@ struct DwgTableControl {
using DwgObjectData = std::variant<
std::monostate, DwgLine, DwgCircle, DwgArc, DwgPoint, DwgSolid, DwgEllipse,
DwgSpline, DwgHatch, DwgLwPolyline, DwgPolyline2D, DwgVertex2D, DwgText,
DwgPolyline3D, DwgVertex3D, DwgPolylineMesh,
DwgMText, DwgInsert, DwgAttrib, DwgDimension, DwgAcis, DwgBlock,
DwgEndBlk, DwgSeqEnd, DwgLayer, DwgLType, DwgStyle, DwgBlockHeader,
DwgTableControl>;
+105 -8
View File
@@ -54,6 +54,8 @@ constexpr std::size_t kMaxObjects = 4000000; // 对象数上限
constexpr std::size_t kMaxWarnings = 256; // 警告条数上限
constexpr std::size_t kMaxEedSize = 1u << 20; // EED 段上限 1 MiB
constexpr std::int64_t kMaxCollectionSize = 1000000; // 单实体点/节点数组上限
constexpr std::size_t kMaxAcisWirePoints = 500000; // 3DSOLID 线框点总预算
constexpr std::size_t kMaxAcisWires = 100000; // 3DSOLID 线框折线数上限
void add_warning(DwgObjectDocument& doc, std::string message) {
if (doc.warnings.size() < kMaxWarnings) {
@@ -1400,7 +1402,12 @@ bool read_acis_payload(BitReader& reader, DwgAcis& acis) {
/// 注意:规范中的 `3BD` 是 **bit-double**(2 bit 码 + 可选 8 字节 RD),
/// 不是裸 8 字节 double——实测每条坐标占 66 bit(码 0 + RD),若按 `rd()`
/// 读取会整体错位。
bool skip_acis_wire(BitReader& reader) {
///
/// `wires` 非空时同时收集折线点(显示级等值线/轮廓,供导入层出图);
/// 受 `kMaxAcisWirePoints` / `kMaxAcisWires` 预算约束,超出后仅跳过不收集。
bool skip_acis_wire(BitReader& reader,
std::vector<std::vector<DwgPoint3>>* wires,
std::size_t& point_budget) {
(void)reader.rc(); // type
(void)reader.bl(); // selection marker
(void)reader.bs(); // color
@@ -1409,10 +1416,27 @@ bool skip_acis_wire(BitReader& reader) {
if (!reader.ok() || num_points < 0 || num_points > kMaxCollectionSize) {
return false;
}
for (std::int64_t i = 0; i < num_points; ++i) {
(void)reader.bd();
(void)reader.bd();
(void)reader.bd();
const bool keep = wires != nullptr && num_points >= 2 &&
wires->size() < kMaxAcisWires &&
static_cast<std::size_t>(num_points) <= point_budget;
if (keep) {
std::vector<DwgPoint3> wire;
wire.reserve(static_cast<std::size_t>(num_points));
for (std::int64_t i = 0; i < num_points; ++i) {
DwgPoint3 p;
p.x = reader.bd();
p.y = reader.bd();
p.z = reader.bd();
wire.push_back(p);
}
point_budget -= static_cast<std::size_t>(num_points);
wires->push_back(std::move(wire));
} else {
for (std::int64_t i = 0; i < num_points; ++i) {
(void)reader.bd();
(void)reader.bd();
(void)reader.bd();
}
}
if (reader.b()) { // transform present
for (int i = 0; i < 3 * 5; ++i) (void)reader.bd(); // axis x/y/z + translation + scale
@@ -1449,6 +1473,7 @@ bool read_modeler_geometry(BitReader& reader, BitReader& handles,
// 不再有前导 ACIS 空位(ACadSharp `readModelerGeometry` 的 `!R2013Plus`
// 分支);R13–R2010 保持 LibreDWG 布局。
const bool r2013_plus = traits.version >= DwgVersion::R2013;
std::size_t wire_point_budget = kMaxAcisWirePoints;
bool acis_empty = true;
if (!r2013_plus) acis_empty = reader.b();
if (!r2013_plus && !acis_empty) {
@@ -1471,7 +1496,9 @@ bool read_modeler_geometry(BitReader& reader, BitReader& handles,
return false;
}
for (std::int64_t i = 0; i < num_wires; ++i) {
if (!skip_acis_wire(reader)) return false;
if (!skip_acis_wire(reader, &acis.wires, wire_point_budget)) {
return false;
}
}
}
// R2013+ 的轮廓计数在 isoline_present 之外(ACadSharp)
@@ -1491,7 +1518,10 @@ bool read_modeler_geometry(BitReader& reader, BitReader& handles,
return false;
}
for (std::int64_t w = 0; w < n; ++w) {
if (!skip_acis_wire(reader)) return false;
if (!skip_acis_wire(reader, &acis.wires,
wire_point_budget)) {
return false;
}
}
}
}
@@ -1503,7 +1533,13 @@ bool read_modeler_geometry(BitReader& reader, BitReader& handles,
if (!inner_empty) {
DwgAcis extra;
if (!read_acis_payload(reader, extra)) return false;
if (acis.data.empty()) acis = std::move(extra);
if (acis.data.empty()) {
const bool has_wireframe = acis.has_wireframe;
auto wires = std::move(acis.wires);
acis = std::move(extra);
acis.has_wireframe = has_wireframe;
if (acis.wires.empty()) acis.wires = std::move(wires);
}
return reader.ok();
}
}
@@ -1840,6 +1876,67 @@ bool decode_entity_data(BitReader& reader, BitReader& handles, DwgObject& obj,
obj.data = vertex;
return true;
}
case DwgObjectType::Polyline3D: {
DwgPolyline3D polyline;
// R13+:RC 曲线类型 + RC 标志位(无宽度/标高/拉伸方向字段)
polyline.curve_type = reader.rc();
polyline.flags = reader.rc();
if (!reader.ok()) return false;
if (traits.r2004_plus) {
const std::int64_t num_owned = reader.bl();
if (!reader.ok() || num_owned < 0 || num_owned > 1000000) {
return false;
}
polyline.num_owned = static_cast<std::uint32_t>(num_owned);
polyline.vertex_handles.resize(
static_cast<std::size_t>(num_owned));
for (auto& handle : polyline.vertex_handles) handle = handles.h();
} else {
polyline.first_vertex = handles.h();
polyline.last_vertex = handles.h();
}
polyline.seqend = handles.h();
if (!handles.ok()) return false;
obj.data = polyline;
return true;
}
case DwgObjectType::PolylineMesh: {
DwgPolylineMesh mesh;
mesh.flags = static_cast<std::uint16_t>(reader.bs());
mesh.curve_type = static_cast<std::uint16_t>(reader.bs());
mesh.num_m_verts = static_cast<std::uint32_t>(reader.bs());
mesh.num_n_verts = static_cast<std::uint32_t>(reader.bs());
mesh.m_density = static_cast<std::uint16_t>(reader.bs());
mesh.n_density = static_cast<std::uint16_t>(reader.bs());
if (!reader.ok()) return false;
if (traits.r2004_plus) {
const std::int64_t num_owned = reader.bl();
if (!reader.ok() || num_owned < 0 || num_owned > 1000000) {
return false;
}
mesh.num_owned = static_cast<std::uint32_t>(num_owned);
mesh.vertex_handles.resize(
static_cast<std::size_t>(num_owned));
for (auto& handle : mesh.vertex_handles) handle = handles.h();
} else {
mesh.first_vertex = handles.h();
mesh.last_vertex = handles.h();
}
mesh.seqend = handles.h();
if (!handles.ok()) return false;
obj.data = mesh;
return true;
}
case DwgObjectType::Vertex3D:
case DwgObjectType::VertexMesh: {
// VERTEX_3D / VERTEX_MESH:RC 标志 + 绝对 WCS 点(无 2D 宽度/凸度)
DwgVertex3D vertex;
vertex.flags = reader.rc();
read_point3(reader, vertex.location);
if (!reader.ok()) return false;
obj.data = vertex;
return true;
}
case DwgObjectType::Text: {
DwgText text;
if (!read_common_text_data(reader, handles, traits, strings, text)) {
+120 -1
View File
@@ -1351,7 +1351,8 @@ bool native_dwg_to_drawing(const std::string& filepath,
by_handle[object.handle] = &object;
if (const auto* layer = std::get_if<DwgLayer>(&object.data)) {
layer_names[object.handle] = layer->name;
} else if (std::get_if<DwgVertex2D>(&object.data) != nullptr &&
} else if ((std::get_if<DwgVertex2D>(&object.data) != nullptr ||
std::get_if<DwgVertex3D>(&object.data) != nullptr) &&
object.common.owner != 0) {
polyline_vertices[object.common.owner].push_back(&object);
}
@@ -1675,6 +1676,99 @@ bool native_dwg_to_drawing(const std::string& filepath,
converted = std::move(e);
ok = true;
}
} else if (const auto* poly =
std::get_if<DwgPolyline3D>(&object.data)) {
// 3D 多段线:顶点为绝对 WCS 坐标,无凸度/宽度
DxfPolyline e;
e.layer = layer;
e.closed = (poly->flags & 1u) != 0;
e.is_3d = true;
const auto append = [&](const DwgObject* vertex_object) {
if (vertex_object == nullptr) return;
const auto* v = std::get_if<DwgVertex3D>(&vertex_object->data);
if (v == nullptr) return;
e.vertices.push_back(DxfPolyline::Vertex{dwg_point(v->location)});
};
if (!poly->vertex_handles.empty()) {
for (const std::uint64_t handle : poly->vertex_handles) {
const auto found = by_handle.find(handle);
append(found == by_handle.end() ? nullptr : found->second);
}
} else {
const auto it = polyline_vertices.find(object.handle);
if (it != polyline_vertices.end()) {
for (const DwgObject* vertex : it->second) append(vertex);
}
}
if (!e.vertices.empty()) {
converted = std::move(e);
ok = true;
}
} else if (const auto* mesh =
std::get_if<DwgPolylineMesh>(&object.data)) {
// 多边形网格:按 M×N 网格生成行列折线(显示级线框,非曲面)
std::vector<Point3D> points;
const auto append_point = [&](const DwgObject* vertex_object) {
if (vertex_object == nullptr) return;
const auto* v = std::get_if<DwgVertex3D>(&vertex_object->data);
if (v == nullptr) return;
points.push_back(dwg_point(v->location));
};
if (!mesh->vertex_handles.empty()) {
for (const std::uint64_t handle : mesh->vertex_handles) {
const auto found = by_handle.find(handle);
append_point(found == by_handle.end() ? nullptr
: found->second);
}
} else {
const auto it = polyline_vertices.find(object.handle);
if (it != polyline_vertices.end()) {
for (const DwgObject* vertex : it->second) {
append_point(vertex);
}
}
}
if (!points.empty()) {
const auto owner = block_index.find(object.common.owner);
std::vector<DxfEntity>* target =
owner != block_index.end()
? &doc.blocks[owner->second].entities
: &doc.entities;
const std::size_t m = mesh->num_m_verts;
const std::size_t n = mesh->num_n_verts;
std::size_t emitted = 0;
const auto emit_line = [&](std::size_t first, std::size_t step,
std::size_t count) {
if (count < 2 ||
first + step * (count - 1) >= points.size()) {
return;
}
DxfPolyline line;
line.layer = layer;
line.is_3d = true;
line.vertices.reserve(count);
for (std::size_t i = 0; i < count; ++i) {
line.vertices.push_back(
DxfPolyline::Vertex{points[first + step * i]});
}
target->push_back(std::move(line));
++emitted;
};
if (m >= 2 && n >= 2 && m * n == points.size()) {
for (std::size_t row = 0; row < m; ++row) {
emit_line(row * n, 1, n);
}
for (std::size_t col = 0; col < n; ++col) {
emit_line(col, n, m);
}
} else {
emit_line(0, 1, points.size());
}
if (emitted != 0) {
parsed += emitted; // 一个网格对象可产出多条折线
continue;
}
}
} else if (const auto* solid = std::get_if<DwgSolid>(&object.data)) {
Dxf3DFace e;
e.layer = layer;
@@ -1706,6 +1800,31 @@ bool native_dwg_to_drawing(const std::string& filepath,
converted = std::move(e);
ok = true;
}
} else if (const auto* acis = std::get_if<DwgAcis>(&object.data)) {
// 3DSOLID/BODY/REGION 的线框/等值线是文件自带的显示级几何,
// 按 3D 多段线导入;B-Rep 表面重建不在本层,不伪造实体。
std::size_t emitted = 0;
const auto owner = block_index.find(object.common.owner);
std::vector<DxfEntity>* target =
owner != block_index.end()
? &doc.blocks[owner->second].entities
: &doc.entities;
for (const auto& wire : acis->wires) {
if (wire.size() < 2) continue;
DxfPolyline e;
e.layer = layer;
e.is_3d = true;
e.vertices.reserve(wire.size());
for (const auto& point : wire) {
e.vertices.push_back(DxfPolyline::Vertex{dwg_point(point)});
}
target->push_back(std::move(e));
++emitted;
}
if (emitted != 0) {
parsed += emitted; // 一个对象可产出多条折线
continue;
}
}
if (!ok) {
+1
View File
@@ -686,6 +686,7 @@ TEST(DwgObjectDecode, DebugSingleFile) {
std::cout << " acis_version=" << acis->acis_version
<< " binary=" << acis->is_binary
<< " wire=" << acis->has_wireframe
<< " wires=" << acis->wires.size()
<< " bytes=" << acis->data.size();
if (const char* dump = std::getenv("VDE_DWG_ACIS_DUMP")) {
const std::string path = std::string(dump) + "_" +