How to get the dng mesh data used to construct a triange mesh(to a STL file) without any distortion?

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,

Original ModelOriginal modeV4-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 model view in MicrostationSTL 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,

exported stl file by microstation Export commandexport 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?

Parents Reply Children
  • 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:

    geo.json
    {
    	"bosclass" : "componentGeoes",
    	"code" : "V4-2.dgn - Default - 192233",
    	"colors" : 
    	[
    		0.76470588235294112,
    		0.76470588235294112,
    		0.76470588235294112,
    		1.0
    	],
    	"indices" : 
    	[
    		38,
    		21,
    		24,
    		21,
    		38,
    		39,
    		38,
    		24,
    		4,
    		38,
    		4,
    		7,
    		7,
    		4,
    		26,
    		7,
    		26,
    		35,
    		35,
    		26,
    		34,
    		34,
    		26,
    		5,
    		34,
    		5,
    		33,
    		33,
    		5,
    		6,
    		33,
    		6,
    		30,
    		33,
    		30,
    		31,
    		41,
    		20,
    		21,
    		20,
    		41,
    		3,
    		3,
    		41,
    		42,
    		41,
    		21,
    		39,
    		3,
    		42,
    		43,
    		3,
    		43,
    		2,
    		2,
    		43,
    		8,
    		2,
    		8,
    		18,
    		18,
    		8,
    		17,
    		17,
    		8,
    		9,
    		17,
    		9,
    		10,
    		17,
    		10,
    		14,
    		14,
    		10,
    		11,
    		14,
    		11,
    		13,
    		13,
    		11,
    		1,
    		1,
    		11,
    		0,
    		0,
    		12,
    		1,
    		1,
    		12,
    		48,
    		1,
    		48,
    		13,
    		13,
    		48,
    		16,
    		13,
    		16,
    		14,
    		14,
    		16,
    		15,
    		14,
    		15,
    		17,
    		17,
    		15,
    		49,
    		17,
    		49,
    		18,
    		18,
    		49,
    		19,
    		18,
    		19,
    		2,
    		2,
    		19,
    		50,
    		2,
    		50,
    		3,
    		3,
    		50,
    		51,
    		3,
    		51,
    		23,
    		3,
    		23,
    		20,
    		20,
    		23,
    		21,
    		21,
    		23,
    		22,
    		21,
    		22,
    		24,
    		24,
    		22,
    		25,
    		24,
    		25,
    		52,
    		24,
    		52,
    		4,
    		4,
    		52,
    		26,
    		26,
    		52,
    		27,
    		26,
    		27,
    		5,
    		5,
    		27,
    		28,
    		5,
    		28,
    		6,
    		6,
    		28,
    		29,
    		6,
    		29,
    		30,
    		30,
    		29,
    		53,
    		30,
    		53,
    		31,
    		31,
    		53,
    		54,
    		31,
    		54,
    		33,
    		33,
    		54,
    		32,
    		33,
    		32,
    		34,
    		34,
    		32,
    		55,
    		34,
    		55,
    		36,
    		34,
    		36,
    		35,
    		35,
    		36,
    		7,
    		7,
    		36,
    		56,
    		7,
    		56,
    		38,
    		38,
    		56,
    		37,
    		38,
    		37,
    		40,
    		38,
    		40,
    		39,
    		39,
    		40,
    		41,
    		41,
    		40,
    		57,
    		41,
    		57,
    		42,
    		42,
    		57,
    		58,
    		42,
    		58,
    		43,
    		43,
    		58,
    		59,
    		43,
    		59,
    		44,
    		43,
    		44,
    		8,
    		8,
    		44,
    		9,
    		9,
    		44,
    		46,
    		9,
    		46,
    		10,
    		10,
    		46,
    		45,
    		10,
    		45,
    		11,
    		11,
    		45,
    		47,
    		11,
    		47,
    		0,
    		0,
    		47,
    		12,
    		16,
    		47,
    		15,
    		47,
    		16,
    		48,
    		15,
    		47,
    		45,
    		15,
    		45,
    		49,
    		49,
    		45,
    		46,
    		49,
    		46,
    		44,
    		49,
    		44,
    		19,
    		19,
    		44,
    		50,
    		50,
    		44,
    		59,
    		50,
    		59,
    		51,
    		51,
    		59,
    		58,
    		51,
    		58,
    		57,
    		51,
    		57,
    		23,
    		23,
    		57,
    		22,
    		22,
    		57,
    		40,
    		22,
    		40,
    		37,
    		22,
    		37,
    		25,
    		25,
    		37,
    		52,
    		52,
    		37,
    		56,
    		52,
    		56,
    		27,
    		27,
    		56,
    		36,
    		27,
    		36,
    		55,
    		27,
    		55,
    		28,
    		28,
    		55,
    		32,
    		28,
    		32,
    		29,
    		29,
    		32,
    		53,
    		53,
    		32,
    		54,
    		47,
    		48,
    		12
    	],
    	"materialIndices" : 
    	[
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0
    	],
    	"normals" : [],
    	"numberOfColors" : 1,
    	"numberOfPrimitives" : 116,
    	"positions" : 
    	[
    		488869746.13316035,
    		2593540522.0998936,
    		1530733.9261686006,
    		488869649.33182812,
    		2593540608.8725972,
    		1530733.9261686006,
    		488871019.92248023,
    		2593539380.2752867,
    		1537914.1750206007,
    		488871441.78274989,
    		2593539002.1197872,
    		1538003.9061556004,
    		488873129.2750296,
    		2593537489.4518909,
    		1537765.7158786003,
    		488873908.59043926,
    		2593536790.8736429,
    		1537299.7453826005,
    		488874087.30059093,
    		2593536630.6778827,
    		1537177.4592756005,
    		488873099.36177313,
    		2593537516.2661309,
    		1537642.0785316005,
    		488870637.27064604,
    		2593539723.2843485,
    		1537642.0785316005,
    		488870247.98027623,
    		2593540072.244194,
    		1537441.3943676003,
    		488869876.44264597,
    		2593540405.2904854,
    		1537187.1620806004,
    		488869746.13316035,
    		2593540522.0998936,
    		1537097.9951266004,
    		488869425.74163938,
    		2593540164.6795902,
    		1530723.3382758598,
    		488869649.33182812,
    		2593540608.8725972,
    		1537177.4592756005,
    		488869828.04197991,
    		2593540448.676837,
    		1537299.7453826005,
    		488869507.65045893,
    		2593540091.2565336,
    		1537289.1574898597,
    		488869328.94030714,
    		2593540251.4522939,
    		1537166.8713828598,
    		488870208.60762691,
    		2593540107.5378323,
    		1537560.1552776005,
    		488870607.35738945,
    		2593539750.0985889,
    		1537765.7158786003,
    		488870286.96586847,
    		2593539392.6782856,
    		1537755.1279858598,
    		488871868.31620955,
    		2593538619.7752399,
    		1538033.9261686006,
    		488872294.84966922,
    		2593538237.4306931,
    		1538003.9061556004,
    		488871974.45814824,
    		2593537880.0103898,
    		1537993.3182628599,
    		488871547.92468858,
    		2593538262.3549366,
    		1538023.3382758598,
    		488872716.70993894,
    		2593537859.2751937,
    		1537914.1750206007,
    		488872396.31841797,
    		2593537501.8548903,
    		1537903.5871278597,
    		488873528.02479213,
    		2593537132.0126476,
    		1537560.1552776005,
    		488873207.63327116,
    		2593536774.5923443,
    		1537549.5673848598,
    		488873588.19891828,
    		2593536433.4533396,
    		1537289.1574898597,
    		488873766.90906996,
    		2593536273.2575788,
    		1537166.8713828598,
    		488874087.30059093,
    		2593536630.6778827,
    		1530733.9261686006,
    		488873990.49925876,
    		2593536717.4505863,
    		1530733.9261686006,
    		488873670.10773778,
    		2593536360.0302825,
    		1537087.4072338599,
    		488873990.49925876,
    		2593536717.4505863,
    		1537097.9951266004,
    		488873860.1897732,
    		2593536834.2599945,
    		1537187.1620806004,
    		488873488.65214294,
    		2593537167.3062859,
    		1537441.3943676003,
    		488873168.26062196,
    		2593536809.8859825,
    		1537430.8064748598,
    		488872376.19228983,
    		2593537519.8959494,
    		1537776.4279398597,
    		488872696.58381081,
    		2593537877.3162527,
    		1537787.0158326002,
    		488872284.73117489,
    		2593538246.5009103,
    		1537874.6183086003,
    		488871964.33965391,
    		2593537889.0806069,
    		1537864.0304158598,
    		488871868.31620955,
    		2593538619.7752399,
    		1537903.9261686003,
    		488871451.90124416,
    		2593538993.0495691,
    		1537874.6183086003,
    		488871040.0486083,
    		2593539362.2342272,
    		1537787.0158326002,
    		488870316.87912506,
    		2593539365.8640451,
    		1537631.4906388598,
    		488869556.05112499,
    		2593540047.870182,
    		1537176.5741878599,
    		488869927.58875525,
    		2593539714.8238902,
    		1537430.8064748598,
    		488869425.74163938,
    		2593540164.6795902,
    		1537087.4072338599,
    		488869328.94030714,
    		2593540251.4522939,
    		1530723.3382758598,
    		488869888.21610606,
    		2593539750.1175289,
    		1537549.5673848598,
    		488870699.53095925,
    		2593539022.8549833,
    		1537903.5871278597,
    		488871121.39122891,
    		2593538644.6994834,
    		1537993.3182628599,
    		488872808.88350862,
    		2593537132.0315876,
    		1537755.1279858598,
    		488873766.90906996,
    		2593536273.2575788,
    		1530723.3382758598,
    		488873670.10773778,
    		2593536360.0302825,
    		1530723.3382758598,
    		488873539.79825222,
    		2593536476.8396912,
    		1537176.5741878599,
    		488872778.97025216,
    		2593537158.8458276,
    		1537631.4906388598,
    		488871547.92468858,
    		2593538262.3549366,
    		1537893.3382758598,
    		488871131.50972319,
    		2593538635.6292658,
    		1537864.0304158598,
    		488870719.65708733,
    		2593539004.8139238,
    		1537776.4279398597
    	]
    }



    Answer Verified By: Rick cheng