From f761d936763d2a6dea0333d8e339559e721b3992 Mon Sep 17 00:00:00 2001 From: tian <11429339@qq.com> Date: Tue, 14 Oct 2025 12:05:05 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E9=80=9A=E9=81=93?= =?UTF-8?q?=E5=AF=B9=E8=B1=A1=E6=8E=92=E9=99=A4=E9=80=BB=E8=BE=91=E5=88=B0?= =?UTF-8?q?=E7=A9=BA=E9=97=B4=E7=B4=A2=E5=BC=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改内容: 1. 在 ClashDetectiveIntegration 中添加 IsChannelObjectPublic() 公开方法 2. SpatialIndexManager.BuildGlobalIndex() 构建索引前调用 BuildChannelObjectsCache() 3. 索引循环中过滤通道对象,避免将其加入空间索引 4. 增强日志输出,显示排除的通道对象数量 技术细节: - 使用已有的 _channelObjectsCache 进行 O(1) 查询 - 在索引构建时过滤(一次性)而非每次查询时过滤 - 保持与旧架构相同的通道排除逻辑 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../Collision/ClashDetectiveIntegration.cs | 12 ++++++++++- src/Core/Spatial/SpatialIndexManager.cs | 20 +++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/Core/Collision/ClashDetectiveIntegration.cs b/src/Core/Collision/ClashDetectiveIntegration.cs index c85414c..0782127 100644 --- a/src/Core/Collision/ClashDetectiveIntegration.cs +++ b/src/Core/Collision/ClashDetectiveIntegration.cs @@ -1087,7 +1087,7 @@ namespace NavisworksTransport { BuildChannelObjectsCache(); } - + // 直接查询缓存,避免递归和重复属性查询 return _channelObjectsCache.Contains(item); } @@ -1098,6 +1098,16 @@ namespace NavisworksTransport } } + /// + /// 公开方法:检查物体是否为通道物体(供外部使用) + /// + /// 要检查的模型对象 + /// 如果是通道对象返回 true + public bool IsChannelObjectPublic(ModelItem item) + { + return IsChannelObject(item); + } + /// /// 构建通道对象缓存,一次性扫描所有对象,避免重复的属性查询 /// diff --git a/src/Core/Spatial/SpatialIndexManager.cs b/src/Core/Spatial/SpatialIndexManager.cs index f5a5968..135cc7f 100644 --- a/src/Core/Spatial/SpatialIndexManager.cs +++ b/src/Core/Spatial/SpatialIndexManager.cs @@ -6,6 +6,9 @@ using Autodesk.Navisworks.Api; using NavisworksTransport.Utils; using g4; // geometry4Sharp +// 使用命名空间引用以避免类名冲突 +using ClashIntegration = NavisworksTransport.ClashDetectiveIntegration; + namespace NavisworksTransport.Core.Spatial { /// @@ -79,12 +82,16 @@ namespace NavisworksTransport.Core.Spatial { _cellSize = cellSizeInModelUnits; + // 0. 构建通道对象缓存(用于排除通道) + ClashIntegration.Instance.BuildChannelObjectsCache(); + ClashIntegration.BuildAllGeometryItemsCache(); + // 1. 获取所有几何对象 var allItems = Application.ActiveDocument.Models.RootItemDescendantsAndSelf .Where(item => item.HasGeometry) .ToList(); - LogManager.Info($"[空间索引] 找到 {allItems.Count} 个几何对象"); + LogManager.Info($"[空间索引] 找到 {allItems.Count} 个几何对象(含通道)"); if (allItems.Count == 0) { @@ -96,14 +103,22 @@ namespace NavisworksTransport.Core.Spatial _globalSpatialIndex = new SpatialHashGrid(cellSizeInModelUnits); _objectPositions.Clear(); - // 3. 索引所有对象 + // 3. 索引所有对象(排除通道对象) int indexedCount = 0; int failedCount = 0; + int channelExcludedCount = 0; foreach (var item in allItems) { try { + // 排除通道对象 + if (ClashIntegration.Instance.IsChannelObjectPublic(item)) + { + channelExcludedCount++; + continue; + } + // 获取包围盒中心作为对象位置 var bbox = item.BoundingBox(); var center = new Vector3d( @@ -134,6 +149,7 @@ namespace NavisworksTransport.Core.Spatial LogManager.Info("[空间索引] 构建完成"); LogManager.Info($" - 成功索引: {indexedCount} 个对象"); + LogManager.Info($" - 排除通道: {channelExcludedCount} 个对象"); LogManager.Info($" - 失败: {failedCount} 个对象"); LogManager.Info($" - 格子数量: {_globalSpatialIndex.CellCount} 个"); LogManager.Info($" - 耗时: {sw.ElapsedMilliseconds} ms");