Modeldiffer.
unit/utMaterialSystem.cpp
unit/utMatrix3x3.cpp
unit/utMatrix4x4.cpp
+ unit/ModelDiffer.h
+ unit/ModelDiffer.cpp
+ unit/utObjImportExport.cpp
unit/utPretransformVertices.cpp
unit/utRemoveComments.cpp
unit/utRemoveComponent.cpp
*/
#include "ModelDiffer.h"
#include <assimp/scene.h>
+#include <assimp/mesh.h>
+#include <assimp/material.h>
#include <sstream>
using namespace Assimp;
return false;
}
+ // meshes
if ( expected->mNumMeshes != toCompare->mNumMeshes ) {
std::stringstream stream;
stream << "Number of meshes not equal ( expected: " << expected->mNumMeshes << ", found : " << toCompare->mNumMeshes << " )\n";
addDiff( stream.str() );
+ return false;
}
for ( unsigned int i = 0; i < expected->mNumMeshes; i++ ) {
aiMesh *expMesh( expected->mMeshes[ i ] );
aiMesh *toCompMesh( toCompare->mMeshes[ i ] );
- compareMesh( expMesh, toCompMesh );
+ if ( !compareMesh( expMesh, toCompMesh ) ) {
+ std::stringstream stream;
+ stream << "Meshes are not equal, index : " << i << "\n";
+ addDiff( stream.str() );
+ }
+ }
+
+ // materials
+ if ( expected->mNumMaterials != toCompare->mNumMaterials ) {
+ std::stringstream stream;
+ stream << "Number of materials not equal ( expected: " << expected->mNumMaterials << ", found : " << toCompare->mNumMaterials << " )\n";
+ addDiff( stream.str() );
+ return false;
}
+ for ( unsigned int i = 0; i < expected->mNumMaterials; i++ ) {
+ aiMaterial *expectedMat( expected->mMaterials[ i ] );
+ aiMaterial *toCompareMat( expected->mMaterials[ i ] );
+ if ( !compareMaterial( expectedMat, toCompareMat ) ) {
+ std::stringstream stream;
+ stream << "Materials are not equal, index : " << i << "\n";
+ addDiff( stream.str() );
+ }
+ }
+
+ return true;
}
void ModelDiffer::showReport() {
aiVector3D &toCompBiTangents( toCompare->mBitangents[ i ] );
if ( expBiTangents != toCompBiTangents ) {
std::stringstream stream;
- stream << "Tangents not equal ( expected: " << dumpVector3( expBiTangents ) << ", found: " << dumpVector3( toCompBiTangents ) << "\n";
+ stream << "Tangents not equal ( expected: " << dumpVector3( expBiTangents ) << ", found: " << dumpVector3( toCompBiTangents ) << " )\n";
addDiff( stream.str() );
tangentsEqual = false;
}
return false;
}
+ // faces
+ if ( expected->mNumFaces != toCompare->mNumFaces ) {
+ std::stringstream stream;
+ stream << "Number of faces are not equal, ( expected: " << expected->mNumFaces << ", found: " << toCompare->mNumFaces << ")\n";
+ addDiff( stream.str() );
+ return false;
+ }
+ bool facesEqual( true );
+ for ( unsigned int i = 0; i < expected->mNumFaces; i++ ) {
+ aiFace &expFace( expected->mFaces[ i ] );
+ aiFace &toCompareFace( expected->mFaces[ i ] );
+ if ( !compareFace( &expFace, &toCompareFace ) ) {
+ facesEqual = false;
+ }
+ }
+ if ( !facesEqual ) {
+ return false;
+ }
+
+ return true;
+}
+
+bool ModelDiffer::compareFace( aiFace *expected, aiFace *toCompare ) {
+ if ( nullptr == expected ) {
+ return false;
+ }
+ if ( nullptr == toCompare ) {
+ return false;
+ }
+
+ // same instance
+ if ( expected == toCompare ) {
+ return true;
+ }
+
+ // using compare operator
+ if ( *expected == *toCompare ) {
+ return true;
+ }
+
+ return false;
+}
+
+bool ModelDiffer::compareMaterial( aiMaterial *expected, aiMaterial *toCompare ) {
+ if ( nullptr == expected ) {
+ return false;
+ }
+ if ( nullptr == toCompare ) {
+ return false;
+ }
+
+ // same instance
+ if ( expected == toCompare ) {
+ return true;
+ }
+
+ // todo!
+
return true;
+
}
struct aiScene;
struct aiMesh;
+struct aiMaterial;
+struct aiFace;
class ModelDiffer {
public:
void showReport();
void reset();
-private:
+protected:
void addDiff( const std::string &diff );
bool compareMesh( aiMesh *expected, aiMesh *toCompare );
+ bool compareFace( aiFace *expected, aiFace *toCompare );
+ bool compareMaterial( aiMaterial *expected, aiMaterial *toCompare );
private:
std::vector<std::string> m_diffs;
--- /dev/null
+/*
+---------------------------------------------------------------------------
+Open Asset Import Library (assimp)
+---------------------------------------------------------------------------
+
+Copyright (c) 2006-2016, assimp team
+
+All rights reserved.
+
+Redistribution and use of this software in source and binary forms,
+with or without modification, are permitted provided that the following
+conditions are met:
+
+* Redistributions of source code must retain the above
+copyright notice, this list of conditions and the
+following disclaimer.
+
+* Redistributions in binary form must reproduce the above
+copyright notice, this list of conditions and the
+following disclaimer in the documentation and/or other
+materials provided with the distribution.
+
+* Neither the name of the assimp team, nor the names of its
+contributors may be used to endorse or promote products
+derived from this software without specific prior
+written permission of the assimp team.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+---------------------------------------------------------------------------
+*/
+
+#include "UnitTestPCH.h"
+#include "ModelDiffer.h"
+#include <assimp/Importer.hpp>
+using namespace Assimp;
+
+class utObjImportExport : public ::testing::Test {
+ // empty
+};
+
+static const std::string ObjModel =
+ "o 1\n"
+ "\n"
+ "# Vertex list\n"
+ "\n"
+ "v -0.5 -0.5 0.5\n"
+ "v -0.5 -0.5 -0.5\n"
+ "v -0.5 0.5 -0.5\n"
+ "v -0.5 0.5 0.5\n"
+ "v 0.5 -0.5 0.5\n"
+ "v 0.5 -0.5 -0.5\n"
+ "v 0.5 0.5 -0.5\n"
+ "v 0.5 0.5 0.5\n"
+ "\n"
+ "# Point / Line / Face list\n"
+ "\n"
+ "usemtl Default\n"
+ "f 4 3 2 1\n"
+ "f 2 6 5 1\n"
+ "f 3 7 6 2\n"
+ "f 8 7 3 4\n"
+ "f 5 8 4 1\n"
+ "f 6 7 8 5\n"
+ "\n"
+ "# End of file\n";
+
+TEST_F( utObjImportExport, obj_import_test ) {
+ Assimp::Importer im;
+ const aiScene *scene = im.ReadFileFromMemory( (void*) ObjModel.c_str(), ObjModel.size(), 0 );
+ EXPECT_NE( nullptr, scene );
+}