2016-09-19 19:35:45 +00:00
|
|
|
/*
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
Open Asset Import Library (assimp)
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
2021-02-28 11:17:54 +00:00
|
|
|
Copyright (c) 2006-2021, assimp team
|
2018-01-28 18:42:05 +00:00
|
|
|
|
2017-05-09 17:57:36 +00:00
|
|
|
|
2016-09-19 19:35:45 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
*/
|
2016-09-23 08:22:14 +00:00
|
|
|
#include "SceneDiffer.h"
|
2016-09-19 19:35:45 +00:00
|
|
|
#include <assimp/scene.h>
|
2016-09-20 09:27:58 +00:00
|
|
|
#include <assimp/mesh.h>
|
|
|
|
#include <assimp/material.h>
|
2016-09-19 19:35:45 +00:00
|
|
|
#include <sstream>
|
|
|
|
|
2016-12-01 09:29:39 +00:00
|
|
|
namespace Assimp {
|
2016-09-19 19:35:45 +00:00
|
|
|
|
2021-09-07 13:04:08 +00:00
|
|
|
SceneDiffer::SceneDiffer()
|
2016-12-01 09:29:39 +00:00
|
|
|
: m_diffs() {
|
2016-09-19 19:35:45 +00:00
|
|
|
// empty
|
|
|
|
}
|
|
|
|
|
2016-09-23 08:22:14 +00:00
|
|
|
SceneDiffer::~SceneDiffer() {
|
2016-09-19 19:35:45 +00:00
|
|
|
// empty
|
|
|
|
}
|
|
|
|
|
2016-09-23 08:22:14 +00:00
|
|
|
bool SceneDiffer::isEqual( const aiScene *expected, const aiScene *toCompare ) {
|
2016-09-19 19:35:45 +00:00
|
|
|
if ( expected == toCompare ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( nullptr == expected ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( nullptr == toCompare ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-09-20 09:27:58 +00:00
|
|
|
// meshes
|
2016-09-19 19:35:45 +00:00
|
|
|
if ( expected->mNumMeshes != toCompare->mNumMeshes ) {
|
|
|
|
std::stringstream stream;
|
|
|
|
stream << "Number of meshes not equal ( expected: " << expected->mNumMeshes << ", found : " << toCompare->mNumMeshes << " )\n";
|
|
|
|
addDiff( stream.str() );
|
2016-09-20 09:27:58 +00:00
|
|
|
return false;
|
2016-09-19 19:35:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for ( unsigned int i = 0; i < expected->mNumMeshes; i++ ) {
|
|
|
|
aiMesh *expMesh( expected->mMeshes[ i ] );
|
|
|
|
aiMesh *toCompMesh( toCompare->mMeshes[ i ] );
|
2016-09-20 09:27:58 +00:00
|
|
|
if ( !compareMesh( expMesh, toCompMesh ) ) {
|
|
|
|
std::stringstream stream;
|
|
|
|
stream << "Meshes are not equal, index : " << i << "\n";
|
|
|
|
addDiff( stream.str() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// materials
|
2020-03-13 16:00:14 +00:00
|
|
|
/*if ( expected->mNumMaterials != toCompare->mNumMaterials ) {
|
2016-09-20 09:27:58 +00:00
|
|
|
std::stringstream stream;
|
|
|
|
stream << "Number of materials not equal ( expected: " << expected->mNumMaterials << ", found : " << toCompare->mNumMaterials << " )\n";
|
|
|
|
addDiff( stream.str() );
|
|
|
|
return false;
|
2016-09-19 19:35:45 +00:00
|
|
|
}
|
2016-12-01 09:29:39 +00:00
|
|
|
|
2016-09-23 08:10:00 +00:00
|
|
|
if ( expected->mNumMaterials > 0 ) {
|
|
|
|
if ( nullptr == expected->mMaterials || nullptr == toCompare->mMaterials ) {
|
|
|
|
addDiff( "Number of materials > 0 and mat pointer is nullptr" );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2016-12-01 09:29:39 +00:00
|
|
|
|
2016-09-20 09:27:58 +00:00
|
|
|
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() );
|
2020-03-11 08:43:55 +00:00
|
|
|
return false;
|
2016-09-20 09:27:58 +00:00
|
|
|
}
|
2020-03-13 16:00:14 +00:00
|
|
|
}*/
|
2016-09-20 09:27:58 +00:00
|
|
|
|
|
|
|
return true;
|
2016-09-19 19:35:45 +00:00
|
|
|
}
|
|
|
|
|
2016-09-23 08:22:14 +00:00
|
|
|
void SceneDiffer::showReport() {
|
2016-09-19 19:35:45 +00:00
|
|
|
if ( m_diffs.empty() ) {
|
|
|
|
return;
|
|
|
|
}
|
2016-12-01 09:29:39 +00:00
|
|
|
|
2019-09-03 06:01:56 +00:00
|
|
|
for ( std::vector<std::string>::iterator it = m_diffs.begin(); it != m_diffs.end(); ++it ) {
|
2016-09-19 19:35:45 +00:00
|
|
|
std::cout << *it << "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cout << std::endl;
|
|
|
|
}
|
|
|
|
|
2016-09-23 08:22:14 +00:00
|
|
|
void SceneDiffer::reset() {
|
2016-09-19 19:35:45 +00:00
|
|
|
m_diffs.resize( 0 );
|
|
|
|
}
|
|
|
|
|
2016-09-23 08:22:14 +00:00
|
|
|
void SceneDiffer::addDiff( const std::string &diff ) {
|
2016-09-19 19:35:45 +00:00
|
|
|
if ( diff.empty() ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_diffs.push_back( diff );
|
|
|
|
}
|
|
|
|
|
|
|
|
static std::string dumpVector3( const aiVector3D &toDump ) {
|
|
|
|
std::stringstream stream;
|
|
|
|
stream << "( " << toDump.x << ", " << toDump.y << ", " << toDump.z << ")";
|
|
|
|
return stream.str();
|
|
|
|
}
|
|
|
|
|
2016-12-31 15:14:06 +00:00
|
|
|
/*static std::string dumpColor4D( const aiColor4D &toDump ) {
|
2016-09-19 19:35:45 +00:00
|
|
|
std::stringstream stream;
|
|
|
|
stream << "( " << toDump.r << ", " << toDump.g << ", " << toDump.b << ", " << toDump.a << ")";
|
|
|
|
return stream.str();
|
2016-12-31 15:14:06 +00:00
|
|
|
}*/
|
2016-09-19 19:35:45 +00:00
|
|
|
|
2016-09-26 18:53:42 +00:00
|
|
|
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 << ", ";
|
2016-12-01 09:29:39 +00:00
|
|
|
}
|
|
|
|
else {
|
2016-09-26 18:53:42 +00:00
|
|
|
stream << "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return stream.str();
|
|
|
|
}
|
|
|
|
|
2016-09-23 08:22:14 +00:00
|
|
|
bool SceneDiffer::compareMesh( aiMesh *expected, aiMesh *toCompare ) {
|
2016-09-19 19:35:45 +00:00
|
|
|
if ( expected == toCompare ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( nullptr == expected || nullptr == toCompare ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( expected->mName != toCompare->mName ) {
|
|
|
|
std::stringstream stream;
|
|
|
|
stream << "Mesh name not equal ( expected: " << expected->mName.C_Str() << ", found : " << toCompare->mName.C_Str() << " )\n";
|
|
|
|
addDiff( stream.str() );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( expected->mNumVertices != toCompare->mNumVertices ) {
|
|
|
|
std::stringstream stream;
|
|
|
|
stream << "Number of vertices not equal ( expected: " << expected->mNumVertices << ", found : " << toCompare->mNumVertices << " )\n";
|
|
|
|
addDiff( stream.str() );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// positions
|
|
|
|
if ( expected->HasPositions() != toCompare->HasPositions() ) {
|
|
|
|
addDiff( "Expected are vertices, toCompare does not have any." );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool vertEqual( true );
|
|
|
|
for ( unsigned int i = 0; i < expected->mNumVertices; i++ ) {
|
|
|
|
aiVector3D &expVert( expected->mVertices[ i ] );
|
|
|
|
aiVector3D &toCompVert( toCompare->mVertices[ i ] );
|
2016-09-22 07:15:41 +00:00
|
|
|
if ( !expVert.Equal( toCompVert ) ) {
|
|
|
|
std::cout << "index = " << i << dumpVector3( toCompVert ) << "\n";
|
2016-09-19 19:35:45 +00:00
|
|
|
std::stringstream stream;
|
2016-09-22 07:15:41 +00:00
|
|
|
stream << "Vertex not equal ( expected: " << dumpVector3( toCompVert ) << ", found: " << dumpVector3( toCompVert ) << "\n";
|
2016-09-19 19:35:45 +00:00
|
|
|
addDiff( stream.str() );
|
|
|
|
vertEqual = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( !vertEqual ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// normals
|
|
|
|
if ( expected->HasNormals() != toCompare->HasNormals() ) {
|
|
|
|
addDiff( "Expected are normals, toCompare does not have any." );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-12-01 09:29:39 +00:00
|
|
|
// return true;
|
2016-09-19 19:35:45 +00:00
|
|
|
|
2016-12-01 09:29:39 +00:00
|
|
|
//ToDo!
|
2016-12-31 15:14:06 +00:00
|
|
|
/*bool normalEqual( true );
|
|
|
|
for ( unsigned int i = 0; i < expected->mNumVertices; i++ ) {
|
2016-12-01 09:29:39 +00:00
|
|
|
aiVector3D &expNormal( expected->mNormals[ i ] );
|
|
|
|
aiVector3D &toCompNormal( toCompare->mNormals[ i ] );
|
|
|
|
if ( expNormal.Equal( toCompNormal ) ) {
|
2016-09-19 19:35:45 +00:00
|
|
|
std::stringstream stream;
|
2016-12-01 09:29:39 +00:00
|
|
|
stream << "Normal not equal ( expected: " << dumpVector3( expNormal ) << ", found: " << dumpVector3( toCompNormal ) << "\n";
|
2016-09-19 19:35:45 +00:00
|
|
|
addDiff( stream.str() );
|
2016-12-01 09:29:39 +00:00
|
|
|
normalEqual = false;
|
2016-09-19 19:35:45 +00:00
|
|
|
}
|
|
|
|
}
|
2016-12-01 09:29:39 +00:00
|
|
|
if ( !normalEqual ) {
|
2016-09-19 19:35:45 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-12-01 09:29:39 +00:00
|
|
|
// vertex colors
|
|
|
|
bool vertColEqual( true );
|
|
|
|
for ( unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; a++ ) {
|
|
|
|
if ( expected->HasVertexColors(a) != toCompare->HasVertexColors(a) ) {
|
|
|
|
addDiff( "Expected are normals, toCompare does not have any." );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
for ( unsigned int i = 0; i < expected->mNumVertices; i++ ) {
|
|
|
|
aiColor4D &expColor4D( expected->mColors[ a ][ i ] );
|
|
|
|
aiColor4D &toCompColor4D( toCompare->mColors[ a ][ i ] );
|
|
|
|
if ( expColor4D != toCompColor4D ) {
|
|
|
|
std::stringstream stream;
|
|
|
|
stream << "Color4D not equal ( expected: " << dumpColor4D( expColor4D ) << ", found: " << dumpColor4D( toCompColor4D ) << "\n";
|
|
|
|
addDiff( stream.str() );
|
|
|
|
vertColEqual = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( !vertColEqual ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// texture coords
|
|
|
|
bool texCoordsEqual( true );
|
|
|
|
for ( unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; a++ ) {
|
|
|
|
if ( expected->HasTextureCoords( a ) != toCompare->HasTextureCoords( a ) ) {
|
|
|
|
addDiff( "Expected are texture coords, toCompare does not have any." );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
for ( unsigned int i = 0; i < expected->mNumVertices; i++ ) {
|
|
|
|
aiVector3D &expTexCoord( expected->mTextureCoords[ a ][ i ] );
|
|
|
|
aiVector3D &toCompTexCoord( toCompare->mTextureCoords[ a ][ i ] );
|
|
|
|
if ( expTexCoord.Equal( toCompTexCoord ) ) {
|
|
|
|
std::stringstream stream;
|
|
|
|
stream << "Texture coords not equal ( expected: " << dumpVector3( expTexCoord ) << ", found: " << dumpVector3( toCompTexCoord ) << "\n";
|
|
|
|
addDiff( stream.str() );
|
|
|
|
vertColEqual = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( !vertColEqual ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// tangents and bi-tangents
|
|
|
|
if ( expected->HasTangentsAndBitangents() != toCompare->HasTangentsAndBitangents() ) {
|
|
|
|
addDiff( "Expected are tangents and bi-tangents, toCompare does not have any." );
|
2016-09-19 19:35:45 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-12-01 09:29:39 +00:00
|
|
|
bool tangentsEqual( true );
|
2016-09-19 19:35:45 +00:00
|
|
|
for ( unsigned int i = 0; i < expected->mNumVertices; i++ ) {
|
2016-12-01 09:29:39 +00:00
|
|
|
aiVector3D &expTangents( expected->mTangents[ i ] );
|
|
|
|
aiVector3D &toCompTangents( toCompare->mTangents[ i ] );
|
|
|
|
if ( expTangents.Equal( toCompTangents ) ) {
|
2016-09-19 19:35:45 +00:00
|
|
|
std::stringstream stream;
|
2016-12-01 09:29:39 +00:00
|
|
|
stream << "Tangents not equal ( expected: " << dumpVector3( expTangents ) << ", found: " << dumpVector3( toCompTangents ) << "\n";
|
2016-09-19 19:35:45 +00:00
|
|
|
addDiff( stream.str() );
|
2016-12-01 09:29:39 +00:00
|
|
|
tangentsEqual = false;
|
2016-09-19 19:35:45 +00:00
|
|
|
}
|
|
|
|
|
2016-12-01 09:29:39 +00:00
|
|
|
aiVector3D &expBiTangents( expected->mBitangents[ i ] );
|
|
|
|
aiVector3D &toCompBiTangents( toCompare->mBitangents[ i ] );
|
|
|
|
if ( expBiTangents.Equal( toCompBiTangents ) ) {
|
|
|
|
std::stringstream stream;
|
|
|
|
stream << "Tangents not equal ( expected: " << dumpVector3( expBiTangents ) << ", found: " << dumpVector3( toCompBiTangents ) << " )\n";
|
|
|
|
addDiff( stream.str() );
|
|
|
|
tangentsEqual = false;
|
|
|
|
}
|
2016-09-19 19:35:45 +00:00
|
|
|
}
|
2016-12-01 09:29:39 +00:00
|
|
|
if ( !tangentsEqual ) {
|
|
|
|
return false;
|
|
|
|
}*/
|
2016-09-19 19:35:45 +00:00
|
|
|
|
2016-12-01 09:29:39 +00:00
|
|
|
// faces
|
2016-09-20 09:27:58 +00:00
|
|
|
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 ] );
|
2016-09-26 18:53:42 +00:00
|
|
|
aiFace &toCompareFace( toCompare->mFaces[ i ] );
|
2016-09-20 09:27:58 +00:00
|
|
|
if ( !compareFace( &expFace, &toCompareFace ) ) {
|
2016-09-26 18:53:42 +00:00
|
|
|
addDiff( "Faces are not equal\n" );
|
|
|
|
addDiff( dumpFace( expFace ) );
|
|
|
|
addDiff( dumpFace( toCompareFace ) );
|
2016-09-20 09:27:58 +00:00
|
|
|
facesEqual = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( !facesEqual ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-09-23 08:22:14 +00:00
|
|
|
bool SceneDiffer::compareFace( aiFace *expected, aiFace *toCompare ) {
|
2016-09-20 09:27:58 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-09-23 08:22:14 +00:00
|
|
|
bool SceneDiffer::compareMaterial( aiMaterial *expected, aiMaterial *toCompare ) {
|
2016-09-20 09:27:58 +00:00
|
|
|
if ( nullptr == expected ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if ( nullptr == toCompare ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// same instance
|
|
|
|
if ( expected == toCompare ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// todo!
|
|
|
|
|
2016-09-19 19:35:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
2016-12-01 09:29:39 +00:00
|
|
|
|
2016-12-31 15:14:06 +00:00
|
|
|
}
|