APS Viewer中Section Box作为范围框:如何仅操作框内元素?
APS Viewer中Section Box的元素隔离与选择范围限制方案
Section Box默认仅做视觉裁剪,不会自动限制元素选择范围,需通过代码逻辑实现框内元素的精准选择与隔离:
核心思路
通过判断元素的**世界边界盒(Bounding Box)**是否处于当前Section Box范围内,筛选出符合条件的元素后再执行选择或隔离操作。
具体实现方法
1. 判断元素是否在Section Box内
先实现一个工具函数,用于检查单个元素的边界是否完全处于Section Box中(若需允许部分重叠,可将containsBox改为intersectsBox):
function isElementInSectionBox(viewer, dbId) { const sectionBox = viewer.getSectionBox(); if (!sectionBox) return true; // 未开启Section Box时默认全选 const fragList = viewer.model.getFragmentList(); const elementBounds = new THREE.Box3(); fragList.getWorldBounds(dbId, elementBounds); return sectionBox.containsBox(elementBounds); }
2. 批量选择框内同类型元素
以选择墙(Wall)为例,先获取所有同类型元素ID,再筛选出Section Box内的元素并选中:
async function selectSameTypeInSectionBox(viewer, targetType) { // 获取目标类型的分类ID const categoryId = await viewer.model.getCategoryId(targetType); // 搜索所有该类型元素 const allTypeDbIds = await viewer.search(targetType); // 筛选框内元素 const validDbIds = []; for (const dbId of allTypeDbIds) { if (isElementInSectionBox(viewer, dbId)) { validDbIds.push(dbId); } } // 选中符合条件的元素 viewer.select(validDbIds); } // 调用示例:选择Section Box内的所有墙 selectSameTypeInSectionBox(viewer, 'Wall');
3. 隔离框内元素
选中符合条件的元素后,调用isolate方法即可隐藏框外元素,实现隔离效果:
viewer.isolate(validDbIds);
内容的提问来源于stack exchange,提问作者piede
相关产品推荐
相关产品推荐

