MCPcopy Create free account
hub / github.com/assimp/assimp / TriangulateMesh

Method TriangulateMesh

code/PostProcessing/TriangulateProcess.cpp:206–505  ·  view source on GitHub ↗

------------------------------------------------------------------------------------------------ Triangulates the given mesh.

Source from the content-addressed store, hash-verified

204// ------------------------------------------------------------------------------------------------
205// Triangulates the given mesh.
206bool TriangulateProcess::TriangulateMesh( aiMesh* pMesh) {
207 // Now we have aiMesh::mPrimitiveTypes, so this is only here for test cases
208 if (!pMesh->mPrimitiveTypes) {
209 bool bNeed = false;
210
211 for( unsigned int a = 0; a < pMesh->mNumFaces; a++) {
212 const aiFace& face = pMesh->mFaces[a];
213 if( face.mNumIndices != 3) {
214 bNeed = true;
215 }
216 }
217 if (!bNeed) {
218 return false;
219 }
220 }
221 else if (!(pMesh->mPrimitiveTypes & aiPrimitiveType_POLYGON)) {
222 return false;
223 }
224
225 // Find out how many output faces we'll get
226 uint32_t numOut = 0, max_out = 0;
227 bool get_normals = true;
228 for( unsigned int a = 0; a < pMesh->mNumFaces; a++) {
229 aiFace& face = pMesh->mFaces[a];
230 if (face.mNumIndices <= 4) {
231 get_normals = false;
232 }
233 if( face.mNumIndices <= 3) {
234 ++numOut;
235 } else {
236 numOut += face.mNumIndices-2;
237 max_out = std::max<uint32_t>(max_out,face.mNumIndices);
238 }
239 }
240
241 // Just another check whether aiMesh::mPrimitiveTypes is correct
242 if (numOut == pMesh->mNumFaces) {
243 ASSIMP_LOG_ERROR( "Invalidation detected in the number of indices: does not fit to the primitive type." );
244 return false;
245 }
246
247 aiVector3D *nor_out = nullptr;
248
249 // if we don't have normals yet, but expect them to be a cheap side
250 // product of triangulation anyway, allocate storage for them.
251 if (!pMesh->mNormals && get_normals) {
252 // XXX need a mechanism to inform the GenVertexNormals process to treat these normals as preprocessed per-face normals
253 // nor_out = pMesh->mNormals = new aiVector3D[pMesh->mNumVertices];
254 }
255
256 // the output mesh will contain triangles, but no polys anymore
257 pMesh->mPrimitiveTypes |= aiPrimitiveType_TRIANGLE;
258 pMesh->mPrimitiveTypes &= ~aiPrimitiveType_POLYGON;
259
260 // The mesh becomes NGON encoded now, during the triangulation process.
261 pMesh->mPrimitiveTypes |= aiPrimitiveType_NGONEncodingFlag;
262
263 aiFace* out = new aiFace[numOut](), *curOut = out;

Callers 1

TEST_FFunction · 0.80

Calls 11

earcutFunction · 0.85
ArrayBoundsFunction · 0.85
ai_snprintfFunction · 0.85
ngonEncodeTriangleMethod · 0.80
ngonEncodeQuadMethod · 0.80
swapFunction · 0.50
reserveMethod · 0.45
NormalizeMethod · 0.45
frontMethod · 0.45
resizeMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected