diff --git a/src/Core/SectionBoxExporter.cs b/src/Core/SectionBoxExporter.cs
index a2e54ae..5eefeb8 100644
--- a/src/Core/SectionBoxExporter.cs
+++ b/src/Core/SectionBoxExporter.cs
@@ -305,12 +305,13 @@ namespace NavisworksTransport.Core
}
///
- /// 递归遍历收集盒内对象和可见节点
+ /// 递归遍历收集盒内对象和可见节点。
+ /// 返回:本子树是否存在盒内对象(后序传播用——命中路径的祖先由父级逐层加入 visibleSet)。
///
- private void TraverseAndCollect(ModelItem item, BoundingBox3D sectionBox,
+ private bool TraverseAndCollect(ModelItem item, BoundingBox3D sectionBox,
List objectsInBox, HashSet visibleSet, bool prune)
{
- if (item == null || item.IsHidden) return;
+ if (item == null || item.IsHidden) return false;
bool hasGeometry = item.HasGeometry;
@@ -323,7 +324,7 @@ namespace NavisworksTransport.Core
var groupBox = item.BoundingBox();
if (!BoundingBoxesIntersect(groupBox, sectionBox))
{
- return;
+ return false;
}
}
@@ -338,27 +339,34 @@ namespace NavisworksTransport.Core
double sizeZ = bbox.Max.Z - bbox.Min.Z;
bool hasVolume = sizeX > 0.0001 && sizeY > 0.0001 && sizeZ > 0.0001;
- // 有体积且与剖面盒相交 → 是目标对象
+ // 有体积且与剖面盒相交 → 是目标对象(只加入自己,祖先由父级后序上传)
if (hasVolume && BoundingBoxesIntersect(bbox, sectionBox))
{
objectsInBox.Add(item);
-
- // 将该对象及其所有祖先标记为可见
- foreach (var ancestor in item.AncestorsAndSelf)
- {
- visibleSet.Add(ancestor);
- }
+ visibleSet.Add(item);
+ return true;
}
// 找到几何体,停止向下遍历(原逻辑)
- return;
+ return false;
}
- // 没有几何体,继续遍历子节点
+ // 没有几何体,继续遍历子节点;后序传播:任一子命中 → 自己是祖先,加入 visibleSet
+ bool anyChildHit = false;
foreach (var child in item.Children)
{
- TraverseAndCollect(child, sectionBox, objectsInBox, visibleSet, prune);
+ if (TraverseAndCollect(child, sectionBox, objectsInBox, visibleSet, prune))
+ {
+ anyChildHit = true;
+ }
}
+
+ if (anyChildHit)
+ {
+ visibleSet.Add(item);
+ }
+
+ return anyChildHit;
}
///