ODA将FacetModeler::Body实体导出IFC对象

        减少导出IFC文件的开销,使用已有Body模型直接转出IFC对象。首先遇到Revit对IFC版本支持问题。Revit2023之前对IFC2.4支持不全,选择IFC2x3。IFC2x3类支持两种转换方式,一种OdDb3dSolid遍历mesh转出IFC对象,例子中有源码。另一种AdvancedBrep,无源码。通过反向解析Revit导出的IFC2x3文件,确定IFC文件中Brep节点,结合IfcModelGeometryFiller的接口形成Body转IFC2x3函数。

bool ConvertBody(FacetModeler::Body& body, OdIfc::OdIfcEntityPtr& pEnt, OdIfcModelPtr pModel)
{
    OdSharedPtr<IfcModelGeometryFiller> pGemetryFiller = new IfcModelGeometryFiller(pModel);
    IfcRepresentationBuilderPtr builder = IfcRepresentationBuilder::createObject(pGemetryFiller, pEnt);
    OdIfc::OdIfcEntityPtr pGeoRepresntionModel = ifcCreator.GetFiller()->getGeometricRepresentationContext("Model");
    if (pGeoRepresntionModel.isNull())
    {
        ASSERT(FALSE);
        return false;
    }

    struct Point3dToDAIObjectId
    {
        Point3dToDAIObjectId(OdGePoint3d vpt, OdDAIObjectId vid) { pt = vpt; id = vid; }
        OdGePoint3d pt;
        OdDAIObjectId id;
    };
    typedef std::vector<Point3dToDAIObjectId> VecEdgePts;
    VecEdgePts vecEdgePts;
    auto FindCartesianPoint = [&](const OdGePoint3d& pt)->OdDAIObjectId {
        for (auto it = vecEdgePts.begin(); it != vecEdgePts.end(); it++)
        {
            if (it->pt.isEqualTo(pt))
                return it->id;
        }
        OdDAIObjectId id = OdDAIObjectId(ifcCreator.GetFiller()->createCartesianPoint3D(pt)->id());
        Point3dToDAIObjectId ptPair(pt, id);
        vecEdgePts.push_back(ptPair);
        return id;
    };

    OdDAIObjectIds idFaces;

    GeMesh::OdGeTrMesh mesh;
    body.generateMesh(mesh);
    OdInt32Array faceArray;
    faceArray.reserve(mesh.m_aTr.logicalLength() * 4);
    for (unsigned int n = 0; n < mesh.m_aTr.logicalLength(); ++n)
    {
        OdDAIObjectIds ids;
        const GeMesh::OdGeTr& tr = mesh.m_aTr[n];
        OdDAIObjectId id = FindCartesianPoint(mesh.m_aVx[tr.tr[0]]);
        ids.push_back(id);
        id = FindCartesianPoint(mesh.m_aVx[tr.tr[1]]);
        ids.push_back(id);
        id = FindCartesianPoint(mesh.m_aVx[tr.tr[2]]);
        ids.push_back(id);

        OdIfc::OdIfcEntityPtr pLoop = pGemetryFiller->createPolyLoop(ids);
        OdIfc::OdIfcEntityPtr pOuterBound = pGemetryFiller->createFaceOuterBound(OdDAIObjectId(pLoop->id()), TRUE);
        OdDAIObjectIds idBounds;
        idBounds.push_back(OdDAIObjectId(pOuterBound->id()));
        OdIfc::OdIfcEntityPtr pIfcFace = pGemetryFiller->createFace(idBounds);
        idFaces.push_back(OdDAIObjectId(pIfcFace->id()));
    }
            
    OdIfc::OdIfcEntityPtr pClosedShell = pGemetryFiller->createClosedShell(idFaces);
    OdIfc::OdIfcEntityPtr pFacetedBrep = pGemetryFiller->createFacetedBrep(OdDAIObjectId(pClosedShell->id()));

    OdIfc::OdIfcEntityPtr pShapeRepresentation = builder->appendRepresentation(pFacetedBrep, pGeoRepresntionModel, OdAnsiString("Body"), OdAnsiString("Brep"));
    return true;
}

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值