Merging coplanar faces of a SubDMesh

By Balaji Ramamoorthy

The faces of a SubDMesh can be merged together if they are coplanar using the "mergeFaces" method of the "AcDbSubDMesh" class. Here is sample code to demonstrated this.

// meshObjectId : 
// ObjectId of the SubDMesh entity whose faces need merging
 
Acad::ErrorStatus es;
AcDbSubDMesh *pMesh = NULL;
es = acdbOpenObject(pMesh, meshObjectId, kForWrite);
if(es != Acad::eOk)
    return;
 
AcDbFullSubentPathArray subentPaths;
es = pMesh->getSubentPath(-1, kFaceSubentType, subentPaths);
 
Adesk::Int32 numOfFaces = 0;
pMesh->numOfFaces(numOfFaces);
for(int face=0; face < numOfFaces; face++)
{
    int faceIndex = 0;
    AcGePlane facePlane1;
    es = pMesh->getFacePlane(
                    subentPaths.at(faceIndex).subentId(),
                    facePlane1);
    AcGePlane facePlane2;
    es = pMesh->getFacePlane(
                    subentPaths.at(faceIndex+1).subentId(),
                    facePlane2);
    if(facePlane1.isCoplanarTo(facePlane2) == Adesk::kTrue)
    {
        AcDbFullSubentPathArray subentPathsToMerge;
        subentPathsToMerge.append(
                    subentPaths.at(faceIndex));
        subentPathsToMerge.append(
                    subentPaths.at(faceIndex+1));
        es = pMesh->mergeFaces(subentPathsToMerge);
        if(es == Acad::eOk)
            acutPrintf(ACRX_T("n2 faces merged."));
        else
            acutPrintf(ACRX_T("nError merging the faces."));
    }
    else
    {
        acutPrintf(ACRX_T("nFaces are non-coplanar."));
    }
}
pMesh->close();

Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading