Merge branch 'master' into import_amf

pull/1011/head
Alexandr Arutjunov 2016-09-28 17:51:59 +03:00
commit 0a25b076b8
16 changed files with 5571 additions and 81 deletions

View File

@ -28,9 +28,11 @@ install:
- call c:\projects\assimp\scripts\appveyor\compiler_setup.bat - call c:\projects\assimp\scripts\appveyor\compiler_setup.bat
build_script: build_script:
- cd c:\projects\assimp - cd c:\projects\assimp
- cmake CMakeLists.txt -G "Visual Studio %Configuration%" - if "%platform%" equ "x64" (cmake CMakeLists.txt -G "Visual Studio %Configuration% Win64")
- msbuild /m /p:Configuration=Release /p:Platform="Win32" Assimp.sln - if "%platform%" equ "x86" (cmake CMakeLists.txt -G "Visual Studio %Configuration%")
- if "%platform%" equ "x64" (msbuild /m /p:Configuration=Release /p:Platform="x64" Assimp.sln)
- if "%platform%" equ "x86" (msbuild /m /p:Configuration=Release /p:Platform="Win32" Assimp.sln)
after_build: after_build:
- 7z a assimp.7z c:\projects\assimp\bin\release\* c:\projects\assimp\lib\release\* - 7z a assimp.7z c:\projects\assimp\bin\release\* c:\projects\assimp\lib\release\*

View File

@ -443,7 +443,8 @@ ADD_ASSIMP_IMPORTER( BLEND
ADD_ASSIMP_IMPORTER( IFC ADD_ASSIMP_IMPORTER( IFC
IFCLoader.cpp IFCLoader.cpp
IFCLoader.h IFCLoader.h
IFCReaderGen.cpp IFCReaderGen1.cpp
IFCReaderGen2.cpp
IFCReaderGen.h IFCReaderGen.h
IFCUtil.h IFCUtil.h
IFCUtil.cpp IFCUtil.cpp

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -50,6 +50,10 @@ OpenGEXExporter::OpenGEXExporter() {
OpenGEXExporter::~OpenGEXExporter() { OpenGEXExporter::~OpenGEXExporter() {
} }
bool OpenGEXExporter::exportScene( const char *filename, const aiScene* pScene ) {
return true;
}
#endif // ASSIMP_BUILD_NO_OPENGEX_EXPORTER #endif // ASSIMP_BUILD_NO_OPENGEX_EXPORTER
} // Namespace OpenGEX } // Namespace OpenGEX

View File

@ -223,17 +223,19 @@ static void propId2StdString( Property *prop, std::string &name, std::string &ke
OpenGEXImporter::VertexContainer::VertexContainer() OpenGEXImporter::VertexContainer::VertexContainer()
: m_numVerts( 0 ) : m_numVerts( 0 )
, m_vertices( nullptr ) , m_vertices( nullptr )
, m_numColors( 0 )
, m_colors( nullptr )
, m_numNormals( 0 ) , m_numNormals( 0 )
, m_normals( nullptr ) , m_normals( nullptr )
, m_numUVComps() , m_numUVComps()
, m_textureCoords() , m_textureCoords() {
{
// empty // empty
} }
//------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------
OpenGEXImporter::VertexContainer::~VertexContainer() { OpenGEXImporter::VertexContainer::~VertexContainer() {
delete[] m_vertices; delete[] m_vertices;
delete[] m_colors;
delete[] m_normals; delete[] m_normals;
for(auto &texcoords : m_textureCoords) { for(auto &texcoords : m_textureCoords) {
@ -279,7 +281,7 @@ OpenGEXImporter::OpenGEXImporter()
//------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------
OpenGEXImporter::~OpenGEXImporter() { OpenGEXImporter::~OpenGEXImporter() {
m_ctx = NULL; m_ctx = nullptr;
} }
//------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------
@ -464,13 +466,13 @@ void OpenGEXImporter::handleMetricNode( DDLNode *node, aiScene *pScene ) {
//------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------
void OpenGEXImporter::handleNameNode( DDLNode *node, aiScene *pScene ) { void OpenGEXImporter::handleNameNode( DDLNode *node, aiScene *pScene ) {
if( NULL == m_currentNode ) { if( nullptr == m_currentNode ) {
throw DeadlyImportError( "No current node for name." ); throw DeadlyImportError( "No current node for name." );
return; return;
} }
Value *val( node->getValue() ); Value *val( node->getValue() );
if( NULL != val ) { if( nullptr != val ) {
if( Value::ddl_string != val->m_type ) { if( Value::ddl_string != val->m_type ) {
throw DeadlyImportError( "OpenGEX: invalid data type for value in node name." ); throw DeadlyImportError( "OpenGEX: invalid data type for value in node name." );
return; return;
@ -488,7 +490,7 @@ void OpenGEXImporter::handleNameNode( DDLNode *node, aiScene *pScene ) {
//------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------
static void getRefNames( DDLNode *node, std::vector<std::string> &names ) { static void getRefNames( DDLNode *node, std::vector<std::string> &names ) {
ai_assert( NULL != node ); ai_assert( nullptr != node );
Reference *ref = node->getReferences(); Reference *ref = node->getReferences();
if( nullptr != ref ) { if( nullptr != ref ) {
@ -710,6 +712,7 @@ void OpenGEXImporter::handleMeshNode( ODDLParser::DDLNode *node, aiScene *pScene
enum MeshAttribute { enum MeshAttribute {
None, None,
Position, Position,
Color,
Normal, Normal,
TexCoord TexCoord
}; };
@ -718,8 +721,10 @@ enum MeshAttribute {
static MeshAttribute getAttributeByName( const char *attribName ) { static MeshAttribute getAttributeByName( const char *attribName ) {
ai_assert( nullptr != attribName ); ai_assert( nullptr != attribName );
if( 0 == strncmp( "position", attribName, strlen( "position" ) ) ) { if ( 0 == strncmp( "position", attribName, strlen( "position" ) ) ) {
return Position; return Position;
} else if ( 0 == strncmp( "color", attribName, strlen( "color" ) ) ) {
return Color;
} else if( 0 == strncmp( "normal", attribName, strlen( "normal" ) ) ) { } else if( 0 == strncmp( "normal", attribName, strlen( "normal" ) ) ) {
return Normal; return Normal;
} else if( 0 == strncmp( "texcoord", attribName, strlen( "texcoord" ) ) ) { } else if( 0 == strncmp( "texcoord", attribName, strlen( "texcoord" ) ) ) {
@ -747,6 +752,22 @@ static void fillVector3( aiVector3D *vec3, Value *vals ) {
vec3->Set( x, y, z ); vec3->Set( x, y, z );
} }
//------------------------------------------------------------------------------------------------
static void fillColor4( aiColor4D *col4, Value *vals ) {
ai_assert( nullptr != col4 );
ai_assert( nullptr != vals );
float r( 0.0f ), g( 0.0f ), b( 0.0f ), a ( 1.0f );
Value *next( vals );
col4->r = next->getFloat();
next = next->m_next;
col4->g = next->getFloat();
next = next->m_next;
col4->b = next->getFloat();
next = next->m_next;
col4->a = next->getFloat();
}
//------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------
static size_t countDataArrayListItems( DataArrayList *vaList ) { static size_t countDataArrayListItems( DataArrayList *vaList ) {
size_t numItems( 0 ); size_t numItems( 0 );
@ -774,6 +795,14 @@ static void copyVectorArray( size_t numItems, DataArrayList *vaList, aiVector3D
} }
} }
//------------------------------------------------------------------------------------------------
static void copyColor4DArray( size_t numItems, DataArrayList *vaList, aiColor4D *colArray ) {
for ( size_t i = 0; i < numItems; i++ ) {
Value *next( vaList->m_dataList );
fillColor4( &colArray[ i ], next );
}
}
//------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------
void OpenGEXImporter::handleVertexArrayNode( ODDLParser::DDLNode *node, aiScene *pScene ) { void OpenGEXImporter::handleVertexArrayNode( ODDLParser::DDLNode *node, aiScene *pScene ) {
if( nullptr == node ) { if( nullptr == node ) {
@ -801,6 +830,10 @@ void OpenGEXImporter::handleVertexArrayNode( ODDLParser::DDLNode *node, aiScene
m_currentVertices.m_numVerts = numItems; m_currentVertices.m_numVerts = numItems;
m_currentVertices.m_vertices = new aiVector3D[ numItems ]; m_currentVertices.m_vertices = new aiVector3D[ numItems ];
copyVectorArray( numItems, vaList, m_currentVertices.m_vertices ); copyVectorArray( numItems, vaList, m_currentVertices.m_vertices );
} else if ( Color == attribType ) {
m_currentVertices.m_numColors = numItems;
m_currentVertices.m_colors = new aiColor4D[ numItems ];
copyColor4DArray( numItems, vaList, m_currentVertices.m_colors );
} else if( Normal == attribType ) { } else if( Normal == attribType ) {
m_currentVertices.m_numNormals = numItems; m_currentVertices.m_numNormals = numItems;
m_currentVertices.m_normals = new aiVector3D[ numItems ]; m_currentVertices.m_normals = new aiVector3D[ numItems ];
@ -835,6 +868,11 @@ void OpenGEXImporter::handleIndexArrayNode( ODDLParser::DDLNode *node, aiScene *
m_currentMesh->mFaces = new aiFace[ numItems ]; m_currentMesh->mFaces = new aiFace[ numItems ];
m_currentMesh->mNumVertices = numItems * 3; m_currentMesh->mNumVertices = numItems * 3;
m_currentMesh->mVertices = new aiVector3D[ m_currentMesh->mNumVertices ]; m_currentMesh->mVertices = new aiVector3D[ m_currentMesh->mNumVertices ];
bool hasColors( false );
if ( m_currentVertices.m_numColors > 0 ) {
m_currentMesh->mColors[0] = new aiColor4D[ m_currentVertices.m_numColors ];
hasColors = true;
}
bool hasNormalCoords( false ); bool hasNormalCoords( false );
if ( m_currentVertices.m_numNormals > 0 ) { if ( m_currentVertices.m_numNormals > 0 ) {
m_currentMesh->mNormals = new aiVector3D[ m_currentMesh->mNumVertices ]; m_currentMesh->mNormals = new aiVector3D[ m_currentMesh->mNumVertices ];
@ -858,6 +896,10 @@ void OpenGEXImporter::handleIndexArrayNode( ODDLParser::DDLNode *node, aiScene *
ai_assert( index < m_currentMesh->mNumVertices ); ai_assert( index < m_currentMesh->mNumVertices );
aiVector3D &pos = ( m_currentVertices.m_vertices[ idx ] ); aiVector3D &pos = ( m_currentVertices.m_vertices[ idx ] );
m_currentMesh->mVertices[ index ].Set( pos.x, pos.y, pos.z ); m_currentMesh->mVertices[ index ].Set( pos.x, pos.y, pos.z );
if ( hasColors ) {
aiColor4D &col = m_currentVertices.m_colors[ idx ];
m_currentMesh->mColors[ 0 ][ index ] = col;
}
if ( hasNormalCoords ) { if ( hasNormalCoords ) {
aiVector3D &normal = ( m_currentVertices.m_normals[ idx ] ); aiVector3D &normal = ( m_currentVertices.m_normals[ idx ] );
m_currentMesh->mNormals[ index ].Set( normal.x, normal.y, normal.z ); m_currentMesh->mNormals[ index ].Set( normal.x, normal.y, normal.z );
@ -1082,10 +1124,10 @@ void OpenGEXImporter::resolveReferences() {
return; return;
} }
RefInfo *currentRefInfo( NULL ); RefInfo *currentRefInfo( nullptr );
for( std::vector<RefInfo*>::iterator it = m_unresolvedRefStack.begin(); it != m_unresolvedRefStack.end(); ++it ) { for( std::vector<RefInfo*>::iterator it = m_unresolvedRefStack.begin(); it != m_unresolvedRefStack.end(); ++it ) {
currentRefInfo = *it; currentRefInfo = *it;
if( NULL != currentRefInfo ) { if( nullptr != currentRefInfo ) {
aiNode *node( currentRefInfo->m_node ); aiNode *node( currentRefInfo->m_node );
if( RefInfo::MeshRef == currentRefInfo->m_type ) { if( RefInfo::MeshRef == currentRefInfo->m_type ) {
for( size_t i = 0; i < currentRefInfo->m_Names.size(); i++ ) { for( size_t i = 0; i < currentRefInfo->m_Names.size(); i++ ) {
@ -1124,7 +1166,7 @@ void OpenGEXImporter::createNodeTree( aiScene *pScene ) {
void OpenGEXImporter::pushNode( aiNode *node, aiScene *pScene ) { void OpenGEXImporter::pushNode( aiNode *node, aiScene *pScene ) {
ai_assert( nullptr != pScene ); ai_assert( nullptr != pScene );
if ( NULL == node ) { if ( nullptr == node ) {
return; return;
} }

View File

@ -142,6 +142,8 @@ private:
struct VertexContainer { struct VertexContainer {
size_t m_numVerts; size_t m_numVerts;
aiVector3D *m_vertices; aiVector3D *m_vertices;
size_t m_numColors;
aiColor4D *m_colors;
size_t m_numNormals; size_t m_numNormals;
aiVector3D *m_normals; aiVector3D *m_normals;
size_t m_numUVComps[ AI_MAX_NUMBER_OF_TEXTURECOORDS ]; size_t m_numUVComps[ AI_MAX_NUMBER_OF_TEXTURECOORDS ];
@ -150,9 +152,8 @@ private:
VertexContainer(); VertexContainer();
~VertexContainer(); ~VertexContainer();
private: VertexContainer( const VertexContainer & ) = delete;
VertexContainer( const VertexContainer & ); VertexContainer &operator = ( const VertexContainer & ) = delete;
VertexContainer &operator = ( const VertexContainer & );
}; };
struct RefInfo { struct RefInfo {
@ -168,9 +169,8 @@ private:
RefInfo( aiNode *node, Type type, std::vector<std::string> &names ); RefInfo( aiNode *node, Type type, std::vector<std::string> &names );
~RefInfo(); ~RefInfo();
private: RefInfo( const RefInfo & ) = delete;
RefInfo( const RefInfo & ); RefInfo &operator = ( const RefInfo & ) = delete;
RefInfo &operator = ( const RefInfo & );
}; };
struct ChildInfo { struct ChildInfo {

View File

@ -113,7 +113,6 @@ struct LightObject {
bool shadowFlag; bool shadowFlag;
}; };
struct CameraObject { struct CameraObject {
float focalLength; float focalLength;
float nearDepth; float nearDepth;
@ -146,7 +145,6 @@ struct Name {
std::string name; std::string name;
}; };
struct ObjectRef { struct ObjectRef {
Object *targetStructure; Object *targetStructure;
}; };
@ -173,7 +171,6 @@ struct BoneIndex {
unsigned short *arrayStorage; unsigned short *arrayStorage;
}; };
struct BoneWeight { struct BoneWeight {
int boneWeightCount; int boneWeightCount;
const float *boneWeightArray; const float *boneWeightArray;

View File

@ -198,7 +198,7 @@ struct SceneHelper
* The class is currently being used by various postprocessing steps * The class is currently being used by various postprocessing steps
* and loaders (ie. LWS). * and loaders (ie. LWS).
*/ */
class SceneCombiner class ASSIMP_API SceneCombiner
{ {
// class cannot be instanced // class cannot be instanced
SceneCombiner() {} SceneCombiner() {}

View File

@ -38,6 +38,11 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
*/ */
/** @file StdOStreamLogStream.h
* @brief Implementation of StdOStreamLogStream
*/
#ifndef AI_STROSTREAMLOGSTREAM_H_INC #ifndef AI_STROSTREAMLOGSTREAM_H_INC
#define AI_STROSTREAMLOGSTREAM_H_INC #define AI_STROSTREAMLOGSTREAM_H_INC
@ -50,8 +55,7 @@ namespace Assimp {
/** @class StdOStreamLogStream /** @class StdOStreamLogStream
* @brief Logs into a std::ostream * @brief Logs into a std::ostream
*/ */
class StdOStreamLogStream : public LogStream class StdOStreamLogStream : public LogStream {
{
public: public:
/** @brief Construction from an existing std::ostream /** @brief Construction from an existing std::ostream
* @param _ostream Output stream to be used * @param _ostream Output stream to be used
@ -63,30 +67,33 @@ public:
/** @brief Writer */ /** @brief Writer */
void write(const char* message); void write(const char* message);
private: private:
std::ostream& ostream; std::ostream& mOstream;
}; };
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// Default constructor // Default constructor
inline StdOStreamLogStream::StdOStreamLogStream(std::ostream& _ostream) inline StdOStreamLogStream::StdOStreamLogStream(std::ostream& _ostream)
: ostream (_ostream) : mOstream (_ostream){
{} // empty
// ---------------------------------------------------------------------------
// Default constructor
inline StdOStreamLogStream::~StdOStreamLogStream()
{}
// ---------------------------------------------------------------------------
// Write method
inline void StdOStreamLogStream::write(const char* message)
{
ostream << message;
ostream.flush();
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// Default constructor
inline StdOStreamLogStream::~StdOStreamLogStream() {
// empty
}
// ---------------------------------------------------------------------------
// Write method
inline void StdOStreamLogStream::write(const char* message) {
mOstream << message;
mOstream.flush();
}
// ---------------------------------------------------------------------------
} // Namespace Assimp } // Namespace Assimp
#endif // guard #endif // guard

View File

@ -1,7 +1,51 @@
/*
---------------------------------------------------------------------------
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.
---------------------------------------------------------------------------
*/
/** @file Win32DebugLogStream.h
* @brief Implementation of Win32DebugLogStream
*/
#ifndef AI_WIN32DEBUGLOGSTREAM_H_INC #ifndef AI_WIN32DEBUGLOGSTREAM_H_INC
#define AI_WIN32DEBUGLOGSTREAM_H_INC #define AI_WIN32DEBUGLOGSTREAM_H_INC
#ifdef WIN32 #ifdef _WIN32
#include <assimp/LogStream.hpp> #include <assimp/LogStream.hpp>
#include "windows.h" #include "windows.h"
@ -12,9 +56,7 @@ namespace Assimp {
/** @class Win32DebugLogStream /** @class Win32DebugLogStream
* @brief Logs into the debug stream from win32. * @brief Logs into the debug stream from win32.
*/ */
class Win32DebugLogStream : class Win32DebugLogStream : public LogStream {
public LogStream
{
public: public:
/** @brief Default constructor */ /** @brief Default constructor */
Win32DebugLogStream(); Win32DebugLogStream();
@ -27,24 +69,25 @@ public:
}; };
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// Default constructor inline
inline Win32DebugLogStream::Win32DebugLogStream() Win32DebugLogStream::Win32DebugLogStream(){
{} // empty
}
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// Default constructor inline
inline Win32DebugLogStream::~Win32DebugLogStream() Win32DebugLogStream::~Win32DebugLogStream(){
{} // empty
}
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// Write method inline
inline void Win32DebugLogStream::write(const char* message) void Win32DebugLogStream::write(const char* message) {
{ ::OutputDebugStringA( message);
OutputDebugStringA( message);
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
} // Namespace Assimp } // Namespace Assimp
#endif // ! WIN32 #endif // ! _WIN32
#endif // guard #endif // guard

View File

@ -98,7 +98,6 @@ public:
operator aiVector3t<TOther> () const; operator aiVector3t<TOther> () const;
public: public:
/** @brief Set the components of a vector /** @brief Set the components of a vector
* @param pX X component * @param pX X component
* @param pY Y component * @param pY Y component
@ -109,7 +108,6 @@ public:
* @return Square length */ * @return Square length */
TReal SquareLength() const; TReal SquareLength() const;
/** @brief Get the length of the vector /** @brief Get the length of the vector
* @return length */ * @return length */
TReal Length() const; TReal Length() const;

View File

@ -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/SceneDiffer.h
unit/SceneDiffer.cpp
unit/utObjImportExport.cpp
unit/utPretransformVertices.cpp unit/utPretransformVertices.cpp
unit/utRemoveComments.cpp unit/utRemoveComments.cpp
unit/utRemoveComponent.cpp unit/utRemoveComponent.cpp

View File

@ -38,21 +38,23 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
*/ */
#include "ModelDiffer.h" #include "SceneDiffer.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;
ModelDiffer::ModelDiffer() { SceneDiffer::SceneDiffer() {
// empty // empty
} }
ModelDiffer::~ModelDiffer() { SceneDiffer::~SceneDiffer() {
// empty // empty
} }
bool ModelDiffer::isEqual( aiScene *expected, aiScene *toCompare ) { bool SceneDiffer::isEqual( const aiScene *expected, const aiScene *toCompare ) {
if ( expected == toCompare ) { if ( expected == toCompare ) {
return true; return true;
} }
@ -65,20 +67,55 @@ 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() );
}
} }
// ToDo!
return true;
// 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;
}
if ( expected->mNumMaterials > 0 ) {
if ( nullptr == expected->mMaterials || nullptr == toCompare->mMaterials ) {
addDiff( "Number of materials > 0 and mat pointer is nullptr" );
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 SceneDiffer::showReport() {
if ( m_diffs.empty() ) { if ( m_diffs.empty() ) {
return; return;
} }
@ -90,11 +127,11 @@ void ModelDiffer::showReport() {
std::cout << std::endl; std::cout << std::endl;
} }
void ModelDiffer::reset() { void SceneDiffer::reset() {
m_diffs.resize( 0 ); m_diffs.resize( 0 );
} }
void ModelDiffer::addDiff( const std::string &diff ) { void SceneDiffer::addDiff( const std::string &diff ) {
if ( diff.empty() ) { if ( diff.empty() ) {
return; return;
} }
@ -113,7 +150,20 @@ static std::string dumpColor4D( const aiColor4D &toDump ) {
return stream.str(); return stream.str();
} }
bool ModelDiffer::compareMesh( aiMesh *expected, aiMesh *toCompare ) { 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 ) { if ( expected == toCompare ) {
return true; return true;
} }
@ -145,9 +195,10 @@ bool ModelDiffer::compareMesh( aiMesh *expected, aiMesh *toCompare ) {
for ( unsigned int i = 0; i < expected->mNumVertices; i++ ) { for ( unsigned int i = 0; i < expected->mNumVertices; i++ ) {
aiVector3D &expVert( expected->mVertices[ i ] ); aiVector3D &expVert( expected->mVertices[ i ] );
aiVector3D &toCompVert( toCompare->mVertices[ i ] ); aiVector3D &toCompVert( toCompare->mVertices[ i ] );
if ( expVert != toCompVert ) { if ( !expVert.Equal( toCompVert ) ) {
std::cout << "index = " << i << dumpVector3( toCompVert ) << "\n";
std::stringstream stream; std::stringstream stream;
stream << "Vertex not equal ( expected: " << dumpVector3( expVert ) << ", found: " << dumpVector3( toCompVert ) << "\n"; stream << "Vertex not equal ( expected: " << dumpVector3( toCompVert ) << ", found: " << dumpVector3( toCompVert ) << "\n";
addDiff( stream.str() ); addDiff( stream.str() );
vertEqual = false; vertEqual = false;
} }
@ -162,11 +213,14 @@ bool ModelDiffer::compareMesh( aiMesh *expected, aiMesh *toCompare ) {
return false; return false;
} }
// return true;
//ToDo!
bool normalEqual( true ); 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 &expNormal( expected->mNormals[ i ] );
aiVector3D &toCompNormal( toCompare->mNormals[ i ] ); aiVector3D &toCompNormal( toCompare->mNormals[ i ] );
if ( expNormal != toCompNormal ) { if ( expNormal.Equal( toCompNormal ) ) {
std::stringstream stream; std::stringstream stream;
stream << "Normal not equal ( expected: " << dumpVector3( expNormal ) << ", found: " << dumpVector3( toCompNormal ) << "\n"; stream << "Normal not equal ( expected: " << dumpVector3( expNormal ) << ", found: " << dumpVector3( toCompNormal ) << "\n";
addDiff( stream.str() ); addDiff( stream.str() );
@ -209,7 +263,7 @@ bool ModelDiffer::compareMesh( aiMesh *expected, aiMesh *toCompare ) {
for ( unsigned int i = 0; i < expected->mNumVertices; i++ ) { for ( unsigned int i = 0; i < expected->mNumVertices; i++ ) {
aiVector3D &expTexCoord( expected->mTextureCoords[ a ][ i ] ); aiVector3D &expTexCoord( expected->mTextureCoords[ a ][ i ] );
aiVector3D &toCompTexCoord( toCompare->mTextureCoords[ a ][ i ] ); aiVector3D &toCompTexCoord( toCompare->mTextureCoords[ a ][ i ] );
if ( expTexCoord != toCompTexCoord ) { if ( expTexCoord.Equal( toCompTexCoord ) ) {
std::stringstream stream; std::stringstream stream;
stream << "Texture coords not equal ( expected: " << dumpVector3( expTexCoord ) << ", found: " << dumpVector3( toCompTexCoord ) << "\n"; stream << "Texture coords not equal ( expected: " << dumpVector3( expTexCoord ) << ", found: " << dumpVector3( toCompTexCoord ) << "\n";
addDiff( stream.str() ); addDiff( stream.str() );
@ -230,7 +284,7 @@ bool ModelDiffer::compareMesh( aiMesh *expected, aiMesh *toCompare ) {
for ( unsigned int i = 0; i < expected->mNumVertices; i++ ) { for ( unsigned int i = 0; i < expected->mNumVertices; i++ ) {
aiVector3D &expTangents( expected->mTangents[ i ] ); aiVector3D &expTangents( expected->mTangents[ i ] );
aiVector3D &toCompTangents( toCompare->mTangents[ i ] ); aiVector3D &toCompTangents( toCompare->mTangents[ i ] );
if ( expTangents != toCompTangents ) { if ( expTangents.Equal( toCompTangents ) ) {
std::stringstream stream; std::stringstream stream;
stream << "Tangents not equal ( expected: " << dumpVector3( expTangents ) << ", found: " << dumpVector3( toCompTangents ) << "\n"; stream << "Tangents not equal ( expected: " << dumpVector3( expTangents ) << ", found: " << dumpVector3( toCompTangents ) << "\n";
addDiff( stream.str() ); addDiff( stream.str() );
@ -239,16 +293,77 @@ bool ModelDiffer::compareMesh( aiMesh *expected, aiMesh *toCompare ) {
aiVector3D &expBiTangents( expected->mBitangents[ i ] ); aiVector3D &expBiTangents( expected->mBitangents[ i ] );
aiVector3D &toCompBiTangents( toCompare->mBitangents[ i ] ); aiVector3D &toCompBiTangents( toCompare->mBitangents[ i ] );
if ( expBiTangents != toCompBiTangents ) { if ( expBiTangents.Equal( 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;
} }
} }
if ( !tangentsEqual ) { if ( !tangentsEqual ) {
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( toCompare->mFaces[ i ] );
if ( !compareFace( &expFace, &toCompareFace ) ) {
addDiff( "Faces are not equal\n" );
addDiff( dumpFace( expFace ) );
addDiff( dumpFace( toCompareFace ) );
facesEqual = false;
}
}
if ( !facesEqual ) {
return false;
} }
return true; return true;
} }
bool SceneDiffer::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 SceneDiffer::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;
}

View File

@ -47,18 +47,22 @@ 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 SceneDiffer {
public: public:
ModelDiffer(); SceneDiffer();
~ModelDiffer(); ~SceneDiffer();
bool isEqual( aiScene *expected, aiScene *toCompare ); bool isEqual( const aiScene *expected, const aiScene *toCompare );
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;

View File

@ -0,0 +1,189 @@
/*
---------------------------------------------------------------------------
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 "SceneDiffer.h"
#include <assimp/Importer.hpp>
#include <assimp/scene.h>
using namespace Assimp;
static const float VertComponents[ 24 * 3 ] = {
-0.500000, 0.500000, 0.500000,
-0.500000, 0.500000, -0.500000,
-0.500000, -0.500000, -0.500000,
-0.500000, -0.500000, 0.500000,
-0.500000, -0.500000, -0.500000,
0.500000, -0.500000, -0.500000,
0.500000, -0.500000, 0.500000,
-0.500000, -0.500000, 0.500000,
-0.500000, 0.500000, -0.500000,
0.500000, 0.500000, -0.500000,
0.500000, -0.500000, -0.500000,
-0.500000, -0.500000, -0.500000,
0.500000, 0.500000, 0.500000,
0.500000, 0.500000, -0.500000,
-0.500000, 0.500000, -0.500000,
-0.500000, 0.500000, 0.500000,
0.500000, -0.500000, 0.500000,
0.500000, 0.500000, 0.500000,
-0.500000, 0.500000, 0.500000,
-0.500000, -0.500000, 0.500000,
0.500000, -0.500000, -0.500000,
0.500000, 0.500000, -0.500000,
0.500000, 0.500000, 0.500000f,
0.500000, -0.500000, 0.500000f
};
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";
class utObjImportExport : public ::testing::Test {
protected:
virtual void SetUp() {
m_im = new Assimp::Importer;
}
virtual void TearDown() {
delete m_im;
m_im = nullptr;
}
aiScene *createScene() {
aiScene *expScene = new aiScene;
expScene->mNumMeshes = 1;
expScene->mMeshes = new aiMesh*[ 1 ];
aiMesh *mesh = new aiMesh;
mesh->mName.Set( "1" );
mesh->mNumVertices = 24;
mesh->mVertices = new aiVector3D[ 24 ];
::memcpy( &mesh->mVertices->x, &VertComponents[ 0 ], sizeof( float ) * 24 * 3 );
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;
expScene->mMaterials = new aiMaterial*[ expScene->mNumMaterials ];
return expScene;
}
protected:
Assimp::Importer *m_im;
aiScene *m_expectedScene;
};
TEST_F( utObjImportExport, obj_import_test ) {
const aiScene *scene = m_im->ReadFileFromMemory( (void*) ObjModel.c_str(), ObjModel.size(), 0 );
aiScene *expected = createScene();
EXPECT_NE( nullptr, scene );
SceneDiffer differ;
EXPECT_TRUE( differ.isEqual( expected, scene ) );
differ.showReport();
}