|
bool getMesh(ap::STrng& mesh, const AcDb3dSolid* solid)
{
AcArray<AcGePoint3d> vs;
AcArray<Adesk::Int32> is;
AcGiFaceData* fs = nullptr;
AcDbFaceterSettings set = {};
AcDbExtents ext = {};
ThrowIfFailed(solid->getGeomExtents(ext));
const AcGeVector3d dir = ext.maxPoint() - ext.minPoint();
set.faceterMeshType = 2;
set.faceterMaxEdgeLength = dir.length() * 0.1;
AcDb3dSolid* s = const_cast<AcDb3dSolid*>(solid);
ThrowIfFailed(acdbGetObjectMesh(s, &set, vs, is, fs));
struct Triangle
{
int32_t m_dummy;
int32_t m_i0;
int32_t m_i1;
int32_t m_i2;
};
const auto size = is.length() / sizeof(Triangle);
const Triangle* ts = reinterpret_cast<const Triangle*>(&is[0]);
for (auto i = 0; i < size; ++i)
{
const Triangle* t = ts + i;
const AcGePoint3d pa = vs[t->m_i0];
const AcGePoint3d pb = vs[t->m_i1];
const AcGePoint3d pc = vs[t->m_i2];
const D3 p0 = { pa.x, pa.y, pa.z };
const D3 p1 = { pb.x, pb.y, pb.z };
const D3 p2 = { pc.x, pc.y, pc.z };
addTr(mesh, p0, p1, p2);
return true;
}
代码2 :
// Description : get mesh from face
bool getMesh(ap::STrng& mesh, const AcBrFace& face)
{
AcBr::ErrorStatus returnValue = AcBr::eOk;
AcGe::EntityId entId;
if(face.getSurfaceType(entId) != AcBr::eOk)
return false;
// conditionally set the mesh controls based on surface type
AcBrMesh2dControl meshCtrl;
meshCtrl.setElementShape(AcBr::kAllTriangles);
// make the mesh filter from the topology entity and the mesh controls
const AcBrEntity* meshEnt = (AcBrEntity*)&face;
AcBrMesh2dFilter meshFilter;
meshFilter.insert(make_pair(meshEnt, (const AcBrMesh2dControl)meshCtrl));
// generate the mesh, display any errors and attempt to dump all
// generated elements (most errors are not fatal so we want to do
// the best we can with whatever subset of the face was meshed).
AcBrMesh2d faceMesh;
if(faceMesh.generate(meshFilter) != eOk)
return false;
// traverse elements (triangles)
TVectorN<D3, 3> aPt;
AcBrMesh2dElement2dTraverser meshElemTrav;
meshElemTrav.setMesh(faceMesh);
for(; !meshElemTrav.done(); meshElemTrav.next())
{
// traverse nodes (points)
AcBrElement2dNodeTraverser elemNodeTrav;
elemNodeTrav.setElement(meshElemTrav);
aPt.setSize(0);
for(; !elemNodeTrav.done(); elemNodeTrav.next())
{
AcBrNode node;
elemNodeTrav.getNode(node);
AcGePoint3d p;
node.getPoint(p);
aPt.add().setValue(p.x, p.y, p.z);
}
addTr(mesh, aPt[0], aPt[1], aPt[2]);
}
return true;
}
bool getMesh(ap::STrng& mesh, const AcDb3dSolid* solid)
{
//create brep traverser
std::unique_ptr<AcBrBrep> brep = std::make_unique<AcBrBrep>();
if(brep->set(*solid) != AcBr::eOk)
return false;
AcBrBrepFaceTraverser trav;
if(trav.setBrep(*brep.get()) != AcBr::eOk)
return false;
//traverse all faces
AcBrFace face;
while(!trav.done())
{
trav.getFace(face);
getMesh(mesh, face);
if(trav.next() != AcBr::eOk)
break;
}
return true;
} |
|