@@ -67,7 +67,7 @@ static constexpr aiImporterDesc desc = {
67
67
" obj"
68
68
};
69
69
70
- static const unsigned int ObjMinSize = 16 ;
70
+ static constexpr unsigned int ObjMinSize = 16u ;
71
71
72
72
namespace Assimp {
73
73
@@ -163,7 +163,7 @@ void ObjFileImporter::InternReadFile(const std::string &file, aiScene *pScene, I
163
163
// ------------------------------------------------------------------------------------------------
164
164
// Create the data from parsed obj-file
165
165
void ObjFileImporter::CreateDataFromImport (const ObjFile::Model *pModel, aiScene *pScene) {
166
- if (nullptr == pModel ) {
166
+ if (pModel == nullptr ) {
167
167
return ;
168
168
}
169
169
@@ -178,7 +178,6 @@ void ObjFileImporter::CreateDataFromImport(const ObjFile::Model *pModel, aiScene
178
178
}
179
179
180
180
if (!pModel->mObjects .empty ()) {
181
-
182
181
unsigned int meshCount = 0 ;
183
182
unsigned int childCount = 0 ;
184
183
@@ -258,8 +257,7 @@ void ObjFileImporter::CreateDataFromImport(const ObjFile::Model *pModel, aiScene
258
257
aiNode *ObjFileImporter::createNodes (const ObjFile::Model *pModel, const ObjFile::Object *pObject,
259
258
aiNode *pParent, aiScene *pScene,
260
259
std::vector<std::unique_ptr<aiMesh>> &MeshArray) {
261
- ai_assert (nullptr != pModel);
262
- if (nullptr == pObject) {
260
+ if (nullptr == pObject || pModel == nullptr ) {
263
261
return nullptr ;
264
262
}
265
263
@@ -311,16 +309,13 @@ aiNode *ObjFileImporter::createNodes(const ObjFile::Model *pModel, const ObjFile
311
309
// ------------------------------------------------------------------------------------------------
312
310
// Create topology data
313
311
std::unique_ptr<aiMesh> ObjFileImporter::createTopology (const ObjFile::Model *pModel, const ObjFile::Object *pData, unsigned int meshIndex) {
314
- // Checking preconditions
315
- ai_assert (nullptr != pModel);
316
-
317
- if (nullptr == pData) {
312
+ if (nullptr == pData || pModel == nullptr ) {
318
313
return nullptr ;
319
314
}
320
315
321
316
// Create faces
322
317
ObjFile::Mesh *pObjMesh = pModel->mMeshes [meshIndex];
323
- if (! pObjMesh) {
318
+ if (pObjMesh == nullptr ) {
324
319
return nullptr ;
325
320
}
326
321
@@ -335,7 +330,10 @@ std::unique_ptr<aiMesh> ObjFileImporter::createTopology(const ObjFile::Model *pM
335
330
336
331
for (size_t index = 0 ; index < pObjMesh->m_Faces .size (); index++) {
337
332
const ObjFile::Face *inp = pObjMesh->m_Faces [index];
338
-
333
+ if (inp == nullptr ) {
334
+ continue ;
335
+ }
336
+
339
337
if (inp->mPrimitiveType == aiPrimitiveType_LINE) {
340
338
pMesh->mNumFaces += static_cast <unsigned int >(inp->m_vertices .size () - 1 );
341
339
pMesh->mPrimitiveTypes |= aiPrimitiveType_LINE;
@@ -352,14 +350,14 @@ std::unique_ptr<aiMesh> ObjFileImporter::createTopology(const ObjFile::Model *pM
352
350
}
353
351
}
354
352
355
- unsigned int uiIdxCount ( 0u ) ;
353
+ unsigned int uiIdxCount = 0u ;
356
354
if (pMesh->mNumFaces > 0 ) {
357
355
pMesh->mFaces = new aiFace[pMesh->mNumFaces ];
358
356
if (pObjMesh->m_uiMaterialIndex != ObjFile::Mesh::NoMaterial) {
359
357
pMesh->mMaterialIndex = pObjMesh->m_uiMaterialIndex ;
360
358
}
361
359
362
- unsigned int outIndex ( 0 ) ;
360
+ unsigned int outIndex = 0u ;
363
361
364
362
// Copy all data from all stored meshes
365
363
for (auto &face : pObjMesh->m_Faces ) {
@@ -403,11 +401,14 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model *pModel,
403
401
aiMesh *pMesh,
404
402
unsigned int numIndices) {
405
403
// Checking preconditions
406
- ai_assert (nullptr != pCurrentObject);
404
+ if (pCurrentObject == nullptr ) {
405
+ return ;
406
+ }
407
407
408
408
// Break, if no faces are stored in object
409
- if (pCurrentObject->m_Meshes .empty ())
409
+ if (pCurrentObject->m_Meshes .empty ()) {
410
410
return ;
411
+ }
411
412
412
413
// Get current mesh
413
414
ObjFile::Mesh *pObjMesh = pModel->mMeshes [uiMeshIndex];
@@ -586,11 +587,12 @@ void ObjFileImporter::createMaterials(const ObjFile::Model *pModel, aiScene *pSc
586
587
it = pModel->mMaterialMap .find (pModel->mMaterialLib [matIndex]);
587
588
588
589
// No material found, use the default material
589
- if (pModel->mMaterialMap .end () == it)
590
+ if (pModel->mMaterialMap .end () == it) {
590
591
continue ;
592
+ }
591
593
592
594
aiMaterial *mat = new aiMaterial;
593
- ObjFile::Material *pCurrentMaterial = (*it). second ;
595
+ ObjFile::Material *pCurrentMaterial = it-> second ;
594
596
mat->AddProperty (&pCurrentMaterial->MaterialName , AI_MATKEY_NAME);
595
597
596
598
// convert illumination model
@@ -777,8 +779,11 @@ void ObjFileImporter::createMaterials(const ObjFile::Model *pModel, aiScene *pSc
777
779
// Appends this node to the parent node
778
780
void ObjFileImporter::appendChildToParentNode (aiNode *pParent, aiNode *pChild) {
779
781
// Checking preconditions
780
- ai_assert (nullptr != pParent);
781
- ai_assert (nullptr != pChild);
782
+ if (pParent == nullptr || pChild == nullptr ) {
783
+ ai_assert (nullptr != pParent);
784
+ ai_assert (nullptr != pChild);
785
+ return ;
786
+ }
782
787
783
788
// Assign parent to child
784
789
pChild->mParent = pParent;
0 commit comments