如何从IFC模型选中的FragmentMesh获取Express ID/Global ID?
解决IFC构件单个expressId/globalId获取问题
不用高亮器的话,直接通过Fragment的faceGroups就能拿到单个构件的ID,核心是利用射线击中的面索引定位到对应的构件分组,步骤如下:
- 从射线检测结果中提取**击中面的索引(faceIndex)**和对应的FragmentMesh
- 遍历Fragment的
faceGroups,找到包含该faceIndex的分组:每个分组对应一个独立构件,里面存储了该构件的expressID - 通过
expressID调用IFC管理器的方法获取构件的GlobalId
代码示例
// 假设你已经通过SimpleRayCaster得到了相交结果intersect const hitMesh = intersect.object; const hitFaceIndex = intersect.faceIndex; const fragment = hitMesh.fragment; // 定位对应构件的expressId let targetExpressId = null; for (const group of fragment.faceGroups) { // 判断当前面是否在这个构件的面范围内 if (hitFaceIndex >= group.startFace && hitFaceIndex < group.startFace + group.faceCount) { targetExpressId = group.expressID; break; } } // 通过expressId获取globalId if (targetExpressId) { const ifcProduct = ifcManager.getIfcProduct(targetExpressId); const globalId = ifcProduct.GlobalId.value; console.log("选中构件的expressId:", targetExpressId); console.log("选中构件的globalId:", globalId); }
关键说明
faceGroups是Fragment内置的分组信息,每个分组对应一个IFC构件,记录了该构件所有面在Mesh中的起始位置和数量,完全不需要依赖高亮器模块- 只要你的IFC模型是按构件拆分生成的Fragment(这是绝大多数IFC加载器的默认行为),这个方法就能精准定位到单个构件的ID
内容的提问来源于stack exchange,提问作者adamaf
相关产品推荐
相关产品推荐

