Hi experts,
I am currently try to get the dgn mesh geometry and export to my system, which is to contruct a triangle mesh file(STL, OpenCTM,,,) but when I get the dgn mesh and write it to other file format, I found there will be
distortion, please see below screen shot, i also attach the code how i get the triangles and the dgn mode i used.
I am using Microstaion CE Update 7, 10.07.00.39.
this is the original model,
V4-2.dgn
and i use below apis to get the triangle mesh: there is only one mesh(PolyfaceHeaderPtr) within the dgn model,
pMesh->m_pMesh->Triangulate(); //pMesh->m_pMesh is a PolyfaceHeaderPtr
auto points = pMesh->m_pMesh->Point(); auto normals = pMesh->m_pMesh->Normal(); auto indexs = pMesh->m_pMesh->PointIndex(); pMesh->m_pointCoordsCount = points.size() * 3; pMesh->m_pointCoords = new double[points.size() * 3]; for (int index = 0; index < points.size(); ++index) { auto adjustPoint= points[index]; pMesh->m_pointCoords[index * 3] = adjustPoint.x; pMesh->m_pointCoords[index * 3 + 1] = adjustPoint.y; pMesh->m_pointCoords[index * 3 + 2] = adjustPoint.z; } pMesh->m_normalCoords = new double[normals.size() * 3]; pMesh->m_normalCoordsCount = normals.size() * 3; for (int index = 0; index < normals.size(); ++index) { pMesh->m_normalCoords[index * 3] = (normals[index].x); pMesh->m_normalCoords[index * 3 + 1] = (normals[index].y); pMesh->m_normalCoords[index * 3 + 2] = (normals[index].z); } size_t triangleCount = indexs.size() / 4; pMesh->m_indexAll = new int[triangleCount * 3]; int realIndex = 0; for (int index = 0; index < indexs.size(); ++index) { auto pointIndex = indexs[index]; if (pointIndex == 0) continue; if (pointIndex < 0) pointIndex = pointIndex * -1; pMesh->m_indexAll[realIndex] = (pointIndex - 1); realIndex++; }
I am not sure the index matrix is correct or not, but it works for most models.
and with above code i am able to get the triangle mesh data which i can save to a STL file, but the STL geometry seems lost some triangles at the edge which lead to the distortion.
the result stl mesh looks as below,
STL mesh no pt offset + normal 0 0 1.dgn
we can see the distortion on the edge, how we can remedy this distortion?
and I also try to export the dgn mesh to a stl file in Microstaion(with export command), and then import the stl file into a new dgn file,
export from Microstation.dgn
and the distortion is much worse.
so is there any way to fix this distortions when i want to get the triangle mesh from a dgn mesh?
by the way, I am using below options for mesh triangulate,
const double tollerance = 0.001; const int arcSegmentCount = 12;
DRange3d rangeBox; m_eh.GetDisplayHandler()->GetBasisRange(m_eh, rangeBox); double boxDistance = rangeBox.DiagonalDistance(); pFacetOptionsPtr->SetChordTolerance(boxDistance * tollerance); pFacetOptionsPtr->SetAngleTolerance(3.1415926 / arcSegmentCount); pFacetOptionsPtr->SetNormalsRequired(1);
Please add the below two lines for triangulation.
pFacetOptionsPtr->SetMaxPerFace(3); //Only apply to type 18/19 elementspFacetOptionsPtr->SetCurvedSurfaceMaxPerFace(3); //Important for SmartSolid
thankk Fu for the reply, I add those two lines, but still get the same result.
is there any way to improve the triangle count to improve the accuracy?
Hi Fu,
Yongan.Fu I try with those options, but the result is still the same, i think the problem here is that the result triangle density is not enought, in some area there are missing triangles. do u know how to improve the result triangle density?
Answer Verified By: Rick cheng
thank Fu, I found out the reason, its has nothing to do with the api, but my mistake. the api works correctly.