Obj: prepare unittest and add missing tests for mesh comparison in
Modeldiffer.pull/1005/head
parent
61419cc0ae
commit
2e943e5443
|
@ -76,6 +76,9 @@ SET( TEST_SRCS
|
||||||
unit/utMaterialSystem.cpp
|
unit/utMaterialSystem.cpp
|
||||||
unit/utMatrix3x3.cpp
|
unit/utMatrix3x3.cpp
|
||||||
unit/utMatrix4x4.cpp
|
unit/utMatrix4x4.cpp
|
||||||
|
unit/ModelDiffer.h
|
||||||
|
unit/ModelDiffer.cpp
|
||||||
|
unit/utObjImportExport.cpp
|
||||||
unit/utPretransformVertices.cpp
|
unit/utPretransformVertices.cpp
|
||||||
unit/utRemoveComments.cpp
|
unit/utRemoveComments.cpp
|
||||||
unit/utRemoveComponent.cpp
|
unit/utRemoveComponent.cpp
|
||||||
|
|
|
@ -40,6 +40,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
#include "ModelDiffer.h"
|
#include "ModelDiffer.h"
|
||||||
#include <assimp/scene.h>
|
#include <assimp/scene.h>
|
||||||
|
#include <assimp/mesh.h>
|
||||||
|
#include <assimp/material.h>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
using namespace Assimp;
|
using namespace Assimp;
|
||||||
|
@ -65,17 +67,42 @@ bool ModelDiffer::isEqual( aiScene *expected, aiScene *toCompare ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// meshes
|
||||||
if ( expected->mNumMeshes != toCompare->mNumMeshes ) {
|
if ( expected->mNumMeshes != toCompare->mNumMeshes ) {
|
||||||
std::stringstream stream;
|
std::stringstream stream;
|
||||||
stream << "Number of meshes not equal ( expected: " << expected->mNumMeshes << ", found : " << toCompare->mNumMeshes << " )\n";
|
stream << "Number of meshes not equal ( expected: " << expected->mNumMeshes << ", found : " << toCompare->mNumMeshes << " )\n";
|
||||||
addDiff( stream.str() );
|
addDiff( stream.str() );
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( unsigned int i = 0; i < expected->mNumMeshes; i++ ) {
|
for ( unsigned int i = 0; i < expected->mNumMeshes; i++ ) {
|
||||||
aiMesh *expMesh( expected->mMeshes[ i ] );
|
aiMesh *expMesh( expected->mMeshes[ i ] );
|
||||||
aiMesh *toCompMesh( toCompare->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() {
|
void ModelDiffer::showReport() {
|
||||||
|
@ -241,7 +268,7 @@ bool ModelDiffer::compareMesh( aiMesh *expected, aiMesh *toCompare ) {
|
||||||
aiVector3D &toCompBiTangents( toCompare->mBitangents[ i ] );
|
aiVector3D &toCompBiTangents( toCompare->mBitangents[ i ] );
|
||||||
if ( expBiTangents != toCompBiTangents ) {
|
if ( expBiTangents != toCompBiTangents ) {
|
||||||
std::stringstream stream;
|
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() );
|
addDiff( stream.str() );
|
||||||
tangentsEqual = false;
|
tangentsEqual = false;
|
||||||
}
|
}
|
||||||
|
@ -250,5 +277,64 @@ bool ModelDiffer::compareMesh( aiMesh *expected, aiMesh *toCompare ) {
|
||||||
return 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;
|
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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -47,6 +47,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
struct aiScene;
|
struct aiScene;
|
||||||
struct aiMesh;
|
struct aiMesh;
|
||||||
|
struct aiMaterial;
|
||||||
|
struct aiFace;
|
||||||
|
|
||||||
class ModelDiffer {
|
class ModelDiffer {
|
||||||
public:
|
public:
|
||||||
|
@ -56,9 +58,11 @@ public:
|
||||||
void showReport();
|
void showReport();
|
||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
void addDiff( const std::string &diff );
|
void addDiff( const std::string &diff );
|
||||||
bool compareMesh( aiMesh *expected, aiMesh *toCompare );
|
bool compareMesh( aiMesh *expected, aiMesh *toCompare );
|
||||||
|
bool compareFace( aiFace *expected, aiFace *toCompare );
|
||||||
|
bool compareMaterial( aiMaterial *expected, aiMaterial *toCompare );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<std::string> m_diffs;
|
std::vector<std::string> m_diffs;
|
||||||
|
|
|
@ -0,0 +1,81 @@
|
||||||
|
/*
|
||||||
|
---------------------------------------------------------------------------
|
||||||
|
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 );
|
||||||
|
}
|
Loading…
Reference in New Issue