diff --git a/src/Core/Collision/ClashDetectiveIntegration.cs b/src/Core/Collision/ClashDetectiveIntegration.cs
index ac86bc2..d5f125f 100644
--- a/src/Core/Collision/ClashDetectiveIntegration.cs
+++ b/src/Core/Collision/ClashDetectiveIntegration.cs
@@ -1228,6 +1228,26 @@ namespace NavisworksTransport
return _allGeometryItemsCache?.ToList(); // 返回副本以保证线程安全
}
}
+
+ ///
+ /// 获取已排除通道对象的几何对象缓存(供空间索引使用)
+ ///
+ /// 排除通道后的几何对象列表,如果缓存不存在则返回null
+ public static List GetNonChannelGeometryItemsCache()
+ {
+ lock (_cacheLock)
+ {
+ if (_allGeometryItemsCache == null || _channelObjectsCache == null)
+ {
+ return null;
+ }
+
+ // 直接过滤掉通道对象
+ return _allGeometryItemsCache
+ .Where(item => !_channelObjectsCache.Contains(item))
+ .ToList();
+ }
+ }
///
/// 清除所有缓存,在模型变化时调用
diff --git a/src/Core/Spatial/SpatialIndexManager.cs b/src/Core/Spatial/SpatialIndexManager.cs
index 801cfe1..670c666 100644
--- a/src/Core/Spatial/SpatialIndexManager.cs
+++ b/src/Core/Spatial/SpatialIndexManager.cs
@@ -82,21 +82,21 @@ namespace NavisworksTransport.Core.Spatial
{
_cellSize = cellSizeInModelUnits;
- // 1. 直接从缓存获取所有几何对象(调用方已在动画生成阶段构建缓存)
- var allItems = ClashIntegration.GetAllGeometryItemsCache();
+ // 1. 直接从缓存获取已排除通道的几何对象(调用方已在动画生成阶段构建缓存)
+ var nonChannelItems = ClashIntegration.GetNonChannelGeometryItemsCache();
- if (allItems == null)
+ if (nonChannelItems == null)
{
// 缓存不存在,说明调用方未按预期构建缓存,这是逻辑错误
- LogManager.Error("[空间索引] 几何对象缓存不存在!调用方应在动画生成阶段构建缓存。");
- throw new InvalidOperationException("空间索引构建失败:几何对象缓存未初始化。请先调用 BuildAllGeometryItemsCache()。");
+ LogManager.Error("[空间索引] 几何对象缓存或通道缓存不存在!调用方应在动画生成阶段构建缓存。");
+ throw new InvalidOperationException("空间索引构建失败:几何对象缓存未初始化。请先调用 BuildAllGeometryItemsCache() 和 BuildChannelObjectsCache()。");
}
- LogManager.Info($"[空间索引] 从缓存获取 {allItems.Count} 个几何对象(含通道)");
+ LogManager.Info($"[空间索引] 从缓存获取 {nonChannelItems.Count} 个非通道几何对象(已过滤通道)");
- if (allItems.Count == 0)
+ if (nonChannelItems.Count == 0)
{
- LogManager.Warning("[空间索引] 场景中没有几何对象");
+ LogManager.Warning("[空间索引] 场景中没有非通道几何对象");
return;
}
@@ -104,22 +104,14 @@ 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)
+ foreach (var item in nonChannelItems)
{
try
{
- // 排除通道对象
- if (ClashIntegration.Instance.IsChannelObjectPublic(item))
- {
- channelExcludedCount++;
- continue;
- }
-
// 获取包围盒中心作为对象位置
var bbox = item.BoundingBox();
var center = new Vector3d(
@@ -149,8 +141,7 @@ namespace NavisworksTransport.Core.Spatial
sw.Stop();
LogManager.Info("[空间索引] 构建完成");
- LogManager.Info($" - 成功索引: {indexedCount} 个对象");
- LogManager.Info($" - 排除通道: {channelExcludedCount} 个对象");
+ LogManager.Info($" - 成功索引: {indexedCount} 个对象(通道已在缓存阶段过滤)");
LogManager.Info($" - 失败: {failedCount} 个对象");
LogManager.Info($" - 格子数量: {_globalSpatialIndex.CellCount} 个");
LogManager.Info($" - 耗时: {sw.ElapsedMilliseconds} ms");