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 do the trianglute in
BentleyStatus ElementGraphicsProcessor::_ProcessFacets(PolyfaceQueryCR facets, bool isFilled)
where class ElementGraphicsProcessor : public Bentley::DgnPlatform::IElementGraphicsProcessor.
There's an example delivered with the SDK:
examples\Elements\Polyfacetool
Regards, Jon Summers LA Solutions
Thanks Jon for the reply, my requirement is that I have a Dgn model, which contain a Mesh element, I want to get the mesh element's triangle points, indexes, normals, and then with that triangles information, I need to write to other 3d model file format in my System. for example, I want to convert the Mesh element in dgn file, to a separate stl file, I will use the api to get the mesh triangles and then write the triangles into my stl file.
I do not think the sample helps me to triangulate the mesh in dgn, and then return all the triangle points, indexes, normals ...., anyway, thanks for the information.
Rick cheng said:I do not think the sample helps me to triangulate the mesh
Perhaps the example doesn't do what you want. However, the ElementGraphicsProcessor API provides that capability. It eliminates the detailed work you must do with the PolyfaceHeader API. I believe that it's used in MicroStation for just the kind of thing you want to achieve.
thanks Jon for the comments, I am sorry I did not make my quesiton clear, I already use the ElementGraphicsProcessor API to get the triangles information for Dgn file, and it works well for most of models, but with this dgn model i attached, the geometry is not accurate, and I wan to find a way to improve the triangle precision or maybe improve the triangle density...
Hello Rick,
I used follow options to create an accurate result as below:
IFacetOptionsPtr facetOptions = IFacetOptions::Create(); facetOptions->SetEdgeHiding(false); facetOptions->SetIgnoreFaceMaterialAttachments(true); facetOptions->SetMaxPerFace(3); //Only apply to type 18/19 elements facetOptions->SetCurvedSurfaceMaxPerFace(3); //Important for smartsolid facetOptions->SetNormalsRequired(true); facetOptions->SetAngleTolerance(0.1);
I wrote output data into an JSON file as below:
https://communities.bentley.com/cfs-file/__key/communityserver-discussions-components-files/343173/geo.json
Answer Verified By: Rick cheng
Thanks Fu for the reply, I have fix the issue I met previously, everything with Microstation api is correct, but I make a stupid mistake when write to the STL file, which lead to precision lost.