From 3aa1bdfd12e25f76bb6f7690398c75e7ec73aebc Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Mon, 26 Sep 2016 20:53:42 +0200 Subject: [PATCH] SceneDiffer: add face tester. --- test/unit/SceneDiffer.cpp | 24 +++++++++++++++++---- test/unit/utObjImportExport.cpp | 46 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 65 insertions(+), 5 deletions(-) diff --git a/test/unit/SceneDiffer.cpp b/test/unit/SceneDiffer.cpp index 0858c30..395ab77 100644 --- a/test/unit/SceneDiffer.cpp +++ b/test/unit/SceneDiffer.cpp @@ -150,6 +150,19 @@ static std::string dumpColor4D( const aiColor4D &toDump ) { return stream.str(); } +static std::string dumpFace( const aiFace &face ) { + std::stringstream stream; + for ( unsigned int i = 0; i < face.mNumIndices; i++ ) { + stream << face.mIndices[ i ]; + if ( i < face.mNumIndices - 1 ) { + stream << ", "; + } else { + stream << "\n"; + } + } + return stream.str(); +} + bool SceneDiffer::compareMesh( aiMesh *expected, aiMesh *toCompare ) { if ( expected == toCompare ) { return true; @@ -200,11 +213,11 @@ bool SceneDiffer::compareMesh( aiMesh *expected, aiMesh *toCompare ) { return false; } - return true; +// return true; //ToDo! bool normalEqual( true ); - for ( unsigned int i = 0; i < expected->mNumVertices; i++ ) { +/* for ( unsigned int i = 0; i < expected->mNumVertices; i++ ) { aiVector3D &expNormal( expected->mNormals[ i ] ); aiVector3D &toCompNormal( toCompare->mNormals[ i ] ); if ( expNormal.Equal( toCompNormal ) ) { @@ -289,7 +302,7 @@ bool SceneDiffer::compareMesh( aiMesh *expected, aiMesh *toCompare ) { } if ( !tangentsEqual ) { return false; - } + }*/ // faces if ( expected->mNumFaces != toCompare->mNumFaces ) { @@ -301,8 +314,11 @@ bool SceneDiffer::compareMesh( aiMesh *expected, aiMesh *toCompare ) { bool facesEqual( true ); for ( unsigned int i = 0; i < expected->mNumFaces; i++ ) { aiFace &expFace( expected->mFaces[ i ] ); - aiFace &toCompareFace( expected->mFaces[ i ] ); + aiFace &toCompareFace( toCompare->mFaces[ i ] ); if ( !compareFace( &expFace, &toCompareFace ) ) { + addDiff( "Faces are not equal\n" ); + addDiff( dumpFace( expFace ) ); + addDiff( dumpFace( toCompareFace ) ); facesEqual = false; } } diff --git a/test/unit/utObjImportExport.cpp b/test/unit/utObjImportExport.cpp index 14fc6b0..44b0a6e 100644 --- a/test/unit/utObjImportExport.cpp +++ b/test/unit/utObjImportExport.cpp @@ -120,7 +120,51 @@ protected: mesh->mNumVertices = 24; mesh->mVertices = new aiVector3D[ 24 ]; ::memcpy( &mesh->mVertices->x, &VertComponents[ 0 ], sizeof( float ) * 24 * 3 ); - mesh->mNumFaces = 12; + mesh->mNumFaces = 6; + mesh->mFaces = new aiFace[ mesh->mNumFaces ]; + + mesh->mFaces[ 0 ].mNumIndices = 4; + mesh->mFaces[ 0 ].mIndices = new unsigned int[ mesh->mFaces[ 0 ].mNumIndices ]; + mesh->mFaces[ 0 ].mIndices[ 0 ] = 0; + mesh->mFaces[ 0 ].mIndices[ 1 ] = 1; + mesh->mFaces[ 0 ].mIndices[ 2 ] = 2; + mesh->mFaces[ 0 ].mIndices[ 3 ] = 3; + + mesh->mFaces[ 1 ].mNumIndices = 4; + mesh->mFaces[ 1 ].mIndices = new unsigned int[ mesh->mFaces[ 0 ].mNumIndices ]; + mesh->mFaces[ 1 ].mIndices[ 0 ] = 4; + mesh->mFaces[ 1 ].mIndices[ 1 ] = 5; + mesh->mFaces[ 1 ].mIndices[ 2 ] = 6; + mesh->mFaces[ 1 ].mIndices[ 3 ] = 7; + + mesh->mFaces[ 2 ].mNumIndices = 4; + mesh->mFaces[ 2 ].mIndices = new unsigned int[ mesh->mFaces[ 0 ].mNumIndices ]; + mesh->mFaces[ 2 ].mIndices[ 0 ] = 8; + mesh->mFaces[ 2 ].mIndices[ 1 ] = 9; + mesh->mFaces[ 2 ].mIndices[ 2 ] = 10; + mesh->mFaces[ 2 ].mIndices[ 3 ] = 11; + + mesh->mFaces[ 3 ].mNumIndices = 4; + mesh->mFaces[ 3 ].mIndices = new unsigned int[ mesh->mFaces[ 0 ].mNumIndices ]; + mesh->mFaces[ 3 ].mIndices[ 0 ] = 12; + mesh->mFaces[ 3 ].mIndices[ 1 ] = 13; + mesh->mFaces[ 3 ].mIndices[ 2 ] = 14; + mesh->mFaces[ 3 ].mIndices[ 3 ] = 15; + + mesh->mFaces[ 4 ].mNumIndices = 4; + mesh->mFaces[ 4 ].mIndices = new unsigned int[ mesh->mFaces[ 0 ].mNumIndices ]; + mesh->mFaces[ 4 ].mIndices[ 0 ] = 16; + mesh->mFaces[ 4 ].mIndices[ 1 ] = 17; + mesh->mFaces[ 4 ].mIndices[ 2 ] = 18; + mesh->mFaces[ 4 ].mIndices[ 3 ] = 19; + + mesh->mFaces[ 5 ].mNumIndices = 4; + mesh->mFaces[ 5 ].mIndices = new unsigned int[ mesh->mFaces[ 0 ].mNumIndices ]; + mesh->mFaces[ 5 ].mIndices[ 0 ] = 20; + mesh->mFaces[ 5 ].mIndices[ 1 ] = 21; + mesh->mFaces[ 5 ].mIndices[ 2 ] = 22; + mesh->mFaces[ 5 ].mIndices[ 3 ] = 23; + expScene->mMeshes[ 0 ] = mesh; expScene->mNumMaterials = 1; -- 2.7.4