void test4()
{
AcDbObjectId entId;
ads_name ent_name;
AcGePoint3d pickPnt;
if (acedEntSel(_T("\n Pick a PFACE\n"), ent_name,
asDblArray(pickPnt)) != RTNORM) return;
if (!eOkVerify(acdbGetObjectId(entId, ent_name))) return;
AcDbSmartObjectPointer<AcDbPolyFaceMesh> pFace(entId, AcDb::kForWrite);
// polyface mesh
if (!eOkVerify(pFace.openStatus())) return;
AcGePoint3dArray vertexArray;
AcArray<Adesk::Int32> faceArray;
AcArray<AcCmColor> colorArray;
AcArray<AcDbObjectId> materialArray;
Acad::ErrorStatus es = GetPolyFaceMeshData(pFace, vertexArray, faceArray);
if (es != eOk)
return;
/*Mesh Type ":
Specifies the type of mesh to be used in the conversion. (FACETERMESHTYPE system variable)
0 : Smooth Mesh Optimized. Sets the shape of the mesh faces to adapt to the shape of the mesh object.
1 : Mostly Quads. Sets the shape of the mesh faces to be mostly quadrilateral.
2 : Triangles. Sets the shape of the mesh faces to be mostly triangular.*/
int faceterMeshType = 0;
int nSmoothLevel = 0;
int nMaxFaces = 0;
resbuf rb;
/*
This variable sets the default level of smoothness that is applied to
mesh that is created as a result of conversion from another object with the MESHSMOOTH command.
The value cannot be greater than the value of SMOOTHMESHMAXLEV.
*/
if (acedGetVar(_T("FACETERSMOOTHLEV"), &rb) == RTNORM)
{
nSmoothLevel = rb.resval.rint;
nSmoothLevel = (nSmoothLevel < 0 ? 0 : nSmoothLevel);
}
if (acedGetVar(_T("FACETERMESHTYPE"), &rb) == RTNORM)
{
faceterMeshType = rb.resval.rint;
}
int newSubdLevel = (faceterMeshType == 0) ? nSmoothLevel : 0;
int oldSubdLevel = nSmoothLevel;
// If oldSubdivLevel > SmoothMeshMaxLev, we need to reset oldSubdivLevel
// value to SmoothMeshMaxLev.
// If newSubdivLevel > SmoothMeshMaxLev, we need to reset newSubdivLevel
// value to SmoothMeshMaxLev.
//The valid range is from 1 to 255. The recommended range is 1 - 5.
//Use this limit to prevent creating extremely dense meshes that might affect program performance.
if (acedGetVar(_T("SMOOTHMESHMAXLEV"), &rb) == RTNORM)
{
int nMaxLevel = rb.resval.rint;
if (nMaxLevel >= 0 && oldSubdLevel > nMaxLevel)
oldSubdLevel = nMaxLevel;
if (nMaxLevel >= 0 && newSubdLevel > nMaxLevel)
newSubdLevel = nMaxLevel;
}
/*We create an in-memory mesh and convert mesh to solid*/
AcDbSubDMesh* pSubDMesh = nullptr;
if (!eOkVerify(CreateSubdMesh(vertexArray, faceArray, newSubdLevel, pSubDMesh)))
return;
pSubDMesh->setPropertiesFrom(pFace);
/*Create A solid and Convert SubDMesh to Solid*/
AcDb3dSolid* pMeshSolid = new AcDb3dSolid();
AcDbObjectId meshSolId;
/*Now convert to Solid using CONVTOSOLID API*/
/*We will restrict to polygonal solid, we set false for smoothness, so not to abuse CPU*/
pSubDMesh->convertToSolid(false, false, pMeshSolid);
postToDatabase(NULL, pMeshSolid, meshSolId);
/*Delete Pface */
if (pFace)
{
pFace->erase();
}
}