From 0bae2bbfa7011b86d44a314e3919f244113127db Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Fri, 7 Oct 2016 09:19:10 +0200 Subject: [PATCH 01/44] Obj-Importer: start new streaming handling. --- code/ObjFileData.h | 6 +++--- code/ObjFileImporter.cpp | 23 +++++++++++++++++++++++ code/ObjFileImporter.h | 4 ++-- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/code/ObjFileData.h b/code/ObjFileData.h index 2d282e6a9..4fc262760 100644 --- a/code/ObjFileData.h +++ b/code/ObjFileData.h @@ -104,7 +104,7 @@ struct Face // ------------------------------------------------------------------------------------------------ //! \struct Object -//! \brief Stores all objects of an objfile object definition +//! \brief Stores all objects of an obj-file object definition struct Object { enum ObjectType @@ -160,8 +160,8 @@ struct Material aiString textureSpecularity; aiString textureOpacity; aiString textureDisp; - enum TextureType - { + + enum TextureType { TextureDiffuseType = 0, TextureSpecularType, TextureAmbientType, diff --git a/code/ObjFileImporter.cpp b/code/ObjFileImporter.cpp index a70d69b4a..8beabaf88 100644 --- a/code/ObjFileImporter.cpp +++ b/code/ObjFileImporter.cpp @@ -70,6 +70,29 @@ namespace Assimp { using namespace std; +struct IOStreamBuffer { + BaseImporter *m_importer; + IOStream *m_stream; + size_t m_cacheSize; + std::vector m_buffer; + size_t m_filesize; + size_t m_blockIndex; + IOStreamBuffer( BaseImporter *imp, IOStream *stream, size_t cache = 4096 ) + : m_importer( imp ) + , m_stream( stream ) + , m_cacheSize( cache ) + , m_buffer() + , m_filesize( 0 ) + , m_blockIndex( 0 ) { + m_buffer.resize( m_cacheSize ); + m_filesize = m_stream->FileSize() ); + } + + char &get( size_t index ) { + + } +}; + // ------------------------------------------------------------------------------------------------ // Default constructor ObjFileImporter::ObjFileImporter() : diff --git a/code/ObjFileImporter.h b/code/ObjFileImporter.h index 8c482017b..a962d43c4 100644 --- a/code/ObjFileImporter.h +++ b/code/ObjFileImporter.h @@ -50,8 +50,8 @@ struct aiNode; namespace Assimp { namespace ObjFile { -struct Object; -struct Model; + struct Object; + struct Model; } // ------------------------------------------------------------------------------------------------ From ad4d1f717ff26d57ee782235e1d42135e5be4aa6 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Mon, 10 Oct 2016 10:18:14 +0200 Subject: [PATCH 02/44] Obj-Import: finish first prototype of IOStreamBuffer. --- code/ObjFileImporter.cpp | 61 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 55 insertions(+), 6 deletions(-) diff --git a/code/ObjFileImporter.cpp b/code/ObjFileImporter.cpp index 8beabaf88..ccf96f827 100644 --- a/code/ObjFileImporter.cpp +++ b/code/ObjFileImporter.cpp @@ -70,27 +70,76 @@ namespace Assimp { using namespace std; +template struct IOStreamBuffer { BaseImporter *m_importer; IOStream *m_stream; size_t m_cacheSize; - std::vector m_buffer; + std::vector m_buffer; size_t m_filesize; - size_t m_blockIndex; + size_t c; + size_t m_numBlocks; + size_t m_sizeLastBlock; + IOStreamBuffer( BaseImporter *imp, IOStream *stream, size_t cache = 4096 ) : m_importer( imp ) , m_stream( stream ) , m_cacheSize( cache ) , m_buffer() , m_filesize( 0 ) - , m_blockIndex( 0 ) { + , m_blockIndex( 0 ) + , m_numBlocks( 0 ) + , m_sizeLastBlock( 0 ) { m_buffer.resize( m_cacheSize ); - m_filesize = m_stream->FileSize() ); + m_filesize = m_stream->FileSize(); + m_numBlocks = m_filesize / m_cacheSize; + m_sizeLastBlock = m_filesize % m_cacheSize; } - char &get( size_t index ) { - + ~IOStreamBuffer() { + clear(); } + + void clear() { + m_cacheSize = 4096; + m_buffer.resize( 0 ); + } + + bool mapPosToBlock( size_t pos, size_t &blockIdx, size_t &blockPos ) { + if ( pos > m_filesize ) { + return false; + } + blockIdx = pos / m_cacheSize; + blockPos = pos % m_cacheSize; + + return true; + } + + void loadBlock( size_t blockIdx ) { + size_t pos = blockIdx * m_cacheSize; + size_t sizeToRead( m_cacheSize ); + if ( m_blockIdx == ( m_numBlocks - 1 ) ) { + sizeToRead = m_sizeLastBlock; + } + + m_stream->Seek( pos <, aiOrigin_SET ); + m_stream->Read( &m_buffer[ 0 ], sizeof( T ), sizeToRead ); + m_blockIndex = blockIdx; + + BaseImporter::ConvertToUTF8( m_buffer ); + } + + T &operator [] (size_t pos ) { + size_t blockIdx( 0 ), blockPos( 0 ); + if ( !mapPosToBlock( pos, blockIdx, blockPos ) ) { + throw DeadlyImportError( "OBJ-file-access out of bounds." ); + } + if ( m_blockIndex != blockIdx ) { + loadBlock( blockIdx ); + } + + return m_buffer[ blockPos ]; + } }; // ------------------------------------------------------------------------------------------------ From 905e48a35c0f84d4931c2ad7ef5c6c6783b8bd1b Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Tue, 11 Oct 2016 12:29:40 +0200 Subject: [PATCH 03/44] Buffered stream API for big files: add next try of a prototype.^ --- code/CMakeLists.txt | 1 + code/ObjFileImporter.cpp | 86 +++++----------------------------------- code/ObjFileParser.cpp | 36 +++++++++-------- code/ObjFileParser.h | 5 ++- code/ObjTools.h | 14 +++++++ 5 files changed, 47 insertions(+), 95 deletions(-) diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index 10979df5c..357fa3693 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -171,6 +171,7 @@ SET( Common_SRCS Bitmap.h XMLTools.h Version.cpp + IOStreamBuffer.h ) SOURCE_GROUP(Common FILES ${Common_SRCS}) diff --git a/code/ObjFileImporter.cpp b/code/ObjFileImporter.cpp index ccf96f827..ae070ab4e 100644 --- a/code/ObjFileImporter.cpp +++ b/code/ObjFileImporter.cpp @@ -45,6 +45,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "ObjFileImporter.h" #include "ObjFileParser.h" #include "ObjFileData.h" +#include "IOStreamBuffer.h" #include #include #include @@ -70,78 +71,6 @@ namespace Assimp { using namespace std; -template -struct IOStreamBuffer { - BaseImporter *m_importer; - IOStream *m_stream; - size_t m_cacheSize; - std::vector m_buffer; - size_t m_filesize; - size_t c; - size_t m_numBlocks; - size_t m_sizeLastBlock; - - IOStreamBuffer( BaseImporter *imp, IOStream *stream, size_t cache = 4096 ) - : m_importer( imp ) - , m_stream( stream ) - , m_cacheSize( cache ) - , m_buffer() - , m_filesize( 0 ) - , m_blockIndex( 0 ) - , m_numBlocks( 0 ) - , m_sizeLastBlock( 0 ) { - m_buffer.resize( m_cacheSize ); - m_filesize = m_stream->FileSize(); - m_numBlocks = m_filesize / m_cacheSize; - m_sizeLastBlock = m_filesize % m_cacheSize; - } - - ~IOStreamBuffer() { - clear(); - } - - void clear() { - m_cacheSize = 4096; - m_buffer.resize( 0 ); - } - - bool mapPosToBlock( size_t pos, size_t &blockIdx, size_t &blockPos ) { - if ( pos > m_filesize ) { - return false; - } - blockIdx = pos / m_cacheSize; - blockPos = pos % m_cacheSize; - - return true; - } - - void loadBlock( size_t blockIdx ) { - size_t pos = blockIdx * m_cacheSize; - size_t sizeToRead( m_cacheSize ); - if ( m_blockIdx == ( m_numBlocks - 1 ) ) { - sizeToRead = m_sizeLastBlock; - } - - m_stream->Seek( pos <, aiOrigin_SET ); - m_stream->Read( &m_buffer[ 0 ], sizeof( T ), sizeToRead ); - m_blockIndex = blockIdx; - - BaseImporter::ConvertToUTF8( m_buffer ); - } - - T &operator [] (size_t pos ) { - size_t blockIdx( 0 ), blockPos( 0 ); - if ( !mapPosToBlock( pos, blockIdx, blockPos ) ) { - throw DeadlyImportError( "OBJ-file-access out of bounds." ); - } - if ( m_blockIndex != blockIdx ) { - loadBlock( blockIdx ); - } - - return m_buffer[ blockPos ]; - } -}; - // ------------------------------------------------------------------------------------------------ // Default constructor ObjFileImporter::ObjFileImporter() : @@ -198,8 +127,11 @@ void ObjFileImporter::InternReadFile( const std::string &file, aiScene* pScene, throw DeadlyImportError( "OBJ-file is too small."); } + IOStreamBuffer streamedBuffer; + streamedBuffer.open( fileStream.get() ); + // Allocate buffer and read file into it - TextFileToBuffer( fileStream.get(),m_Buffer); + //TextFileToBuffer( fileStream.get(),m_Buffer); // Get the model name std::string modelName, folderName; @@ -222,7 +154,7 @@ void ObjFileImporter::InternReadFile( const std::string &file, aiScene* pScene, const unsigned int updateProgressEveryBytes = 100 * 1024; const unsigned int progressTotal = (3*m_Buffer.size()/updateProgressEveryBytes); // process all '\' - std::vector ::iterator iter = m_Buffer.begin(); + /*std::vector ::iterator iter = m_Buffer.begin(); while (iter != m_Buffer.end()) { if (*iter == '\\') @@ -241,17 +173,19 @@ void ObjFileImporter::InternReadFile( const std::string &file, aiScene* pScene, m_progress->UpdateFileRead(++progress, progressTotal); progressCounter = 0; } - } + }*/ // 1/3rd progress m_progress->UpdateFileRead(1, 3); // parse the file into a temporary representation - ObjFileParser parser(m_Buffer, modelName, pIOHandler, m_progress, file); + ObjFileParser parser( streamedBuffer, modelName, pIOHandler, m_progress, file); // And create the proper return structures out of it CreateDataFromImport(parser.GetModel(), pScene); + streamedBuffer.close(); + // Clean up allocated storage for the next import m_Buffer.clear(); diff --git a/code/ObjFileParser.cpp b/code/ObjFileParser.cpp index 9b13eea6f..306c101a4 100644 --- a/code/ObjFileParser.cpp +++ b/code/ObjFileParser.cpp @@ -61,9 +61,9 @@ const std::string ObjFileParser::DEFAULT_MATERIAL = AI_DEFAULT_MATERIAL_NAME; // ------------------------------------------------------------------- // Constructor with loaded data and directories. -ObjFileParser::ObjFileParser(std::vector &data, const std::string &modelName, IOSystem *io, ProgressHandler* progress, const std::string &originalObjFileName) : - m_DataIt(data.begin()), - m_DataItEnd(data.end()), +ObjFileParser::ObjFileParser( IOStreamBuffer &streamBuffer, const std::string &modelName, IOSystem *io, ProgressHandler* progress, const std::string &originalObjFileName) : + m_DataIt(), + m_DataItEnd(), m_pModel(NULL), m_uiLine(0), m_pIO( io ), @@ -83,7 +83,7 @@ ObjFileParser::ObjFileParser(std::vector &data, const std::string &modelNa m_pModel->m_MaterialMap[ DEFAULT_MATERIAL ] = m_pModel->m_pDefaultMaterial; // Start parsing the file - parseFile(); + parseFile( streamBuffer ); } // ------------------------------------------------------------------- @@ -103,31 +103,33 @@ ObjFile::Model *ObjFileParser::GetModel() const // ------------------------------------------------------------------- // File parsing method. -void ObjFileParser::parseFile() -{ - if (m_DataIt == m_DataItEnd) - return; - +void ObjFileParser::parseFile( IOStreamBuffer &streamBuffer ) { // only update every 100KB or it'll be too slow const unsigned int updateProgressEveryBytes = 100 * 1024; unsigned int progressCounter = 0; - const unsigned int bytesToProcess = std::distance(m_DataIt, m_DataItEnd); + const unsigned int bytesToProcess = streamBuffer.size(); const unsigned int progressTotal = 3 * bytesToProcess; const unsigned int progressOffset = bytesToProcess; unsigned int processed = 0; - DataArrayIt lastDataIt = m_DataIt; + //DataArrayIt lastDataIt = m_DataIt; + + bool endOfFile( false ); + std::vector buffer; + + //while ( m_DataIt != m_DataItEnd ) + while ( streamBuffer.getNextLine( buffer ) ) { + m_DataIt = buffer.begin(); + m_DataItEnd = buffer.end(); - while (m_DataIt != m_DataItEnd) - { // Handle progress reporting - processed += std::distance(lastDataIt, m_DataIt); + /*processed += std::distance(lastDataIt, m_DataIt); lastDataIt = m_DataIt; if (processed > (progressCounter * updateProgressEveryBytes)) { progressCounter++; m_progress->UpdateFileRead(progressOffset + processed*2, progressTotal); - } + }*/ // parse line switch (*m_DataIt) @@ -149,8 +151,8 @@ void ObjFileParser::parseFile() } } else if (*m_DataIt == 't') { // read in texture coordinate ( 2D or 3D ) - ++m_DataIt; - getVector( m_pModel->m_TextureCoord ); + ++m_DataIt; + getVector( m_pModel->m_TextureCoord ); } else if (*m_DataIt == 'n') { // Read in normal vector definition ++m_DataIt; diff --git a/code/ObjFileParser.h b/code/ObjFileParser.h index ce7c34655..d5058b624 100644 --- a/code/ObjFileParser.h +++ b/code/ObjFileParser.h @@ -46,6 +46,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include "IOStreamBuffer.h" namespace Assimp { @@ -72,7 +73,7 @@ public: public: /// \brief Constructor with data array. - ObjFileParser(std::vector &Data, const std::string &strModelName, IOSystem* io, ProgressHandler* progress, const std::string &originalObjFileName); + ObjFileParser( IOStreamBuffer &streamBuffer, const std::string &strModelName, IOSystem* io, ProgressHandler* progress, const std::string &originalObjFileName); /// \brief Destructor ~ObjFileParser(); /// \brief Model getter. @@ -80,7 +81,7 @@ public: private: /// Parse the loaded file - void parseFile(); + void parseFile( IOStreamBuffer &streamBuffer ); /// Method to copy the new delimited word in the current line. void copyNextWord(char *pBuffer, size_t length); /// Method to copy the new line. diff --git a/code/ObjTools.h b/code/ObjTools.h index 649ac5a51..8abf60e16 100644 --- a/code/ObjTools.h +++ b/code/ObjTools.h @@ -246,6 +246,20 @@ string_type trim_whitespaces(string_type str) return str; } +template +bool hasLineEnd( T it, T end ) { + bool hasLineEnd( false ); + while ( !isEndOfBuffer( it, end ) ) { + it++; + if ( IsLineEnd( it ) ) { + hasLineEnd = true; + break; + } + } + + return hasLineEnd; +} + } // Namespace Assimp #endif // OBJ_TOOLS_H_INC From 084a6f64156949efd8036381179b333db5b42328 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Wed, 12 Oct 2016 15:30:04 +0200 Subject: [PATCH 04/44] Obj-Streaming: add new io-stream for line-wise cached reading + first bugfixes. --- code/IOStreamBuffer.h | 135 +++++++++++++++++++++++++++++++++ code/ObjTools.h | 6 +- test/unit/utIOStreamBuffer.cpp | 63 +++++++++++++++ 3 files changed, 201 insertions(+), 3 deletions(-) create mode 100644 code/IOStreamBuffer.h create mode 100644 test/unit/utIOStreamBuffer.cpp diff --git a/code/IOStreamBuffer.h b/code/IOStreamBuffer.h new file mode 100644 index 000000000..c7482352e --- /dev/null +++ b/code/IOStreamBuffer.h @@ -0,0 +1,135 @@ +#pragma once + +/* +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 + +namespace Assimp { + +class IOStream; + +template +class IOStreamBuffer { +public: + IOStreamBuffer( size_t cache = 4096 ) + : m_stream( nullptr ) + , m_filesize( 0 ) + , m_cacheSize( cache ) + , m_cachePos( 0 ) + , m_filePos( 0 ) { + m_cache.resize( cache ); + std::fill( m_cache.begin(), m_cache.end(), '\0' ); + } + + ~IOStreamBuffer() { + } + + bool open( IOStream *stream ) { + if ( nullptr == stream ) { + return false; + } + + m_stream = stream; + m_filesize = m_stream->FileSize(); + if ( m_filesize == 0 ) { + return false; + } + + return true; + } + + bool close() { + if ( nullptr == m_stream ) { + return false; + } + + m_stream = nullptr; + m_filesize =0; + + return true; + } + + size_t size() const { + return m_filesize; + } + + bool getNextLine( std::vector &buffer ) { + buffer.resize( m_cacheSize ); + ::memset( &buffer[ 0 ], ' ', m_cacheSize ); + if ( 0 == m_filePos ) { + size_t readLen = m_stream->Read( &m_cache[ 0 ], sizeof( T ), m_cacheSize ); + if ( readLen == 0 ) { + return false; + } + m_filePos += m_cacheSize; + } + + size_t i=0; + while ( !IsLineEnd( m_cache[ m_cachePos ] ) ) { + if ( m_cachePos + 1 == m_cacheSize ) { + m_stream->Seek(m_filePos, aiOrigin_CUR ); + size_t readLen = m_stream->Read( &m_cache[ 0 ], sizeof( T ), m_cacheSize ); + if ( readLen == 0 ) { + return false; + } + m_filePos += m_cacheSize; + m_cachePos = 0; + } + buffer[ i ] = m_cache[ m_cachePos ]; + m_cachePos++; + i++; + } + buffer[ i ]='\n'; + m_cachePos++; + + return true; + } + +private: + IOStream *m_stream; + size_t m_filesize; + size_t m_cacheSize; + std::vector m_cache; + size_t m_cachePos; + size_t m_filePos; +}; + +} // !ns Assimp diff --git a/code/ObjTools.h b/code/ObjTools.h index 8abf60e16..e58bf0c82 100644 --- a/code/ObjTools.h +++ b/code/ObjTools.h @@ -142,15 +142,15 @@ inline char_t getName( char_t it, char_t end, std::string &name ) } char *pStart = &( *it ); - while( !isEndOfBuffer( it, end ) && !IsLineEnd( *it ) ) { + while( !isEndOfBuffer( it, end ) && !IsLineEnd( *it ) && !IsSpaceOrNewLine( *it ) ) { ++it; } - while( isEndOfBuffer( it, end ) || IsLineEnd( *it ) || IsSpaceOrNewLine( *it ) ) { + /*while( isEndOfBuffer( it, end ) || IsLineEnd( *it ) || IsSpaceOrNewLine( *it ) ) { --it; } ++it; - + */ // Get name // if there is no name, and the previous char is a separator, come back to start while (&(*it) < pStart) { diff --git a/test/unit/utIOStreamBuffer.cpp b/test/unit/utIOStreamBuffer.cpp new file mode 100644 index 000000000..9d8d6ad96 --- /dev/null +++ b/test/unit/utIOStreamBuffer.cpp @@ -0,0 +1,63 @@ +/* +--------------------------------------------------------------------------- +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 "IOStreamBuffer.h" + +class IOStreamBufferTest : public ::testing::Test { + // empty +}; + +using namespace Assimp; + +TEST_F( IOStreamBufferTest, creationTest ) { + bool ok( true ); + try { + IOStreamBuffer myBuffer; + } catch ( ... ) { + ok = false; + } + EXPECT_TRUE( ok ); +} + +TEST_F( IOStreamBufferTest, readlineTest ) { + +} \ No newline at end of file From a54e42cb5ab22187169479773444c137e9462ef1 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Tue, 18 Oct 2016 14:02:58 +0200 Subject: [PATCH 05/44] Some more fixes. --- code/IOStreamBuffer.h | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/code/IOStreamBuffer.h b/code/IOStreamBuffer.h index c7482352e..09b7d5e57 100644 --- a/code/IOStreamBuffer.h +++ b/code/IOStreamBuffer.h @@ -41,7 +41,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include - +#include namespace Assimp { class IOStream; @@ -91,31 +91,33 @@ public: return m_filesize; } + bool readNextBlock() { + std::cout << "readNextBlock()\n"; + m_stream->Seek( m_filePos, aiOrigin_CUR ); + size_t readLen = m_stream->Read( &m_cache[ 0 ], sizeof( T ), m_cacheSize ); + if ( readLen == 0 ) { + return false; + } + m_filePos += m_cacheSize; + m_cachePos = 0; + return true; + } + bool getNextLine( std::vector &buffer ) { buffer.resize( m_cacheSize ); ::memset( &buffer[ 0 ], ' ', m_cacheSize ); - if ( 0 == m_filePos ) { - size_t readLen = m_stream->Read( &m_cache[ 0 ], sizeof( T ), m_cacheSize ); - if ( readLen == 0 ) { - return false; - } - m_filePos += m_cacheSize; - } - size_t i=0; + if ( m_cachePos == m_cacheSize || 0 == m_filePos ) { + readNextBlock(); + } + size_t i = 0; while ( !IsLineEnd( m_cache[ m_cachePos ] ) ) { - if ( m_cachePos + 1 == m_cacheSize ) { - m_stream->Seek(m_filePos, aiOrigin_CUR ); - size_t readLen = m_stream->Read( &m_cache[ 0 ], sizeof( T ), m_cacheSize ); - if ( readLen == 0 ) { - return false; - } - m_filePos += m_cacheSize; - m_cachePos = 0; - } buffer[ i ] = m_cache[ m_cachePos ]; m_cachePos++; i++; + if ( m_cachePos >= m_cacheSize ) { + readNextBlock(); + } } buffer[ i ]='\n'; m_cachePos++; From 33e370a8b7c788af5ecac39afb3d67867e152066 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Fri, 21 Oct 2016 21:14:35 +0200 Subject: [PATCH 06/44] Obj-Stream-Handling: fix readin of linewise import. --- code/IOStreamBuffer.h | 12 +++++++----- code/ObjFileImporter.cpp | 14 ++++---------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/code/IOStreamBuffer.h b/code/IOStreamBuffer.h index 09b7d5e57..d6365cfac 100644 --- a/code/IOStreamBuffer.h +++ b/code/IOStreamBuffer.h @@ -92,8 +92,7 @@ public: } bool readNextBlock() { - std::cout << "readNextBlock()\n"; - m_stream->Seek( m_filePos, aiOrigin_CUR ); + m_stream->Seek( m_filePos, aiOrigin_SET ); size_t readLen = m_stream->Read( &m_cache[ 0 ], sizeof( T ), m_cacheSize ); if ( readLen == 0 ) { return false; @@ -108,7 +107,9 @@ public: ::memset( &buffer[ 0 ], ' ', m_cacheSize ); if ( m_cachePos == m_cacheSize || 0 == m_filePos ) { - readNextBlock(); + if ( !readNextBlock() ) { + return false; + } } size_t i = 0; while ( !IsLineEnd( m_cache[ m_cachePos ] ) ) { @@ -116,12 +117,13 @@ public: m_cachePos++; i++; if ( m_cachePos >= m_cacheSize ) { - readNextBlock(); + if ( !readNextBlock() ) { + return false; + } } } buffer[ i ]='\n'; m_cachePos++; - return true; } diff --git a/code/ObjFileImporter.cpp b/code/ObjFileImporter.cpp index ae070ab4e..52e544ea0 100644 --- a/code/ObjFileImporter.cpp +++ b/code/ObjFileImporter.cpp @@ -297,9 +297,7 @@ aiNode *ObjFileImporter::createNodes(const ObjFile::Model* pModel, const ObjFile // ------------------------------------------------------------------------------------------------ // Create topology data -aiMesh *ObjFileImporter::createTopology( const ObjFile::Model* pModel, const ObjFile::Object* pData, - unsigned int meshIndex ) -{ +aiMesh *ObjFileImporter::createTopology( const ObjFile::Model* pModel, const ObjFile::Object* pData, unsigned int meshIndex ) { // Checking preconditions ai_assert( NULL != pModel ); @@ -483,19 +481,15 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model* pModel, aiFace *pDestFace = &pMesh->mFaces[ outIndex ]; const bool last = ( vertexIndex == pSourceFace->m_pVertices->size() - 1 ); - if (pSourceFace->m_PrimitiveType != aiPrimitiveType_LINE || !last) - { + if (pSourceFace->m_PrimitiveType != aiPrimitiveType_LINE || !last) { pDestFace->mIndices[ outVertexIndex ] = newIndex; outVertexIndex++; } - if (pSourceFace->m_PrimitiveType == aiPrimitiveType_POINT) - { + if (pSourceFace->m_PrimitiveType == aiPrimitiveType_POINT) { outIndex++; outVertexIndex = 0; - } - else if (pSourceFace->m_PrimitiveType == aiPrimitiveType_LINE) - { + } else if (pSourceFace->m_PrimitiveType == aiPrimitiveType_LINE) { outVertexIndex = 0; if(!last) From d3a3bd9c12c8caa1ccc11f798130b1bee41979e5 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sat, 22 Oct 2016 21:03:11 +0200 Subject: [PATCH 07/44] BUgfixes regarding filepos setupBUgfixes regarding filepos setup. --- code/DefaultIOStream.h | 2 - code/IOStreamBuffer.h | 191 ++++++++++++++++++++++++----------------- 2 files changed, 111 insertions(+), 82 deletions(-) diff --git a/code/DefaultIOStream.h b/code/DefaultIOStream.h index 83bd3a9d4..ecca1a79b 100644 --- a/code/DefaultIOStream.h +++ b/code/DefaultIOStream.h @@ -114,7 +114,6 @@ private: mutable size_t mCachedSize; }; - // ---------------------------------------------------------------------------------- inline DefaultIOStream::DefaultIOStream () : mFile (NULL), @@ -124,7 +123,6 @@ inline DefaultIOStream::DefaultIOStream () : // empty } - // ---------------------------------------------------------------------------------- inline DefaultIOStream::DefaultIOStream (FILE* pFile, const std::string &strFilename) : diff --git a/code/IOStreamBuffer.h b/code/IOStreamBuffer.h index d6365cfac..5b00ef5d6 100644 --- a/code/IOStreamBuffer.h +++ b/code/IOStreamBuffer.h @@ -41,91 +41,22 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include -#include -namespace Assimp { +#include -class IOStream; +#include + +namespace Assimp { template class IOStreamBuffer { public: - IOStreamBuffer( size_t cache = 4096 ) - : m_stream( nullptr ) - , m_filesize( 0 ) - , m_cacheSize( cache ) - , m_cachePos( 0 ) - , m_filePos( 0 ) { - m_cache.resize( cache ); - std::fill( m_cache.begin(), m_cache.end(), '\0' ); - } - - ~IOStreamBuffer() { - } - - bool open( IOStream *stream ) { - if ( nullptr == stream ) { - return false; - } - - m_stream = stream; - m_filesize = m_stream->FileSize(); - if ( m_filesize == 0 ) { - return false; - } - - return true; - } - - bool close() { - if ( nullptr == m_stream ) { - return false; - } - - m_stream = nullptr; - m_filesize =0; - - return true; - } - - size_t size() const { - return m_filesize; - } - - bool readNextBlock() { - m_stream->Seek( m_filePos, aiOrigin_SET ); - size_t readLen = m_stream->Read( &m_cache[ 0 ], sizeof( T ), m_cacheSize ); - if ( readLen == 0 ) { - return false; - } - m_filePos += m_cacheSize; - m_cachePos = 0; - return true; - } - - bool getNextLine( std::vector &buffer ) { - buffer.resize( m_cacheSize ); - ::memset( &buffer[ 0 ], ' ', m_cacheSize ); - - if ( m_cachePos == m_cacheSize || 0 == m_filePos ) { - if ( !readNextBlock() ) { - return false; - } - } - size_t i = 0; - while ( !IsLineEnd( m_cache[ m_cachePos ] ) ) { - buffer[ i ] = m_cache[ m_cachePos ]; - m_cachePos++; - i++; - if ( m_cachePos >= m_cacheSize ) { - if ( !readNextBlock() ) { - return false; - } - } - } - buffer[ i ]='\n'; - m_cachePos++; - return true; - } + IOStreamBuffer( size_t cache = 4096 * 4096 ); + ~IOStreamBuffer(); + bool open( IOStream *stream ); + bool close(); + size_t size() const; + bool readNextBlock(); + bool getNextLine( std::vector &buffer ); private: IOStream *m_stream; @@ -136,4 +67,104 @@ private: size_t m_filePos; }; +template +inline +IOStreamBuffer::IOStreamBuffer( size_t cache = 4096 * 4096 ) + : m_stream( nullptr ) + , m_filesize( 0 ) + , m_cacheSize( cache ) + , m_cachePos( 0 ) + , m_filePos( 0 ) { + m_cache.resize( cache ); + std::fill( m_cache.begin(), m_cache.end(), '\0' ); +} + +template +inline +IOStreamBuffer::~IOStreamBuffer() { + // empty +} + +template +inline +bool IOStreamBuffer::open( IOStream *stream ) { + if ( nullptr == stream ) { + return false; + } + + m_stream = stream; + m_filesize = m_stream->FileSize(); + if ( m_filesize == 0 ) { + return false; + } + if ( m_filesize < m_cacheSize ) { + m_cacheSize = m_filesize; + } + + return true; +} + +template +inline +bool IOStreamBuffer::close() { + if ( nullptr == m_stream ) { + return false; + } + + m_stream = nullptr; + m_filesize = 0; + + return true; +} + +template +inline +size_t IOStreamBuffer::size() const { + return m_filesize; +} + +template +inline +bool IOStreamBuffer::readNextBlock() { + m_stream->Seek( m_filePos, aiOrigin_SET ); + size_t readLen = m_stream->Read( &m_cache[ 0 ], sizeof( T ), m_cacheSize ); + if ( readLen == 0 ) { + return false; + } + if ( readLen < m_cacheSize ) { + m_cacheSize = readLen; + } + m_filePos += m_cacheSize; + m_cachePos = 0; + + return true; +} + +template +inline +bool IOStreamBuffer::getNextLine( std::vector &buffer ) { + buffer.resize( m_cacheSize ); + ::memset( &buffer[ 0 ], '\n', m_cacheSize ); + + if ( m_cachePos == m_cacheSize || 0 == m_filePos ) { + if ( !readNextBlock() ) { + return false; + } + } + size_t i = 0; + while ( !IsLineEnd( m_cache[ m_cachePos ] ) ) { + buffer[ i ] = m_cache[ m_cachePos ]; + m_cachePos++; + i++; + if ( m_cachePos >= m_cacheSize ) { + if ( !readNextBlock() ) { + return false; + } + } + } + m_cachePos++; + + return true; +} + } // !ns Assimp From 79504c08d9f70af37315c6e35f0304c6c22405b5 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sat, 22 Oct 2016 22:14:01 +0200 Subject: [PATCH 08/44] QtViewer: fix review findings. --- tools/assimp_qt_viewer/glview.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/assimp_qt_viewer/glview.cpp b/tools/assimp_qt_viewer/glview.cpp index 7203f8a5d..5f8c313a4 100644 --- a/tools/assimp_qt_viewer/glview.cpp +++ b/tools/assimp_qt_viewer/glview.cpp @@ -325,7 +325,7 @@ void CGLView::ImportTextures(const QString& pScenePath) void CGLView::BBox_GetForNode(const aiNode& pNode, const aiMatrix4x4& pParent_TransformationMatrix, SBBox& pNodeBBox, bool& pFirstAssign) { -aiMatrix4x4 mat_trans = pParent_TransformationMatrix * pNode.mTransformation; + aiMatrix4x4 mat_trans = pParent_TransformationMatrix * pNode.mTransformation; // Check if node has meshes for(size_t idx_idx_mesh = 0; idx_idx_mesh < pNode.mNumMeshes; idx_idx_mesh++) @@ -437,7 +437,7 @@ void CGLView::LogError(const QString& pMessage) void CGLView::Draw_Node(const aiNode* pNode) { -aiMatrix4x4 mat_node = pNode->mTransformation; + aiMatrix4x4 mat_node = pNode->mTransformation; // Apply node transformation matrix. mat_node.Transpose(); @@ -516,7 +516,7 @@ void CGLView::Draw_Mesh(const size_t pMesh_Index) void CGLView::Draw_BBox(const SBBox& pBBox) { -aiVector3D vertex[8]; + aiVector3D vertex[8]; BBox_GetVertices(pBBox, vertex); // Draw @@ -592,7 +592,7 @@ void CGLView::resizeGL(int pWidth, int pHeight) void CGLView::paintGL() { -QTime time_paintbegin; + QTime time_paintbegin; time_paintbegin = QTime::currentTime(); @@ -1015,8 +1015,8 @@ void CGLView::Lighting_DisableSource(const size_t pLightNumber) void CGLView::Camera_Set(const size_t pCameraNumber) { -SHelper_Camera& hcam = mHelper_Camera;// reference with short name for conveniance. -aiVector3D up; + SHelper_Camera& hcam = mHelper_Camera;// reference with short name for conveniance. + aiVector3D up; if(mCamera_DefaultAdded || (pCameraNumber >= mScene->mNumCameras))// If default camera used then 'pCameraNumber' doesn't matter. { From 949a27a7438587ee873442b840a1908d9e0a8af4 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sat, 22 Oct 2016 23:34:56 +0200 Subject: [PATCH 09/44] New streaming interface: fix build. --- code/IOStreamBuffer.h | 2 +- code/ObjFileParser.cpp | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/code/IOStreamBuffer.h b/code/IOStreamBuffer.h index 5b00ef5d6..aeb600328 100644 --- a/code/IOStreamBuffer.h +++ b/code/IOStreamBuffer.h @@ -69,7 +69,7 @@ private: template inline -IOStreamBuffer::IOStreamBuffer( size_t cache = 4096 * 4096 ) +IOStreamBuffer::IOStreamBuffer( size_t cache ) : m_stream( nullptr ) , m_filesize( 0 ) , m_cacheSize( cache ) diff --git a/code/ObjFileParser.cpp b/code/ObjFileParser.cpp index a46d7c084..2469219f8 100644 --- a/code/ObjFileParser.cpp +++ b/code/ObjFileParser.cpp @@ -38,8 +38,6 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --------------------------------------------------------------------------- */ - - #ifndef ASSIMP_BUILD_NO_OBJ_IMPORTER #include "ObjFileParser.h" @@ -54,14 +52,15 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include - namespace Assimp { const std::string ObjFileParser::DEFAULT_MATERIAL = AI_DEFAULT_MATERIAL_NAME; // ------------------------------------------------------------------- // Constructor with loaded data and directories. -ObjFileParser::ObjFileParser( IOStreamBuffer &streamBuffer, const std::string &modelName, IOSystem *io, ProgressHandler* progress, const std::string &originalObjFileName) : +ObjFileParser::ObjFileParser( IOStreamBuffer &streamBuffer, const std::string &modelName, + IOSystem *io, ProgressHandler* progress, + const std::string &originalObjFileName) : m_DataIt(), m_DataItEnd(), m_pModel(NULL), From 8e8757f800ea06653c645b12061059b6997b8afb Mon Sep 17 00:00:00 2001 From: tomacd Date: Thu, 27 Oct 2016 19:23:43 +0200 Subject: [PATCH 10/44] Keep original materials names after RemoveRedundant materials process and export to collada --- code/ColladaExporter.cpp | 19 +++++++++++++++++-- code/RemoveRedundantMaterials.cpp | 8 +++++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/code/ColladaExporter.cpp b/code/ColladaExporter.cpp index a3bbc56ae..eb94b4e9c 100644 --- a/code/ColladaExporter.cpp +++ b/code/ColladaExporter.cpp @@ -636,9 +636,24 @@ void ColladaExporter::WriteMaterials() const aiMaterial* mat = mScene->mMaterials[a]; aiString name; - if( mat->Get( AI_MATKEY_NAME, name) != aiReturn_SUCCESS ) + if( mat->Get( AI_MATKEY_NAME, name) != aiReturn_SUCCESS ) { name = "mat"; - materials[a].name = std::string( "m") + to_string(a) + name.C_Str(); + materials[a].name = std::string( "m") + to_string(a) + name.C_Str(); + } else { + // try to use the material's name if no other material has already taken it, else append # + std::string testName = name.C_Str(); + size_t materialCountWithThisName = 0; + for( size_t i = 0; i < a; i ++ ) { + if( materials[i].name == testName ) { + materialCountWithThisName ++; + } + } + if( materialCountWithThisName == 0 ) { + materials[a].name = name.C_Str(); + } else { + materials[a].name = std::string(name.C_Str()) + to_string(materialCountWithThisName); + } + } for( std::string::iterator it = materials[a].name.begin(); it != materials[a].name.end(); ++it ) { if( !isalnum_C( *it ) ) { *it = '_'; diff --git a/code/RemoveRedundantMaterials.cpp b/code/RemoveRedundantMaterials.cpp index a3e61ae8d..a9954b946 100644 --- a/code/RemoveRedundantMaterials.cpp +++ b/code/RemoveRedundantMaterials.cpp @@ -177,12 +177,14 @@ void RemoveRedundantMatsProcess::Execute( aiScene* pScene) continue; } - // generate new names for all modified materials + // generate new names for modified materials that had no names const unsigned int idx = aiMappingTable[p]; if (ppcMaterials[idx]) { aiString sz; - sz.length = ::ai_snprintf(sz.data,MAXLEN,"JoinedMaterial_#%u",p); - ((aiMaterial*)ppcMaterials[idx])->AddProperty(&sz,AI_MATKEY_NAME); + if( ppcMaterials[idx]->Get(AI_MATKEY_NAME, sz) != AI_SUCCESS ) { + sz.length = ::ai_snprintf(sz.data,MAXLEN,"JoinedMaterial_#%u",p); + ((aiMaterial*)ppcMaterials[idx])->AddProperty(&sz,AI_MATKEY_NAME); + } } else { ppcMaterials[idx] = pScene->mMaterials[p]; } From b13c30f50e7685dcbc32d358d80ff8975f2396c8 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sat, 29 Oct 2016 19:07:30 +0200 Subject: [PATCH 11/44] Obj: Fix some small issues --- code/IOStreamBuffer.h | 52 ++++++++++++++++++++++++++++----- test/CMakeLists.txt | 1 + test/unit/TestIOStream.h | 23 +++++++++++++++ test/unit/utDefaultIOStream.cpp | 19 +----------- test/unit/utIOStreamBuffer.cpp | 28 ++++++++++++++++++ 5 files changed, 98 insertions(+), 25 deletions(-) create mode 100644 test/unit/TestIOStream.h diff --git a/code/IOStreamBuffer.h b/code/IOStreamBuffer.h index 5b00ef5d6..e82207340 100644 --- a/code/IOStreamBuffer.h +++ b/code/IOStreamBuffer.h @@ -47,15 +47,43 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace Assimp { +// --------------------------------------------------------------------------- +/** + * Implementation of a cached stream buffer. + */ template class IOStreamBuffer { public: + /// @brief The class constructor. IOStreamBuffer( size_t cache = 4096 * 4096 ); + + /// @brief The class destructor. ~IOStreamBuffer(); + + /// @brief Will open the cached access for a given stream. + /// @param stream The stream to cache. + /// @return true if successful. bool open( IOStream *stream ); + + /// @brief Will close the cached access. + /// @return true if successful. bool close(); + + /// @brief Returns the filesize. + /// @return The filesize. size_t size() const; + + /// @brief Returns the cache size. + /// @return The cache size. + size_t cacheSize() const; + + /// @brief Will read the next block. + /// @return true if successful. bool readNextBlock(); + + /// @brief Will read the next line. + /// @param buffer The buffer for the next line. + /// @return true if successful. bool getNextLine( std::vector &buffer ); private: @@ -69,14 +97,14 @@ private: template inline -IOStreamBuffer::IOStreamBuffer( size_t cache = 4096 * 4096 ) - : m_stream( nullptr ) - , m_filesize( 0 ) - , m_cacheSize( cache ) - , m_cachePos( 0 ) - , m_filePos( 0 ) { +IOStreamBuffer::IOStreamBuffer( size_t cache ) +: m_stream( nullptr ) +, m_filesize( 0 ) +, m_cacheSize( cache ) +, m_cachePos( 0 ) +, m_filePos( 0 ) { m_cache.resize( cache ); - std::fill( m_cache.begin(), m_cache.end(), '\0' ); + std::fill( m_cache.begin(), m_cache.end(), '\n' ); } template @@ -88,6 +116,10 @@ IOStreamBuffer::~IOStreamBuffer() { template inline bool IOStreamBuffer::open( IOStream *stream ) { + if ( nullptr != m_stream ) { + return false; + } + if ( nullptr == stream ) { return false; } @@ -123,6 +155,12 @@ size_t IOStreamBuffer::size() const { return m_filesize; } +template +inline +size_t IOStreamBuffer::cacheSize() const { + return m_cacheSize; +} + template inline bool IOStreamBuffer::readNextBlock() { diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 7c14dff0e..c23ad806f 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -70,6 +70,7 @@ SET( TEST_SRCS unit/utImporter.cpp unit/utImproveCacheLocality.cpp unit/utIOSystem.cpp + unit/utIOStreamBuffer.cpp unit/utIssues.cpp unit/utJoinVertices.cpp unit/utLimitBoneWeights.cpp diff --git a/test/unit/TestIOStream.h b/test/unit/TestIOStream.h new file mode 100644 index 000000000..1014a77d0 --- /dev/null +++ b/test/unit/TestIOStream.h @@ -0,0 +1,23 @@ +#pragma once + +#include "DefaultIOStream.h" + +using namespace ::Assimp; + +class TestDefaultIOStream : public DefaultIOStream { +public: + TestDefaultIOStream() + : DefaultIOStream() { + // empty + } + + TestDefaultIOStream( FILE* pFile, const std::string &strFilename ) + : DefaultIOStream( pFile, strFilename ) { + // empty + } + + virtual ~TestDefaultIOStream() { + // empty + } +}; + diff --git a/test/unit/utDefaultIOStream.cpp b/test/unit/utDefaultIOStream.cpp index 7d3c07f20..50a15437c 100644 --- a/test/unit/utDefaultIOStream.cpp +++ b/test/unit/utDefaultIOStream.cpp @@ -37,7 +37,7 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------*/ #include -#include "DefaultIOStream.h" +#include "TestIOStream.h" using namespace ::Assimp; @@ -45,23 +45,6 @@ class utDefaultIOStream : public ::testing::Test { // empty }; -class TestDefaultIOStream : public DefaultIOStream { -public: - TestDefaultIOStream() - : DefaultIOStream() { - // empty - } - - TestDefaultIOStream( FILE* pFile, const std::string &strFilename ) - : DefaultIOStream( pFile, strFilename ) { - // empty - } - - virtual ~TestDefaultIOStream() { - // empty - } -}; - TEST_F( utDefaultIOStream, FileSizeTest ) { char buffer[ L_tmpnam ]; tmpnam( buffer ); diff --git a/test/unit/utIOStreamBuffer.cpp b/test/unit/utIOStreamBuffer.cpp index 9d8d6ad96..ec70f759b 100644 --- a/test/unit/utIOStreamBuffer.cpp +++ b/test/unit/utIOStreamBuffer.cpp @@ -41,6 +41,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "UnitTestPCH.h" #include "IOStreamBuffer.h" +#include "TestIOStream.h" class IOStreamBufferTest : public ::testing::Test { // empty @@ -58,6 +59,33 @@ TEST_F( IOStreamBufferTest, creationTest ) { EXPECT_TRUE( ok ); } +TEST_F( IOStreamBufferTest, accessCacheSizeTest ) { + IOStreamBuffer myBuffer1; + EXPECT_NE( 0, myBuffer1.cacheSize() ); + + IOStreamBuffer myBuffer2( 100 ); + EXPECT_EQ( 100, myBuffer2.cacheSize() ); +} + +TEST_F( IOStreamBufferTest, open_close_Test ) { + IOStreamBuffer myBuffer; + + EXPECT_FALSE( myBuffer.open( nullptr ) ); + EXPECT_FALSE( myBuffer.close() ); + + char buffer[ L_tmpnam ]; + tmpnam( buffer ); + std::FILE *fs( std::fopen( buffer, "w+" ) ); + size_t written( std::fwrite( buffer, 1, sizeof( char ) * L_tmpnam, fs ) ); + std::fflush( fs ); + + TestDefaultIOStream myStream( fs, buffer ); + + EXPECT_TRUE( myBuffer.open( &myStream ) ); + EXPECT_FALSE( myBuffer.open( &myStream ) ); + EXPECT_TRUE( myBuffer.close() ); +} + TEST_F( IOStreamBufferTest, readlineTest ) { } \ No newline at end of file From 8bae6ad7b7cba442bc062c50169b55e7331737c8 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sat, 29 Oct 2016 19:11:00 +0200 Subject: [PATCH 12/44] Add missing license info. --- test/unit/TestIOStream.h | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/test/unit/TestIOStream.h b/test/unit/TestIOStream.h index 1014a77d0..974fa68cd 100644 --- a/test/unit/TestIOStream.h +++ b/test/unit/TestIOStream.h @@ -1,3 +1,42 @@ +/* +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. + +---------------------------------------------------------------------- +*/ #pragma once #include "DefaultIOStream.h" From b9261f01a3b23338781346332fee613896b78fd3 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sat, 29 Oct 2016 21:41:24 +0200 Subject: [PATCH 13/44] Obj-Stream-Handling: fix compiler-errors and warnings. --- code/IOStreamBuffer.h | 52 ++++++++++++++++++++++++++++++++-- code/ObjFileParser.cpp | 17 ++++++----- test/unit/utIOStreamBuffer.cpp | 20 ++++++++++++- 3 files changed, 77 insertions(+), 12 deletions(-) diff --git a/code/IOStreamBuffer.h b/code/IOStreamBuffer.h index e82207340..9d87942df 100644 --- a/code/IOStreamBuffer.h +++ b/code/IOStreamBuffer.h @@ -42,6 +42,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#include "ParsingUtils.h" #include @@ -81,6 +82,18 @@ public: /// @return true if successful. bool readNextBlock(); + /// @brief Returns the number of blocks to read. + /// @return The number of blocks. + size_t getNumBlocks() const; + + /// @brief Returns the current block index. + /// @return The current block index. + size_t getCurrentBlockIndex() const; + + /// @brief Returns the current file pos. + /// @return The current file pos. + size_t getFilePos() const; + /// @brief Will read the next line. /// @param buffer The buffer for the next line. /// @return true if successful. @@ -90,6 +103,8 @@ private: IOStream *m_stream; size_t m_filesize; size_t m_cacheSize; + size_t m_numBlocks; + size_t m_blockIdx; std::vector m_cache; size_t m_cachePos; size_t m_filePos; @@ -101,6 +116,8 @@ IOStreamBuffer::IOStreamBuffer( size_t cache ) : m_stream( nullptr ) , m_filesize( 0 ) , m_cacheSize( cache ) +, m_numBlocks( 0 ) +, m_blockIdx( 0 ) , m_cachePos( 0 ) , m_filePos( 0 ) { m_cache.resize( cache ); @@ -116,10 +133,12 @@ IOStreamBuffer::~IOStreamBuffer() { template inline bool IOStreamBuffer::open( IOStream *stream ) { + // file still opened! if ( nullptr != m_stream ) { return false; } + // Invalid stream pointer if ( nullptr == stream ) { return false; } @@ -133,6 +152,11 @@ bool IOStreamBuffer::open( IOStream *stream ) { m_cacheSize = m_filesize; } + m_numBlocks = m_filesize / m_cacheSize; + if ( ( m_filesize % m_cacheSize ) > 0 ) { + m_numBlocks++; + } + return true; } @@ -143,8 +167,13 @@ bool IOStreamBuffer::close() { return false; } - m_stream = nullptr; - m_filesize = 0; + // init counters and state vars + m_stream = nullptr; + m_filesize = 0; + m_numBlocks = 0; + m_blockIdx = 0; + m_cachePos = 0; + m_filePos = 0; return true; } @@ -174,10 +203,29 @@ bool IOStreamBuffer::readNextBlock() { } m_filePos += m_cacheSize; m_cachePos = 0; + m_blockIdx++; return true; } +template +inline +size_t IOStreamBuffer::getNumBlocks() const { + return m_numBlocks; +} + +template +inline +size_t IOStreamBuffer::getCurrentBlockIndex() const { + return m_blockIdx; +} + +template +inline +size_t IOStreamBuffer::getFilePos() const { + return m_filePos; +} + template inline bool IOStreamBuffer::getNextLine( std::vector &buffer ) { diff --git a/code/ObjFileParser.cpp b/code/ObjFileParser.cpp index 2469219f8..f8fd08d4a 100644 --- a/code/ObjFileParser.cpp +++ b/code/ObjFileParser.cpp @@ -110,8 +110,7 @@ void ObjFileParser::parseFile( IOStreamBuffer &streamBuffer ) { const unsigned int progressTotal = 3 * bytesToProcess; const unsigned int progressOffset = bytesToProcess; unsigned int processed = 0; - - //DataArrayIt lastDataIt = m_DataIt; + size_t lastFilePos( 0 ); bool endOfFile( false ); std::vector buffer; @@ -121,14 +120,14 @@ void ObjFileParser::parseFile( IOStreamBuffer &streamBuffer ) { m_DataIt = buffer.begin(); m_DataItEnd = buffer.end(); - // Handle progress reporting - /*processed += std::distance(lastDataIt, m_DataIt); - lastDataIt = m_DataIt; - if (processed > (progressCounter * updateProgressEveryBytes)) - { + // Handle progress reporting + const size_t filePos( streamBuffer.getFilePos() ); + if ( lastFilePos < filePos ) { + processed += filePos; + lastFilePos = filePos; progressCounter++; - m_progress->UpdateFileRead(progressOffset + processed*2, progressTotal); - }*/ + m_progress->UpdateFileRead( progressOffset + processed * 2, progressTotal ); + } // parse line switch (*m_DataIt) diff --git a/test/unit/utIOStreamBuffer.cpp b/test/unit/utIOStreamBuffer.cpp index ec70f759b..d139cfbec 100644 --- a/test/unit/utIOStreamBuffer.cpp +++ b/test/unit/utIOStreamBuffer.cpp @@ -87,5 +87,23 @@ TEST_F( IOStreamBufferTest, open_close_Test ) { } TEST_F( IOStreamBufferTest, readlineTest ) { + char buffer[ L_tmpnam ]; + tmpnam( buffer ); + std::FILE *fs( std::fopen( buffer, "w+" ) ); + size_t written( std::fwrite( buffer, 1, sizeof( char ) * L_tmpnam, fs ) ); + std::fflush( fs ); -} \ No newline at end of file + IOStreamBuffer myBuffer( 26 ); + EXPECT_EQ( 26, myBuffer.cacheSize() ); + + TestDefaultIOStream myStream( fs, buffer ); + + EXPECT_TRUE( myBuffer.open( &myStream ) ); + + EXPECT_EQ( 10, myBuffer.getNumBlocks() ); + EXPECT_TRUE( myBuffer.close() ); +} + +TEST_F( IOStreamBufferTest, accessBlockIndexTest ) { + +} From 293654fe7ca37ece540cbf756f490b321669c62a Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sun, 30 Oct 2016 08:55:11 +0100 Subject: [PATCH 14/44] Fix unittest. --- code/BlenderLoader.h | 1 - code/DefaultIOStream.h | 12 ++++++------ code/glTFExporter.cpp | 4 ++-- test/unit/TestIOStream.h | 2 +- test/unit/utIOStreamBuffer.cpp | 6 +++--- 5 files changed, 12 insertions(+), 13 deletions(-) diff --git a/code/BlenderLoader.h b/code/BlenderLoader.h index c964eee32..505409260 100644 --- a/code/BlenderLoader.h +++ b/code/BlenderLoader.h @@ -105,7 +105,6 @@ public: BlenderImporter(); ~BlenderImporter(); - public: // -------------------- diff --git a/code/DefaultIOStream.h b/code/DefaultIOStream.h index ecca1a79b..017f33f67 100644 --- a/code/DefaultIOStream.h +++ b/code/DefaultIOStream.h @@ -78,14 +78,14 @@ public: /// Read from stream size_t Read(void* pvBuffer, size_t pSize, - size_t pCount); + size_t pCount) override; // ------------------------------------------------------------------- /// Write to stream size_t Write(const void* pvBuffer, size_t pSize, - size_t pCount); + size_t pCount) override; // ------------------------------------------------------------------- /// Seek specific position @@ -94,18 +94,18 @@ public: // ------------------------------------------------------------------- /// Get current seek position - size_t Tell() const; + size_t Tell() const override; // ------------------------------------------------------------------- /// Get size of file - size_t FileSize() const; + size_t FileSize() const override; // ------------------------------------------------------------------- /// Flush file contents - void Flush(); + void Flush() override; private: - // File datastructure, using clib + // File data-structure, using clib FILE* mFile; // Filename std::string mFilename; diff --git a/code/glTFExporter.cpp b/code/glTFExporter.cpp index 07d8f8c23..f2203929c 100644 --- a/code/glTFExporter.cpp +++ b/code/glTFExporter.cpp @@ -447,7 +447,7 @@ void ExportSkin(Asset& mAsset, const aiMesh* aim, Ref& meshRef, RefjointNames.size(); ++idx_joint) { + for ( unsigned int idx_joint = 0; idx_joint < skinRef->jointNames.size(); ++idx_joint) { if (skinRef->jointNames[idx_joint]->jointName.compare(nodeRef->jointName) == 0) { addJointToJointNames = false; jointNamesIndex = idx_joint; @@ -732,7 +732,7 @@ void glTFExporter::ExportMeshes() // Create the Accessor for skinRef->inverseBindMatrices if (createSkin) { mat4* invBindMatrixData = new mat4[inverseBindMatricesData.size()]; - for (int idx_joint = 0; idx_joint < inverseBindMatricesData.size(); ++idx_joint) { + for ( unsigned int idx_joint = 0; idx_joint < inverseBindMatricesData.size(); ++idx_joint) { CopyValue(inverseBindMatricesData[idx_joint], invBindMatrixData[idx_joint]); } diff --git a/test/unit/TestIOStream.h b/test/unit/TestIOStream.h index 974fa68cd..a979caec8 100644 --- a/test/unit/TestIOStream.h +++ b/test/unit/TestIOStream.h @@ -51,7 +51,7 @@ public: } TestDefaultIOStream( FILE* pFile, const std::string &strFilename ) - : DefaultIOStream( pFile, strFilename ) { + : DefaultIOStream( pFile, strFilename ) { // empty } diff --git a/test/unit/utIOStreamBuffer.cpp b/test/unit/utIOStreamBuffer.cpp index d139cfbec..a6308fc7d 100644 --- a/test/unit/utIOStreamBuffer.cpp +++ b/test/unit/utIOStreamBuffer.cpp @@ -97,10 +97,10 @@ TEST_F( IOStreamBufferTest, readlineTest ) { EXPECT_EQ( 26, myBuffer.cacheSize() ); TestDefaultIOStream myStream( fs, buffer ); - + size_t size( myStream.FileSize() ); + size_t numBlocks( size / myBuffer.cacheSize() ); EXPECT_TRUE( myBuffer.open( &myStream ) ); - - EXPECT_EQ( 10, myBuffer.getNumBlocks() ); + EXPECT_EQ( numBlocks, myBuffer.getNumBlocks() ); EXPECT_TRUE( myBuffer.close() ); } From 810fc405a831bd434a2757f7bae3158ad7dc11a3 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sun, 30 Oct 2016 09:06:45 +0100 Subject: [PATCH 15/44] Fix build. --- code/DefaultIOStream.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/code/DefaultIOStream.h b/code/DefaultIOStream.h index 017f33f67..294c5b797 100644 --- a/code/DefaultIOStream.h +++ b/code/DefaultIOStream.h @@ -78,14 +78,14 @@ public: /// Read from stream size_t Read(void* pvBuffer, size_t pSize, - size_t pCount) override; + size_t pCount); // ------------------------------------------------------------------- /// Write to stream size_t Write(const void* pvBuffer, size_t pSize, - size_t pCount) override; + size_t pCount); // ------------------------------------------------------------------- /// Seek specific position @@ -94,15 +94,15 @@ public: // ------------------------------------------------------------------- /// Get current seek position - size_t Tell() const override; + size_t Tell() const; // ------------------------------------------------------------------- /// Get size of file - size_t FileSize() const override; + size_t FileSize() const; // ------------------------------------------------------------------- /// Flush file contents - void Flush() override; + void Flush(); private: // File data-structure, using clib From 337990510c074a4a921c669676210a3cc250eed0 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sun, 30 Oct 2016 11:16:31 +0100 Subject: [PATCH 16/44] Fix rounding issue in unittest for block calculation. --- test/unit/utIOStreamBuffer.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/unit/utIOStreamBuffer.cpp b/test/unit/utIOStreamBuffer.cpp index a6308fc7d..ded6c0eb7 100644 --- a/test/unit/utIOStreamBuffer.cpp +++ b/test/unit/utIOStreamBuffer.cpp @@ -99,6 +99,9 @@ TEST_F( IOStreamBufferTest, readlineTest ) { TestDefaultIOStream myStream( fs, buffer ); size_t size( myStream.FileSize() ); size_t numBlocks( size / myBuffer.cacheSize() ); + if ( size % myBuffer.cacheSize() > 0 ) { + numBlocks++; + } EXPECT_TRUE( myBuffer.open( &myStream ) ); EXPECT_EQ( numBlocks, myBuffer.getNumBlocks() ); EXPECT_TRUE( myBuffer.close() ); From fcac614ad09b455784b3f7968859b770e72cd243 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sun, 30 Oct 2016 19:21:38 +0100 Subject: [PATCH 17/44] Blender: fix compiler warning: FAIL already defined. --- code/BlenderScene.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/code/BlenderScene.h b/code/BlenderScene.h index 4f4ed81cc..04eb4bcad 100644 --- a/code/BlenderScene.h +++ b/code/BlenderScene.h @@ -91,8 +91,17 @@ namespace Blender { // value for the field. // -#define WARN // warn if field is missing, substitute default value -#define FAIL // fail the import if the field does not exist +// warn if field is missing, substitute default value +#ifdef WARN +# undef WARN +#endif +#define WARN + +// fail the import if the field does not exist +#ifdef FAIL +# undef FAIL +#endif +#define FAIL struct Object; struct MTex; From b5c7c9c3ac65d89c8224f57c66572db871dda1e0 Mon Sep 17 00:00:00 2001 From: rdb Date: Wed, 2 Nov 2016 18:42:16 +0100 Subject: [PATCH 18/44] Fix compile error with MSVC 2015 This patch fixes compilation with MSVC 2015. WIN32 is not a preprocessor symbol that is defined by MSVC, but _WIN32 is. --- contrib/Open3DGC/o3dgcTimer.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/Open3DGC/o3dgcTimer.h b/contrib/Open3DGC/o3dgcTimer.h index 97f575931..00fe5b653 100644 --- a/contrib/Open3DGC/o3dgcTimer.h +++ b/contrib/Open3DGC/o3dgcTimer.h @@ -26,7 +26,7 @@ THE SOFTWARE. #include "o3dgcCommon.h" -#ifdef WIN32 +#ifdef _WIN32 /* Thank you, Microsoft, for file WinDef.h with min/max redefinition. */ #define NOMINMAX #include @@ -42,7 +42,7 @@ THE SOFTWARE. namespace o3dgc { -#ifdef WIN32 +#ifdef _WIN32 class Timer { public: From b30dc8ffc978b412b3ee75d360410c6f9ebef85f Mon Sep 17 00:00:00 2001 From: Martin Gerhardy Date: Wed, 2 Nov 2016 19:54:53 +0100 Subject: [PATCH 19/44] Fixes compile issue for 3ds exporter ... when you have disabled the 3ds importer --- code/3DSExporter.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/code/3DSExporter.cpp b/code/3DSExporter.cpp index 9bef33525..d34901854 100644 --- a/code/3DSExporter.cpp +++ b/code/3DSExporter.cpp @@ -44,6 +44,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "3DSExporter.h" #include "3DSLoader.h" +#include "3DSHelper.h" #include "SceneCombiner.h" #include "SplitLargeMeshes.h" #include "StringComparison.h" @@ -54,6 +55,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. using namespace Assimp; namespace Assimp { +using namespace D3DS; namespace { From 02e038bbb6f12ee53da4ed4902da5d5d4ef3d35e Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Thu, 3 Nov 2016 18:37:02 +0100 Subject: [PATCH 20/44] Fix compiler warnings related to issue 957. --- code/3DSHelper.h | 15 ++++---- code/3DSLoader.cpp | 61 +++++++++++++++++--------------- code/AMFImporter_Postprocess.cpp | 2 +- code/ASEParser.cpp | 3 +- code/ColladaExporter.cpp | 2 +- code/ColladaLoader.cpp | 4 +-- code/ColladaParser.cpp | 2 +- code/ComputeUVMappingProcess.cpp | 10 +++--- code/GenVertexNormalsProcess.cpp | 2 +- code/IRRLoader.cpp | 8 ++--- code/IRRLoader.h | 8 ++--- code/LWOMaterial.cpp | 4 +-- code/MD3FileData.h | 12 +++---- code/MDCLoader.cpp | 2 +- code/OFFLoader.cpp | 2 +- code/ObjFileData.h | 8 ++--- code/OgreMaterial.cpp | 2 +- code/PretransformVertices.cpp | 2 +- code/ProcessHelper.cpp | 8 ++--- code/SIBImporter.cpp | 2 +- code/STLLoader.cpp | 31 ++++++++-------- code/SkeletonMeshBuilder.cpp | 2 +- code/StandardShapes.cpp | 25 ++++++------- contrib/Open3DGC/o3dgcCommon.h | 2 +- 24 files changed, 113 insertions(+), 106 deletions(-) diff --git a/code/3DSHelper.h b/code/3DSHelper.h index b1de4ee77..7a2ad3f8a 100644 --- a/code/3DSHelper.h +++ b/code/3DSHelper.h @@ -369,14 +369,13 @@ struct Material { //! Default constructor. Builds a default name for the material Material() - : - mDiffuse (0.6,0.6,0.6), // FIX ... we won't want object to be black - mSpecularExponent (0.0), - mShininessStrength (1.0), - mShading(Discreet3DS::Gouraud), - mTransparency (1.0), - mBumpHeight (1.0), - mTwoSided (false) + : mDiffuse ( ai_real( 0.6 ), ai_real( 0.6 ), ai_real( 0.6 ) ) // FIX ... we won't want object to be black + , mSpecularExponent ( ai_real( 0.0 ) ) + , mShininessStrength ( ai_real( 1.0 ) ) + , mShading(Discreet3DS::Gouraud) + , mTransparency ( ai_real( 1.0 ) ) + , mBumpHeight ( ai_real( 1.0 ) ) + , mTwoSided (false) { static int iCnt = 0; diff --git a/code/3DSLoader.cpp b/code/3DSLoader.cpp index bae3cb1e6..0a1fe776b 100644 --- a/code/3DSLoader.cpp +++ b/code/3DSLoader.cpp @@ -1166,14 +1166,15 @@ void Discreet3DSImporter::ParseMaterialChunk() case Discreet3DS::CHUNK_MAT_TRANSPARENCY: { - // This is the material's transparency - ai_real* pcf = &mScene->mMaterials.back().mTransparency; - *pcf = ParsePercentageChunk(); + // This is the material's transparency + ai_real* pcf = &mScene->mMaterials.back().mTransparency; + *pcf = ParsePercentageChunk(); - // NOTE: transparency, not opacity - if (is_qnan(*pcf)) - *pcf = 1.0; - else *pcf = 1.0 - *pcf * (ai_real)0xFFFF / 100.0; + // NOTE: transparency, not opacity + if (is_qnan(*pcf)) + *pcf = ai_real( 1.0 ); + else + *pcf = ai_real( 1.0 ) - *pcf * (ai_real)0xFFFF / ai_real( 100.0 ); } break; @@ -1199,21 +1200,23 @@ void Discreet3DSImporter::ParseMaterialChunk() case Discreet3DS::CHUNK_MAT_SHININESS_PERCENT: { // This is the shininess strength of the material - ai_real* pcf = &mScene->mMaterials.back().mShininessStrength; - *pcf = ParsePercentageChunk(); - if (is_qnan(*pcf)) - *pcf = 0.0; - else *pcf *= (ai_real)0xffff / 100.0; + ai_real* pcf = &mScene->mMaterials.back().mShininessStrength; + *pcf = ParsePercentageChunk(); + if (is_qnan(*pcf)) + *pcf = ai_real( 0.0 ); + else + *pcf *= (ai_real)0xffff / ai_real( 100.0 ); } break; case Discreet3DS::CHUNK_MAT_SELF_ILPCT: { // This is the self illumination strength of the material - ai_real f = ParsePercentageChunk(); - if (is_qnan(f)) - f = 0.0; - else f *= (ai_real)0xFFFF / 100.0; - mScene->mMaterials.back().mEmissive = aiColor3D(f,f,f); + ai_real f = ParsePercentageChunk(); + if (is_qnan(f)) + f = ai_real( 0.0 ); + else + f *= (ai_real)0xFFFF / ai_real( 100.0 ); + mScene->mMaterials.back().mEmissive = aiColor3D(f,f,f); } break; @@ -1272,7 +1275,7 @@ void Discreet3DSImporter::ParseTextureChunk(D3DS::Texture* pcOut) case Discreet3DS::CHUNK_PERCENTD: // Manually parse the blend factor - pcOut->mTextureBlend = stream->GetF8(); + pcOut->mTextureBlend = ai_real( stream->GetF8() ); break; case Discreet3DS::CHUNK_PERCENTF: @@ -1282,7 +1285,7 @@ void Discreet3DSImporter::ParseTextureChunk(D3DS::Texture* pcOut) case Discreet3DS::CHUNK_PERCENTW: // Manually parse the blend factor - pcOut->mTextureBlend = (ai_real)((uint16_t)stream->GetI2()) / 100.0; + pcOut->mTextureBlend = (ai_real)((uint16_t)stream->GetI2()) / ai_real( 100.0 ); break; case Discreet3DS::CHUNK_MAT_MAP_USCALE: @@ -1355,8 +1358,7 @@ ai_real Discreet3DSImporter::ParsePercentageChunk() // ------------------------------------------------------------------------------------------------ // Read a color chunk. If a percentage chunk is found instead it is read as a grayscale color -void Discreet3DSImporter::ParseColorChunk(aiColor3D* out, - bool acceptPercent) +void Discreet3DSImporter::ParseColorChunk( aiColor3D* out, bool acceptPercent ) { ai_assert(out != NULL); @@ -1389,13 +1391,16 @@ void Discreet3DSImporter::ParseColorChunk(aiColor3D* out, case Discreet3DS::CHUNK_LINRGBB: bGamma = true; case Discreet3DS::CHUNK_RGBB: - if (sizeof(char) * 3 > diff) { - *out = clrError; - return; + { + if ( sizeof( char ) * 3 > diff ) { + *out = clrError; + return; + } + const ai_real invVal = ai_real( 1.0 ) / ai_real( 255.0 ); + out->r = ( ai_real ) ( uint8_t ) stream->GetI1() * invVal; + out->g = ( ai_real ) ( uint8_t ) stream->GetI1() * invVal; + out->b = ( ai_real ) ( uint8_t ) stream->GetI1() * invVal; } - out->r = (ai_real)(uint8_t)stream->GetI1() / 255.0; - out->g = (ai_real)(uint8_t)stream->GetI1() / 255.0; - out->b = (ai_real)(uint8_t)stream->GetI1() / 255.0; break; // Percentage chunks are accepted, too. @@ -1409,7 +1414,7 @@ void Discreet3DSImporter::ParseColorChunk(aiColor3D* out, case Discreet3DS::CHUNK_PERCENTW: if (acceptPercent && 1 <= diff) { - out->g = out->b = out->r = (ai_real)(uint8_t)stream->GetI1() / 255.0; + out->g = out->b = out->r = (ai_real)(uint8_t)stream->GetI1() / ai_real( 255.0 ); break; } *out = clrError; diff --git a/code/AMFImporter_Postprocess.cpp b/code/AMFImporter_Postprocess.cpp index 69aad1a66..41b16035e 100644 --- a/code/AMFImporter_Postprocess.cpp +++ b/code/AMFImporter_Postprocess.cpp @@ -227,7 +227,7 @@ std::string TextureConverted_ID; // check that all textures has same size if(src_texture_4check.size() > 1) { - for(uint8_t i = 0, i_e = (src_texture_4check.size() - 1); i < i_e; i++) + for (size_t i = 0, i_e = (src_texture_4check.size() - 1); i < i_e; i++) { if((src_texture_4check[i]->Width != src_texture_4check[i + 1]->Width) || (src_texture_4check[i]->Height != src_texture_4check[i + 1]->Height) || (src_texture_4check[i]->Depth != src_texture_4check[i + 1]->Depth)) diff --git a/code/ASEParser.cpp b/code/ASEParser.cpp index d34da2578..3b3b696e5 100644 --- a/code/ASEParser.cpp +++ b/code/ASEParser.cpp @@ -618,7 +618,8 @@ void Parser::ParseLV2MaterialBlock(ASE::Material& mat) if (TokenMatch(filePtr,"MATERIAL_TRANSPARENCY",21)) { ParseLV4MeshFloat(mat.mTransparency); - mat.mTransparency = 1.0 - mat.mTransparency;continue; + mat.mTransparency = ai_real( 1.0 ) - mat.mTransparency; + continue; } // material self illumination if (TokenMatch(filePtr,"MATERIAL_SELFILLUM",18)) diff --git a/code/ColladaExporter.cpp b/code/ColladaExporter.cpp index a3bbc56ae..473883d89 100644 --- a/code/ColladaExporter.cpp +++ b/code/ColladaExporter.cpp @@ -150,7 +150,7 @@ void ColladaExporter::WriteFile() // Writes the asset header void ColladaExporter::WriteHeader() { - static const ai_real epsilon = 0.00001; + static const ai_real epsilon = ai_real( 0.00001 ); static const aiQuaternion x_rot(aiMatrix3x3( 0, -1, 0, 1, 0, 0, diff --git a/code/ColladaLoader.cpp b/code/ColladaLoader.cpp index 681f9965a..81a43754e 100644 --- a/code/ColladaLoader.cpp +++ b/code/ColladaLoader.cpp @@ -1071,7 +1071,7 @@ void ColladaLoader::CreateAnimation( aiScene* pScene, const ColladaParser& pPars continue; // resolve the data pointers for all anim channels. Find the minimum time while we're at it - ai_real startTime = 1e20, endTime = -1e20; + ai_real startTime = ai_real( 1e20 ), endTime = ai_real( -1e20 ); for( std::vector::iterator it = entries.begin(); it != entries.end(); ++it) { Collada::ChannelEntry& e = *it; @@ -1152,7 +1152,7 @@ void ColladaLoader::CreateAnimation( aiScene* pScene, const ColladaParser& pPars resultTrafos.push_back( mat); // find next point in time to evaluate. That's the closest frame larger than the current in any channel - ai_real nextTime = 1e20; + ai_real nextTime = ai_real( 1e20 ); for( std::vector::iterator it = entries.begin(); it != entries.end(); ++it) { Collada::ChannelEntry& channelElement = *it; diff --git a/code/ColladaParser.cpp b/code/ColladaParser.cpp index aaccfad40..1fd762e40 100644 --- a/code/ColladaParser.cpp +++ b/code/ColladaParser.cpp @@ -3075,7 +3075,7 @@ aiMatrix4x4 ColladaParser::CalculateResultTransform( const std::vectormNumFaces;++fidx) { diff --git a/code/GenVertexNormalsProcess.cpp b/code/GenVertexNormalsProcess.cpp index 14b7962c0..c205ac5ac 100644 --- a/code/GenVertexNormalsProcess.cpp +++ b/code/GenVertexNormalsProcess.cpp @@ -154,7 +154,7 @@ bool GenVertexNormalsProcess::GenMeshVertexNormals (aiMesh* pMesh, unsigned int // check whether we can reuse the SpatialSort of a previous step. SpatialSort* vertexFinder = NULL; SpatialSort _vertexFinder; - ai_real posEpsilon = 1e-5; + ai_real posEpsilon = ai_real( 1e-5 ); if (shared) { std::vector >* avf; shared->GetProperty(AI_SPP_SPATIAL_SORT,avf); diff --git a/code/IRRLoader.cpp b/code/IRRLoader.cpp index a1cfaf28b..6e2a9a5b5 100644 --- a/code/IRRLoader.cpp +++ b/code/IRRLoader.cpp @@ -542,7 +542,7 @@ void IRRImporter::ComputeAnimations(Node* root, aiNode* real, std::vectormPositionKeys[i]; - const ai_real dt = (i * in.speed * 0.001 ); + const ai_real dt = (i * in.speed * ai_real( 0.001 ) ); const ai_real u = dt - std::floor(dt); const int idx = (int)std::floor(dt) % size; @@ -556,9 +556,9 @@ void IRRImporter::ComputeAnimations(Node* root, aiNode* real, std::vectorAddProperty(&clr,1,AI_MATKEY_COLOR_EMISSIVE); // opacity ... either additive or default-blended, please diff --git a/code/MD3FileData.h b/code/MD3FileData.h index a8869264a..3a59d0d1d 100644 --- a/code/MD3FileData.h +++ b/code/MD3FileData.h @@ -261,13 +261,13 @@ inline void LatLngNormalToVec3(uint16_t p_iNormal, ai_real* p_afOut) { ai_real lat = (ai_real)(( p_iNormal >> 8u ) & 0xff); ai_real lng = (ai_real)(( p_iNormal & 0xff )); - lat *= 3.141926/128.0; - lng *= 3.141926/128.0; + const ai_real invVal( ai_real( 1.0 ) / ai_real( 128.0 ) ); + lat *= ai_real( 3.141926 ) * invVal; + lng *= ai_real( 3.141926 ) * invVal; - p_afOut[0] = std::cos(lat) * std::sin(lng); - p_afOut[1] = std::sin(lat) * std::sin(lng); - p_afOut[2] = std::cos(lng); - return; + p_afOut[ 0 ] = std::cos(lat) * std::sin(lng); + p_afOut[ 1 ] = std::sin(lat) * std::sin(lng); + p_afOut[ 2 ] = std::cos(lng); } diff --git a/code/MDCLoader.cpp b/code/MDCLoader.cpp index 50a3d9422..d97215864 100644 --- a/code/MDCLoader.cpp +++ b/code/MDCLoader.cpp @@ -408,7 +408,7 @@ void MDCImporter::InternReadFile( // copy texture coordinates pcUVCur->x = pcUVs[quak].u; - pcUVCur->y = 1.0-pcUVs[quak].v; // DX to OGL + pcUVCur->y = ai_real( 1.0 )-pcUVs[quak].v; // DX to OGL } pcVertCur->x += pcFrame->localOrigin[0] ; pcVertCur->y += pcFrame->localOrigin[1] ; diff --git a/code/OFFLoader.cpp b/code/OFFLoader.cpp index 3139bc238..cb2226bf6 100644 --- a/code/OFFLoader.cpp +++ b/code/OFFLoader.cpp @@ -242,7 +242,7 @@ void OFFImporter::InternReadFile( const std::string& pFile, pScene->mMaterials = new aiMaterial*[pScene->mNumMaterials]; aiMaterial* pcMat = new aiMaterial(); - aiColor4D clr(0.6,0.6,0.6,1.0); + aiColor4D clr( ai_real( 0.6 ), ai_real( 0.6 ), ai_real( 0.6 ), ai_real( 1.0 ) ); pcMat->AddProperty(&clr,1,AI_MATKEY_COLOR_DIFFUSE); pScene->mMaterials[0] = pcMat; diff --git a/code/ObjFileData.h b/code/ObjFileData.h index 4fc262760..23b50ef2d 100644 --- a/code/ObjFileData.h +++ b/code/ObjFileData.h @@ -201,11 +201,11 @@ struct Material //! Constructor Material() - : diffuse (0.6,0.6,0.6) - , alpha (1.0) - , shineness (0.0) + : diffuse ( ai_real( 0.6 ), ai_real( 0.6 ), ai_real( 0.6 ) ) + , alpha (ai_real( 1.0 ) ) + , shineness ( ai_real( 0.0) ) , illumination_model (1) - , ior (1.0) + , ior ( ai_real( 1.0 ) ) { // empty for (size_t i = 0; i < TextureTypeCount; ++i) diff --git a/code/OgreMaterial.cpp b/code/OgreMaterial.cpp index f9da9d584..a221ab274 100644 --- a/code/OgreMaterial.cpp +++ b/code/OgreMaterial.cpp @@ -93,7 +93,7 @@ void OgreImporter::ReadMaterials(const std::string &pFile, Assimp::IOSystem *pIO // Create materials that can be found and parsed via the IOSystem. for (size_t i=0, len=mesh->NumSubMeshes(); iGetSubMesh(i); + SubMeshXml *submesh = mesh->GetSubMesh( static_cast(i)); if (submesh && !submesh->materialRef.empty()) { aiMaterial *material = ReadMaterial(pFile, pIOHandler, submesh->materialRef); diff --git a/code/PretransformVertices.cpp b/code/PretransformVertices.cpp index 48a3e6f61..90a58e321 100644 --- a/code/PretransformVertices.cpp +++ b/code/PretransformVertices.cpp @@ -690,7 +690,7 @@ void PretransformVertices::Execute( aiScene* pScene) // find the dominant axis aiVector3D d = max-min; - const ai_real div = std::max(d.x,std::max(d.y,d.z))*0.5; + const ai_real div = std::max(d.x,std::max(d.y,d.z))*ai_real( 0.5); d = min + d * (ai_real)0.5; for (unsigned int a = 0; a < pScene->mNumMeshes; ++a) { diff --git a/code/ProcessHelper.cpp b/code/ProcessHelper.cpp index c77049061..4bfbbd5a3 100644 --- a/code/ProcessHelper.cpp +++ b/code/ProcessHelper.cpp @@ -77,8 +77,8 @@ void ConvertListToStrings(const std::string& in, std::list& out) void FindAABBTransformed (const aiMesh* mesh, aiVector3D& min, aiVector3D& max, const aiMatrix4x4& m) { - min = aiVector3D (10e10, 10e10, 10e10); - max = aiVector3D (-10e10,-10e10,-10e10); + min = aiVector3D ( ai_real( 10e10 ), ai_real( 10e10 ), ai_real( 10e10 ) ); + max = aiVector3D ( ai_real( -10e10 ), ai_real( -10e10 ), ai_real( -10e10 ) ); for (unsigned int i = 0;i < mesh->mNumVertices;++i) { const aiVector3D v = m * mesh->mVertices[i]; @@ -144,7 +144,7 @@ void FindMeshCenterTransformed (aiMesh* mesh, aiVector3D& out, // ------------------------------------------------------------------------------- ai_real ComputePositionEpsilon(const aiMesh* pMesh) { - const ai_real epsilon = 1e-4; + const ai_real epsilon = ai_real( 1e-4 ); // calculate the position bounds so we have a reliable epsilon to check position differences against aiVector3D minVec, maxVec; @@ -157,7 +157,7 @@ ai_real ComputePositionEpsilon(const aiMesh* const* pMeshes, size_t num) { ai_assert( NULL != pMeshes ); - const ai_real epsilon = 1e-4; + const ai_real epsilon = ai_real( 1e-4 ); // calculate the position bounds so we have a reliable epsilon to check position differences against aiVector3D minVec, maxVec, mi, ma; diff --git a/code/SIBImporter.cpp b/code/SIBImporter.cpp index 75a7ccf8e..05afb5198 100644 --- a/code/SIBImporter.cpp +++ b/code/SIBImporter.cpp @@ -709,7 +709,7 @@ static void ReadLightInfo(aiLight* light, StreamReaderLE* stream) // 99% and 1% percentiles. // OpenGL: I = cos(angle)^E // Solving: angle = acos(I^(1/E)) - ai_real E = 1.0 / std::max(spotExponent, (ai_real)0.00001); + ai_real E = ai_real( 1.0 ) / std::max(spotExponent, (ai_real)0.00001); ai_real inner = std::acos(std::pow((ai_real)0.99, E)); ai_real outer = std::acos(std::pow((ai_real)0.01, E)); diff --git a/code/STLLoader.cpp b/code/STLLoader.cpp index 647bd8a96..c2cffdb03 100644 --- a/code/STLLoader.cpp +++ b/code/STLLoader.cpp @@ -168,8 +168,7 @@ void addFacesToMesh(aiMesh* pMesh) // ------------------------------------------------------------------------------------------------ // Imports the given file into the given scene structure. -void STLImporter::InternReadFile( const std::string& pFile, - aiScene* pScene, IOSystem* pIOHandler) +void STLImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler ) { std::unique_ptr file( pIOHandler->Open( pFile, "rb")); @@ -189,7 +188,7 @@ void STLImporter::InternReadFile( const std::string& pFile, this->mBuffer = &mBuffer2[0]; // the default vertex color is light gray. - clrColorDefault.r = clrColorDefault.g = clrColorDefault.b = clrColorDefault.a = 0.6; + clrColorDefault.r = clrColorDefault.g = clrColorDefault.b = clrColorDefault.a = (ai_real) 0.6; // allocate a single node pScene->mRootNode = new aiNode(); @@ -217,13 +216,13 @@ void STLImporter::InternReadFile( const std::string& pFile, s.Set(AI_DEFAULT_MATERIAL_NAME); pcMat->AddProperty(&s, AI_MATKEY_NAME); - aiColor4D clrDiffuse(0.6,0.6,0.6,1.0); + aiColor4D clrDiffuse(ai_real(0.6),ai_real(0.6),ai_real(0.6),ai_real(1.0)); if (bMatClr) { clrDiffuse = clrColorDefault; } pcMat->AddProperty(&clrDiffuse,1,AI_MATKEY_COLOR_DIFFUSE); pcMat->AddProperty(&clrDiffuse,1,AI_MATKEY_COLOR_SPECULAR); - clrDiffuse = aiColor4D(0.05,0.05,0.05,1.0); + clrDiffuse = aiColor4D( ai_real( 0.05), ai_real( 0.05), ai_real( 0.05), ai_real( 1.0)); pcMat->AddProperty(&clrDiffuse,1,AI_MATKEY_COLOR_AMBIENT); pScene->mNumMaterials = 1; @@ -416,10 +415,11 @@ bool STLImporter::LoadBinaryFile() // read the default vertex color for facets bIsMaterialise = true; DefaultLogger::get()->info("STL: Taking code path for Materialise files"); - clrColorDefault.r = (*sz2++) / 255.0; - clrColorDefault.g = (*sz2++) / 255.0; - clrColorDefault.b = (*sz2++) / 255.0; - clrColorDefault.a = (*sz2++) / 255.0; + const ai_real invByte = (ai_real)1.0 / ( ai_real )255.0; + clrColorDefault.r = (*sz2++) * invByte; + clrColorDefault.g = (*sz2++) * invByte; + clrColorDefault.b = (*sz2++) * invByte; + clrColorDefault.a = (*sz2++) * invByte; break; } } @@ -481,17 +481,18 @@ bool STLImporter::LoadBinaryFile() } aiColor4D* clr = &pMesh->mColors[0][i*3]; clr->a = 1.0; + const ai_real invVal( (ai_real)1.0 / ( ai_real )31.0 ); if (bIsMaterialise) // this is reversed { - clr->r = (color & 0x31u) / 31.0; - clr->g = ((color & (0x31u<<5))>>5u) / 31.0; - clr->b = ((color & (0x31u<<10))>>10u) / 31.0; + clr->r = (color & 0x31u) *invVal; + clr->g = ((color & (0x31u<<5))>>5u) *invVal; + clr->b = ((color & (0x31u<<10))>>10u) *invVal; } else { - clr->b = (color & 0x31u) / 31.0; - clr->g = ((color & (0x31u<<5))>>5u) / 31.0; - clr->r = ((color & (0x31u<<10))>>10u) / 31.0; + clr->b = (color & 0x31u) *invVal; + clr->g = ((color & (0x31u<<5))>>5u) *invVal; + clr->r = ((color & (0x31u<<10))>>10u) *invVal; } // assign the color to all vertices of the face *(clr+1) = *clr; diff --git a/code/SkeletonMeshBuilder.cpp b/code/SkeletonMeshBuilder.cpp index c564cbc95..d929ac361 100644 --- a/code/SkeletonMeshBuilder.cpp +++ b/code/SkeletonMeshBuilder.cpp @@ -132,7 +132,7 @@ void SkeletonMeshBuilder::CreateGeometry( const aiNode* pNode) { // if the node has no children, it's an end node. Put a little knob there instead aiVector3D ownpos( pNode->mTransformation.a4, pNode->mTransformation.b4, pNode->mTransformation.c4); - ai_real sizeEstimate = ownpos.Length() * 0.18; + ai_real sizeEstimate = ownpos.Length() * ai_real( 0.18 ); mVertices.push_back( aiVector3D( -sizeEstimate, 0.0, 0.0)); mVertices.push_back( aiVector3D( 0.0, sizeEstimate, 0.0)); diff --git a/code/StandardShapes.cpp b/code/StandardShapes.cpp index 8b0b32336..eed8ddabc 100644 --- a/code/StandardShapes.cpp +++ b/code/StandardShapes.cpp @@ -193,8 +193,8 @@ unsigned int StandardShapes::MakeIcosahedron(std::vector& positions) { positions.reserve(positions.size()+60); - const ai_real t = (1.0 + 2.236067977)/2.0; - const ai_real s = std::sqrt(1.0 + t*t); + const ai_real t = ( ai_real( 1.0 )+ ai_real( 2.236067977 ) ) / ai_real( 2.0 ); + const ai_real s = std::sqrt(ai_real(1.0) + t*t); const aiVector3D v0 = aiVector3D(t,1.0, 0.0)/s; const aiVector3D v1 = aiVector3D(-t,1.0, 0.0)/s; @@ -243,9 +243,9 @@ unsigned int StandardShapes::MakeDodecahedron(std::vector& positions { positions.reserve(positions.size()+108); - const ai_real a = 1.0 / 1.7320508; - const ai_real b = std::sqrt((3.0-2.23606797f)/6.0); - const ai_real c = std::sqrt((3.0+2.23606797f)/6.0); + const ai_real a = ai_real( 1.0 ) / ai_real(1.7320508); + const ai_real b = std::sqrt(( ai_real( 3.0 )- ai_real( 2.23606797))/ ai_real( 6.0) ); + const ai_real c = std::sqrt(( ai_real( 3.0 )+ ai_real( 2.23606797f))/ ai_real( 6.0) ); const aiVector3D v0 = aiVector3D(a,a,a); const aiVector3D v1 = aiVector3D(a,a,-a); @@ -315,13 +315,14 @@ unsigned int StandardShapes::MakeTetrahedron(std::vector& positions) { positions.reserve(positions.size()+9); - const ai_real a = 1.41421/3.0; - const ai_real b = 2.4494/3.0; + const ai_real invThree = ai_real( 1.0 ) / ai_real( 3.0 ); + const ai_real a = ai_real( 1.41421 ) * invThree; + const ai_real b = ai_real( 2.4494 ) * invThree; const aiVector3D v0 = aiVector3D(0.0,0.0,1.0); - const aiVector3D v1 = aiVector3D(2*a,0,-1.0/3.0); - const aiVector3D v2 = aiVector3D(-a,b,-1.0/3.0); - const aiVector3D v3 = aiVector3D(-a,-b,-1.0/3.0); + const aiVector3D v1 = aiVector3D(2*a,0,-invThree ); + const aiVector3D v2 = aiVector3D(-a,b,-invThree ); + const aiVector3D v3 = aiVector3D(-a,-b,-invThree ); ADD_TRIANGLE(v0,v1,v2); ADD_TRIANGLE(v0,v2,v3); @@ -336,7 +337,7 @@ unsigned int StandardShapes::MakeHexahedron(std::vector& positions, bool polygons /*= false*/) { positions.reserve(positions.size()+36); - const ai_real length = 1.0/1.73205080; + const ai_real length = ai_real(1.0)/ai_real(1.73205080); const aiVector3D v0 = aiVector3D(-1.0,-1.0,-1.0)*length; const aiVector3D v1 = aiVector3D(1.0,-1.0,-1.0)*length; @@ -395,7 +396,7 @@ void StandardShapes::MakeCone(ai_real height,ai_real radius1, radius1 = std::fabs(radius1); radius2 = std::fabs(radius2); - ai_real halfHeight = height / 2.0; + ai_real halfHeight = height / ai_real(2.0); // radius1 is always the smaller one if (radius2 > radius1) diff --git a/contrib/Open3DGC/o3dgcCommon.h b/contrib/Open3DGC/o3dgcCommon.h index a9be4d885..13af4153d 100644 --- a/contrib/Open3DGC/o3dgcCommon.h +++ b/contrib/Open3DGC/o3dgcCommon.h @@ -376,7 +376,7 @@ namespace o3dgc if (quantMode == O3DGC_SC3DMC_DIAG_BB) { - Real diag = 0.0; + Real diag = Real( 0.0 ); Real r; for(unsigned long d = 0; d < dim; ++d) { From dfaea27dfc4e85bb3894250c98299f2cdc99fec2 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Thu, 3 Nov 2016 23:29:03 +0100 Subject: [PATCH 21/44] MaterialSystem: fix some findings. --- code/MaterialSystem.cpp | 51 ++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/code/MaterialSystem.cpp b/code/MaterialSystem.cpp index 088336ef3..672ebd9c5 100644 --- a/code/MaterialSystem.cpp +++ b/code/MaterialSystem.cpp @@ -42,8 +42,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * @brief Implementation of the material system of the library */ - - #include "Hash.h" #include "fast_atof.h" #include "ParsingUtils.h" @@ -71,7 +69,7 @@ aiReturn aiGetMaterialProperty(const aiMaterial* pMat, * could be improved by hashing, but it's possibly * no worth the effort (we're bound to C structures, * thus std::map or derivates are not applicable. */ - for (unsigned int i = 0; i < pMat->mNumProperties;++i) { + for ( unsigned int i = 0; i < pMat->mNumProperties; ++i ) { aiMaterialProperty* prop = pMat->mProperties[i]; if (prop /* just for safety ... */ @@ -151,14 +149,15 @@ aiReturn aiGetMaterialFloatArray(const aiMaterial* pMat, iWrite = *pMax; } // strings are zero-terminated with a 32 bit length prefix, so this is safe - const char* cur = prop->mData+4; - ai_assert(prop->mDataLength>=5 && !prop->mData[prop->mDataLength-1]); - for (unsigned int a = 0; ;++a) { + const char *cur = prop->mData + 4; + ai_assert( prop->mDataLength >= 5 ); + ai_assert( !prop->mData[ prop->mDataLength - 1 ] ); + for ( unsigned int a = 0; ;++a) { cur = fast_atoreal_move(cur,pOut[a]); - if(a==iWrite-1) { + if ( a==iWrite-1 ) { break; } - if(!IsSpace(*cur)) { + if ( !IsSpace(*cur) ) { DefaultLogger::get()->error("Material property" + std::string(pKey) + " is a string; failed to parse a float array out of it."); return AI_FAILURE; @@ -170,7 +169,6 @@ aiReturn aiGetMaterialFloatArray(const aiMaterial* pMat, } } return AI_SUCCESS; - } // ------------------------------------------------------------------------------------------------ @@ -224,8 +222,9 @@ aiReturn aiGetMaterialIntegerArray(const aiMaterial* pMat, iWrite = *pMax; } // strings are zero-terminated with a 32 bit length prefix, so this is safe - const char* cur = prop->mData+4; - ai_assert(prop->mDataLength>=5 && !prop->mData[prop->mDataLength-1]); + const char *cur = prop->mData+4; + ai_assert( prop->mDataLength >= 5 ); + ai_assert( !prop->mData[ prop->mDataLength - 1 ] ); for (unsigned int a = 0; ;++a) { pOut[a] = strtol10(cur,&cur); if(a==iWrite-1) { @@ -298,7 +297,8 @@ aiReturn aiGetMaterialString(const aiMaterial* pMat, // The string is stored as 32 but length prefix followed by zero-terminated UTF8 data pOut->length = static_cast(*reinterpret_cast(prop->mData)); - ai_assert(pOut->length+1+4==prop->mDataLength && !prop->mData[prop->mDataLength-1]); + ai_assert( pOut->length+1+4==prop->mDataLength ); + ai_assert( !prop->mData[ prop->mDataLength - 1 ] ); memcpy(pOut->data,prop->mData+4,pOut->length+1); } else { @@ -317,12 +317,12 @@ ASSIMP_API unsigned int aiGetMaterialTextureCount(const C_STRUCT aiMaterial* pMa { ai_assert (pMat != NULL); - /* Textures are always stored with ascending indices (ValidateDS provides a check, so we don't need to do it again) */ + // Textures are always stored with ascending indices (ValidateDS provides a check, so we don't need to do it again) unsigned int max = 0; for (unsigned int i = 0; i < pMat->mNumProperties;++i) { aiMaterialProperty* prop = pMat->mProperties[i]; - if (prop /* just a sanity check ... */ + if ( prop /* just a sanity check ... */ && 0 == strcmp( prop->mKey.data, _AI_MATKEY_TEXTURE_BASE ) && prop->mSemantic == type) { @@ -381,14 +381,17 @@ aiReturn aiGetMaterialTexture(const C_STRUCT aiMaterial* mat, return AI_SUCCESS; } +static const unsigned int DefaultNumAllocated = 5; + // ------------------------------------------------------------------------------------------------ // Construction. Actually the one and only way to get an aiMaterial instance -aiMaterial::aiMaterial() +aiMaterial::aiMaterial() +: mNumProperties( 0 ) +, mNumAllocated( DefaultNumAllocated ) +, mProperties( NULL ) { // Allocate 5 entries by default - mNumProperties = 0; - mNumAllocated = 5; - mProperties = new aiMaterialProperty*[5]; + mProperties = new aiMaterialProperty*[ DefaultNumAllocated ]; } // ------------------------------------------------------------------------------------------------ @@ -543,10 +546,10 @@ aiReturn aiMaterial::AddProperty (const aiString* pInput, } // ------------------------------------------------------------------------------------------------ -uint32_t Assimp :: ComputeMaterialHash(const aiMaterial* mat, bool includeMatName /*= false*/) +uint32_t Assimp::ComputeMaterialHash(const aiMaterial* mat, bool includeMatName /*= false*/) { uint32_t hash = 1503; // magic start value, chosen to be my birthday :-) - for (unsigned int i = 0; i < mat->mNumProperties;++i) { + for ( unsigned int i = 0; i < mat->mNumProperties; ++i ) { aiMaterialProperty* prop; // Exclude all properties whose first character is '?' from the hash @@ -585,15 +588,16 @@ void aiMaterial::CopyPropertyList(aiMaterial* pcDest, } } - if(pcOld) - delete[] pcOld; + if ( pcOld ) { + delete[] pcOld; + } for (unsigned int i = iOldNum; i< pcDest->mNumProperties;++i) { aiMaterialProperty* propSrc = pcSrc->mProperties[i]; // search whether we have already a property with this name -> if yes, overwrite it aiMaterialProperty* prop; - for (unsigned int q = 0; q < iOldNum;++q) { + for ( unsigned int q = 0; q < iOldNum; ++q ) { prop = pcDest->mProperties[q]; if (prop /* just for safety */ && prop->mKey == propSrc->mKey && prop->mSemantic == propSrc->mSemantic && prop->mIndex == propSrc->mIndex) { @@ -617,5 +621,4 @@ void aiMaterial::CopyPropertyList(aiMaterial* pcDest, prop->mData = new char[propSrc->mDataLength]; memcpy(prop->mData,propSrc->mData,prop->mDataLength); } - return; } From a074ca58b339172274c63dbf3bb652bc7ba55c6c Mon Sep 17 00:00:00 2001 From: AndrzejKozik Date: Fri, 4 Nov 2016 08:48:14 +0100 Subject: [PATCH 22/44] Keys interpolation fix In line 3073 there was an unproper scope of cast to double. --- code/FBXConverter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/FBXConverter.cpp b/code/FBXConverter.cpp index 1f6274d8f..4de880640 100644 --- a/code/FBXConverter.cpp +++ b/code/FBXConverter.cpp @@ -3070,7 +3070,7 @@ void Converter::InterpolateKeys( aiVectorKey* valOut, const KeyTimeList& keys, c // do the actual interpolation in double-precision arithmetics // because it is a bit sensitive to rounding errors. - const double factor = timeB == timeA ? 0. : static_cast( ( time - timeA ) / ( timeB - timeA ) ); + const double factor = timeB == timeA ? 0. : static_cast( ( time - timeA ) ) / ( timeB - timeA ); const ai_real interpValue = static_cast( valueA + ( valueB - valueA ) * factor ); result[ std::get<2>(kfl) ] = interpValue; From dcb74787853a3925a4433bfadf6124349c8550f1 Mon Sep 17 00:00:00 2001 From: AndrzejKozik Date: Fri, 4 Nov 2016 09:20:04 +0100 Subject: [PATCH 23/44] Update FBXConverter.cpp --- code/FBXConverter.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/code/FBXConverter.cpp b/code/FBXConverter.cpp index 4de880640..365d7fe65 100644 --- a/code/FBXConverter.cpp +++ b/code/FBXConverter.cpp @@ -3068,9 +3068,7 @@ void Converter::InterpolateKeys( aiVectorKey* valOut, const KeyTimeList& keys, c const KeyTimeList::value_type timeA = std::get<0>(kfl)->at( id0 ); const KeyTimeList::value_type timeB = std::get<0>(kfl)->at( id1 ); - // do the actual interpolation in double-precision arithmetics - // because it is a bit sensitive to rounding errors. - const double factor = timeB == timeA ? 0. : static_cast( ( time - timeA ) ) / ( timeB - timeA ); + const ai_real factor = timeB == timeA ? 0. : static_cast( ( time - timeA ) ) / ( timeB - timeA ); const ai_real interpValue = static_cast( valueA + ( valueB - valueA ) * factor ); result[ std::get<2>(kfl) ] = interpValue; From 499886f89e6e05e06e99f9e744c0dd44ecf7581b Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sat, 5 Nov 2016 18:41:19 +0100 Subject: [PATCH 24/44] ScenePreprocessor: fix invalid index counter. --- code/ScenePreprocessor.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/code/ScenePreprocessor.cpp b/code/ScenePreprocessor.cpp index a38a9430e..327da0b35 100644 --- a/code/ScenePreprocessor.cpp +++ b/code/ScenePreprocessor.cpp @@ -176,22 +176,22 @@ void ScenePreprocessor::ProcessAnimation (aiAnimation* anim) if (anim->mDuration == -1.) { // Position keys - for (unsigned int i = 0; i < channel->mNumPositionKeys;++i) { - aiVectorKey& key = channel->mPositionKeys[i]; + for (unsigned int j = 0; j < channel->mNumPositionKeys;++j) { + aiVectorKey& key = channel->mPositionKeys[j]; first = std::min (first, key.mTime); last = std::max (last, key.mTime); } // Scaling keys - for (unsigned int i = 0; i < channel->mNumScalingKeys;++i) { - aiVectorKey& key = channel->mScalingKeys[i]; + for (unsigned int j = 0; j < channel->mNumScalingKeys;++j ) { + aiVectorKey& key = channel->mScalingKeys[j]; first = std::min (first, key.mTime); last = std::max (last, key.mTime); } // Rotation keys - for (unsigned int i = 0; i < channel->mNumRotationKeys;++i) { - aiQuatKey& key = channel->mRotationKeys[i]; + for (unsigned int j = 0; j < channel->mNumRotationKeys;++j ) { + aiQuatKey& key = channel->mRotationKeys[ j ]; first = std::min (first, key.mTime); last = std::max (last, key.mTime); } From d4223d1fce2e9edd8d4c1be1fa48f70042b71876 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sun, 6 Nov 2016 19:36:37 +0100 Subject: [PATCH 25/44] closes https://github.com/assimp/assimp/issues/105://github.com/assimp/assimp/issues/1057 --- code/SceneCombiner.cpp | 2 +- include/assimp/metadata.h | 10 +----- include/assimp/types.h | 15 ++++---- test/CMakeLists.txt | 1 + test/unit/utTypes.cpp | 74 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 86 insertions(+), 16 deletions(-) create mode 100644 test/unit/utTypes.cpp diff --git a/code/SceneCombiner.cpp b/code/SceneCombiner.cpp index e167a3600..e19741a9d 100644 --- a/code/SceneCombiner.cpp +++ b/code/SceneCombiner.cpp @@ -740,7 +740,7 @@ void SceneCombiner::MergeBones(aiMesh* out,std::vector::const_iterator aiVertexWeight* avw = pc->mWeights = new aiVertexWeight[pc->mNumWeights]; // And copy the final weights - adjust the vertex IDs by the - // face index offset of the coresponding mesh. + // face index offset of the corresponding mesh. for (std::vector< BoneSrcIndex >::const_iterator wmit = (*it).pSrcBones.begin(); wmit != wend; ++wmit) { aiBone* pip = (*wmit).first; for (unsigned int mp = 0; mp < pip->mNumWeights;++mp,++avw) { diff --git a/include/assimp/metadata.h b/include/assimp/metadata.h index 068bbbe5e..da9d4578e 100644 --- a/include/assimp/metadata.h +++ b/include/assimp/metadata.h @@ -92,14 +92,10 @@ struct aiMetadataEntry void* mData; }; - - #ifdef __cplusplus #include - - // ------------------------------------------------------------------------------- /** * Helper functions to get the aiType enum entry for a type @@ -113,11 +109,7 @@ inline aiMetadataType GetAiType( double ) { return AI_DOUBLE; } inline aiMetadataType GetAiType( aiString ) { return AI_AISTRING; } inline aiMetadataType GetAiType( aiVector3D ) { return AI_AIVECTOR3D; } - - -#endif - - +#endif // __cplusplus // ------------------------------------------------------------------------------- /** diff --git a/include/assimp/types.h b/include/assimp/types.h index 0b48453c6..56e7c2437 100644 --- a/include/assimp/types.h +++ b/include/assimp/types.h @@ -176,11 +176,7 @@ struct aiColor3D /** Component-wise comparison */ // TODO: add epsilon? bool operator < (const aiColor3D& other) const { - return r < other.r || ( - r == other.r && (g < other.g || - (g == other.g && b < other.b) - ) - ); + return r < other.r || ( r == other.r && (g < other.g || (g == other.g && b < other.b ) ) ); } /** Component-wise addition */ @@ -210,7 +206,14 @@ struct aiColor3D /** Access a specific color component */ ai_real& operator[](unsigned int i) { - return *(&r + i); + if ( 0 == i ) { + return r; + } else if ( 1 == i ) { + return g; + } else if ( 2 == i ) { + return b; + } + return r; } /** Check whether a color is black */ diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index c23ad806f..f2584753d 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -92,6 +92,7 @@ SET( TEST_SRCS unit/utTargetAnimation.cpp unit/utTextureTransform.cpp unit/utTriangulate.cpp + unit/utTypes.cpp unit/utVertexTriangleAdjacency.cpp unit/utVersion.cpp ) diff --git a/test/unit/utTypes.cpp b/test/unit/utTypes.cpp new file mode 100644 index 000000000..47c39f989 --- /dev/null +++ b/test/unit/utTypes.cpp @@ -0,0 +1,74 @@ +/* +--------------------------------------------------------------------------- +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 + +using namespace Assimp; +class utTypes : public ::testing::Test { + // empty +}; + +TEST_F( utTypes, Color3dCpmpareOpTest ) { + aiColor3D col1( 1, 2, 3 ); + aiColor3D col2( 4, 5, 6 ); + aiColor3D col3( col1 ); + + EXPECT_FALSE( col1 == col2 ); + EXPECT_FALSE( col2 == col3 ); + EXPECT_TRUE( col1 == col3 ); + + EXPECT_TRUE( col1 != col2 ); + EXPECT_TRUE( col2 != col3 ); + EXPECT_FALSE( col1 != col3 ); +} + +TEST_F( utTypes, Color3dIndexOpTest ) { + aiColor3D col( 1, 2, 3 ); + const ai_real r = col[ 0 ]; + EXPECT_FLOAT_EQ( 1, r ); + + const ai_real g = col[ 1 ]; + EXPECT_FLOAT_EQ( 2, g ); + + const ai_real b = col[ 2 ]; + EXPECT_FLOAT_EQ( 3, b ); +} From a43634ebd0ddcb1b33d3c7a3210e5a3aa3768a4d Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sun, 6 Nov 2016 20:39:33 +0100 Subject: [PATCH 26/44] Fix build: --- include/assimp/types.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/assimp/types.h b/include/assimp/types.h index 56e7c2437..d28a93b52 100644 --- a/include/assimp/types.h +++ b/include/assimp/types.h @@ -226,7 +226,7 @@ struct aiColor3D //! Red, green and blue color values ai_real r, g, b; -} PACK_STRUCT; // !struct aiColor3D +} /*PACK_STRUCT*/; // !struct aiColor3D #include "./Compiler/poppack1.h" // ---------------------------------------------------------------------------------- From 8ffd94937e1fc0d8c3365390825f348cd845c812 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Mon, 7 Nov 2016 17:19:49 +0100 Subject: [PATCH 27/44] Fix BlenderDNA for clang cross compiler. --- code/BlenderDNA.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/code/BlenderDNA.cpp b/code/BlenderDNA.cpp index 19d08a590..e8f335bce 100644 --- a/code/BlenderDNA.cpp +++ b/code/BlenderDNA.cpp @@ -56,10 +56,10 @@ using namespace Assimp::Formatter; static bool match4(StreamReaderAny& stream, const char* string) { ai_assert( nullptr != string ); char tmp[] = { - (stream).GetI1(), - (stream).GetI1(), - (stream).GetI1(), - (stream).GetI1() + (const char)(stream).GetI1(), + (const char)(stream).GetI1(), + (const char)(stream).GetI1(), + (const char)(stream).GetI1() }; return (tmp[0]==string[0] && tmp[1]==string[1] && tmp[2]==string[2] && tmp[3]==string[3]); } @@ -346,10 +346,10 @@ void SectionParser :: Next() stream.SetCurrentPos(current.start + current.size); const char tmp[] = { - stream.GetI1(), - stream.GetI1(), - stream.GetI1(), - stream.GetI1() + (const char)stream.GetI1(), + (const char)stream.GetI1(), + (const char)stream.GetI1(), + (const char)stream.GetI1() }; current.id = std::string(tmp,tmp[3]?4:tmp[2]?3:tmp[1]?2:1); From 6d58926046c22d9174462b888ac3b7d7b51e9fc2 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Tue, 8 Nov 2016 10:38:57 +0100 Subject: [PATCH 28/44] Code reformatting. --- include/assimp/Compiler/pushpack1.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/include/assimp/Compiler/pushpack1.h b/include/assimp/Compiler/pushpack1.h index 73973c50d..94ee1e474 100644 --- a/include/assimp/Compiler/pushpack1.h +++ b/include/assimp/Compiler/pushpack1.h @@ -36,11 +36,8 @@ #endif #if defined(_MSC_VER) - // C4103: Packing was changed after the inclusion of the header, probably missing #pragma pop # pragma warning (disable : 4103) #endif #define AI_PUSHPACK_IS_DEFINED - - From 67febc41c61ebde08831bf4695b7b4b2d521acde Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Tue, 8 Nov 2016 14:53:52 +0100 Subject: [PATCH 29/44] QtViewer: some refactorings. --- tools/assimp_qt_viewer/glview.cpp | 38 ++++++++++++++++++------------- tools/assimp_qt_viewer/glview.hpp | 2 +- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/tools/assimp_qt_viewer/glview.cpp b/tools/assimp_qt_viewer/glview.cpp index 5f8c313a4..2d1e07a98 100644 --- a/tools/assimp_qt_viewer/glview.cpp +++ b/tools/assimp_qt_viewer/glview.cpp @@ -590,6 +590,24 @@ void CGLView::resizeGL(int pWidth, int pHeight) gluPerspective(mCamera_FOVY, mCamera_Viewport_AspectRatio, 1.0, 100000.0);///TODO: znear/zfar depend on scene size. } +void CGLView::drawCoordSystem() { + glBindTexture(GL_TEXTURE_1D, 0); + glBindTexture(GL_TEXTURE_2D, 0); + glBindTexture(GL_TEXTURE_3D, 0); + glEnable(GL_COLOR_MATERIAL); + glBegin(GL_LINES); + // X, -X + qglColor(QColor(Qt::red)), glVertex3f(0.0, 0.0, 0.0), glVertex3f(100000.0, 0.0, 0.0); + qglColor(QColor(Qt::cyan)), glVertex3f(0.0, 0.0, 0.0), glVertex3f(-100000.0, 0.0, 0.0); + // Y, -Y + qglColor(QColor(Qt::green)), glVertex3f(0.0, 0.0, 0.0), glVertex3f(0.0, 100000.0, 0.0); + qglColor(QColor(Qt::magenta)), glVertex3f(0.0, 0.0, 0.0), glVertex3f(0.0, -100000.0, 0.0); + // Z, -Z + qglColor(QColor(Qt::blue)), glVertex3f(0.0, 0.0, 0.0), glVertex3f(0.0, 0.0, 100000.0); + qglColor(QColor(Qt::yellow)), glVertex3f(0.0, 0.0, 0.0), glVertex3f(0.0, 0.0, -100000.0); + glEnd(); +} + void CGLView::paintGL() { QTime time_paintbegin; @@ -604,23 +622,11 @@ void CGLView::paintGL() glTranslatef(-mHelper_Camera.Translation_ToScene.x, -mHelper_Camera.Translation_ToScene.y, -mHelper_Camera.Translation_ToScene.z); glMultMatrixf((GLfloat*)&mHelper_Camera.Rotation_Scene); // Coordinate system - if(mLightingEnabled) glDisable(GL_LIGHTING);///TODO: display list + if ( mLightingEnabled ) { + glDisable( GL_LIGHTING );///TODO: display list + } + drawCoordSystem(); - glBindTexture(GL_TEXTURE_1D, 0); - glBindTexture(GL_TEXTURE_2D, 0); - glBindTexture(GL_TEXTURE_3D, 0); - glEnable(GL_COLOR_MATERIAL); - glBegin(GL_LINES); - // X, -X - qglColor(QColor(Qt::red)), glVertex3f(0.0, 0.0, 0.0), glVertex3f(100000.0, 0.0, 0.0); - qglColor(QColor(Qt::cyan)), glVertex3f(0.0, 0.0, 0.0), glVertex3f(-100000.0, 0.0, 0.0); - // Y, -Y - qglColor(QColor(Qt::green)), glVertex3f(0.0, 0.0, 0.0), glVertex3f(0.0, 100000.0, 0.0); - qglColor(QColor(Qt::magenta)), glVertex3f(0.0, 0.0, 0.0), glVertex3f(0.0, -100000.0, 0.0); - // Z, -Z - qglColor(QColor(Qt::blue)), glVertex3f(0.0, 0.0, 0.0), glVertex3f(0.0, 0.0, 100000.0); - qglColor(QColor(Qt::yellow)), glVertex3f(0.0, 0.0, 0.0), glVertex3f(0.0, 0.0, -100000.0); - glEnd(); glDisable(GL_COLOR_MATERIAL); if(mLightingEnabled) glEnable(GL_LIGHTING); diff --git a/tools/assimp_qt_viewer/glview.hpp b/tools/assimp_qt_viewer/glview.hpp index d98141653..49207a7ed 100644 --- a/tools/assimp_qt_viewer/glview.hpp +++ b/tools/assimp_qt_viewer/glview.hpp @@ -253,7 +253,7 @@ private: /********************************************************************/ protected: - + void drawCoordSystem(); /// \fn void initializeGL() override /// Overrided function for initialise OpenGL. void initializeGL() override; From 5ff1c39e02d08265a631a2cf7141e3465022972a Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Tue, 8 Nov 2016 20:34:55 +0100 Subject: [PATCH 30/44] Obj-Parser: Fix performance issue. --- code/IOStreamBuffer.h | 3 ++- test/unit/utTypes.cpp | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/code/IOStreamBuffer.h b/code/IOStreamBuffer.h index 9d87942df..fe7b2a50a 100644 --- a/code/IOStreamBuffer.h +++ b/code/IOStreamBuffer.h @@ -230,7 +230,7 @@ template inline bool IOStreamBuffer::getNextLine( std::vector &buffer ) { buffer.resize( m_cacheSize ); - ::memset( &buffer[ 0 ], '\n', m_cacheSize ); + //::memset( &buffer[ 0 ], '\n', m_cacheSize ); if ( m_cachePos == m_cacheSize || 0 == m_filePos ) { if ( !readNextBlock() ) { @@ -248,6 +248,7 @@ bool IOStreamBuffer::getNextLine( std::vector &buffer ) { } } } + buffer[ i ] = '\n'; m_cachePos++; return true; diff --git a/test/unit/utTypes.cpp b/test/unit/utTypes.cpp index 47c39f989..875f66240 100644 --- a/test/unit/utTypes.cpp +++ b/test/unit/utTypes.cpp @@ -43,6 +43,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include using namespace Assimp; + class utTypes : public ::testing::Test { // empty }; From 9f96126362cbdea903981700365df543239c900e Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Tue, 8 Nov 2016 20:35:21 +0100 Subject: [PATCH 31/44] ObjParser: remove dead code. --- code/IOStreamBuffer.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/code/IOStreamBuffer.h b/code/IOStreamBuffer.h index fe7b2a50a..8fb58e548 100644 --- a/code/IOStreamBuffer.h +++ b/code/IOStreamBuffer.h @@ -230,8 +230,6 @@ template inline bool IOStreamBuffer::getNextLine( std::vector &buffer ) { buffer.resize( m_cacheSize ); - //::memset( &buffer[ 0 ], '\n', m_cacheSize ); - if ( m_cachePos == m_cacheSize || 0 == m_filePos ) { if ( !readNextBlock() ) { return false; From ae956044aafe757e6eee4592ceebcd7cf6d5f286 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Wed, 9 Nov 2016 20:09:45 +0100 Subject: [PATCH 32/44] ObjImporter: remove unnecessary allocations of std::vector in obj-specific face. --- code/ObjFileData.h | 98 ++++++++++++++----------------------- code/ObjFileImporter.cpp | 28 +++++------ code/ObjFileParser.cpp | 37 ++++++++------ test/unit/utTriangulate.cpp | 53 +++++++------------- 4 files changed, 91 insertions(+), 125 deletions(-) diff --git a/code/ObjFileData.h b/code/ObjFileData.h index 23b50ef2d..c72175d4d 100644 --- a/code/ObjFileData.h +++ b/code/ObjFileData.h @@ -38,6 +38,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ---------------------------------------------------------------------- */ +#pragma once #ifndef OBJ_FILEDATA_H_INC #define OBJ_FILEDATA_H_INC @@ -56,59 +57,43 @@ struct Material; // ------------------------------------------------------------------------------------------------ //! \struct Face //! \brief Data structure for a simple obj-face, describes discredit,l.ation and materials -struct Face -{ +// ------------------------------------------------------------------------------------------------ +struct Face { typedef std::vector IndexArray; //! Primitive type aiPrimitiveType m_PrimitiveType; //! Vertex indices - IndexArray *m_pVertices; + IndexArray m_vertices; //! Normal indices - IndexArray *m_pNormals; + IndexArray m_normals; //! Texture coordinates indices - IndexArray *m_pTexturCoords; + IndexArray m_texturCoords; //! Pointer to assigned material Material *m_pMaterial; //! \brief Default constructor - //! \param pVertices Pointer to assigned vertex indexbuffer - //! \param pNormals Pointer to assigned normals indexbuffer - //! \param pTexCoords Pointer to assigned texture indexbuffer - Face( std::vector *pVertices, - std::vector *pNormals, - std::vector *pTexCoords, - aiPrimitiveType pt = aiPrimitiveType_POLYGON) : - m_PrimitiveType( pt ), - m_pVertices( pVertices ), - m_pNormals( pNormals ), - m_pTexturCoords( pTexCoords ), - m_pMaterial( 0L ) - { + Face( aiPrimitiveType pt = aiPrimitiveType_POLYGON) + : m_PrimitiveType( pt ) + , m_vertices() + , m_normals() + , m_texturCoords() + , m_pMaterial( 0L ) { // empty } //! \brief Destructor - ~Face() - { - delete m_pVertices; - m_pVertices = NULL; - - delete m_pNormals; - m_pNormals = NULL; - - delete m_pTexturCoords; - m_pTexturCoords = NULL; + ~Face() { + // empty } }; // ------------------------------------------------------------------------------------------------ //! \struct Object //! \brief Stores all objects of an obj-file object definition -struct Object -{ - enum ObjectType - { +// ------------------------------------------------------------------------------------------------ +struct Object { + enum ObjectType { ObjType, GroupType }; @@ -123,29 +108,24 @@ struct Object std::vector m_Meshes; //! \brief Default constructor - Object() : - m_strObjName("") - { + Object() + : m_strObjName("") { // empty } //! \brief Destructor - ~Object() - { - for (std::vector::iterator it = m_SubObjects.begin(); - it != m_SubObjects.end(); ++it) - { + ~Object() { + for ( std::vector::iterator it = m_SubObjects.begin(); it != m_SubObjects.end(); ++it) { delete *it; } - m_SubObjects.clear(); } }; // ------------------------------------------------------------------------------------------------ //! \struct Material //! \brief Data structure to store all material specific data -struct Material -{ +// ------------------------------------------------------------------------------------------------ +struct Material { //! Name of material description aiString MaterialName; @@ -201,22 +181,19 @@ struct Material //! Constructor Material() - : diffuse ( ai_real( 0.6 ), ai_real( 0.6 ), ai_real( 0.6 ) ) - , alpha (ai_real( 1.0 ) ) - , shineness ( ai_real( 0.0) ) - , illumination_model (1) - , ior ( ai_real( 1.0 ) ) - { + : diffuse ( ai_real( 0.6 ), ai_real( 0.6 ), ai_real( 0.6 ) ) + , alpha (ai_real( 1.0 ) ) + , shineness ( ai_real( 0.0) ) + , illumination_model (1) + , ior ( ai_real( 1.0 ) ) { // empty - for (size_t i = 0; i < TextureTypeCount; ++i) - { - clamp[i] = false; + for (size_t i = 0; i < TextureTypeCount; ++i) { + clamp[ i ] = false; } } // Destructor - ~Material() - { + ~Material() { // empty } }; @@ -224,6 +201,7 @@ struct Material // ------------------------------------------------------------------------------------------------ //! \struct Mesh //! \brief Data structure to store a mesh +// ------------------------------------------------------------------------------------------------ struct Mesh { static const unsigned int NoMaterial = ~0u; /// The name for the mesh @@ -254,8 +232,7 @@ struct Mesh { } /// Destructor - ~Mesh() - { + ~Mesh() { for (std::vector::iterator it = m_Faces.begin(); it != m_Faces.end(); ++it) { @@ -267,8 +244,8 @@ struct Mesh { // ------------------------------------------------------------------------------------------------ //! \struct Model //! \brief Data structure to store all obj-specific model datas -struct Model -{ +// ------------------------------------------------------------------------------------------------ +struct Model { typedef std::map* > GroupMap; typedef std::map* >::iterator GroupMapIt; typedef std::map* >::const_iterator ConstGroupMapIt; @@ -320,8 +297,7 @@ struct Model } //! \brief The class destructor - ~Model() - { + ~Model() { // Clear all stored object instances for (std::vector::iterator it = m_Objects.begin(); it != m_Objects.end(); ++it) { @@ -352,4 +328,4 @@ struct Model } // Namespace ObjFile } // Namespace Assimp -#endif +#endif // OBJ_FILEDATA_H_INC diff --git a/code/ObjFileImporter.cpp b/code/ObjFileImporter.cpp index 52e544ea0..97ae29996 100644 --- a/code/ObjFileImporter.cpp +++ b/code/ObjFileImporter.cpp @@ -326,14 +326,14 @@ aiMesh *ObjFileImporter::createTopology( const ObjFile::Model* pModel, const Obj ai_assert( NULL != inp ); if (inp->m_PrimitiveType == aiPrimitiveType_LINE) { - pMesh->mNumFaces += inp->m_pVertices->size() - 1; + pMesh->mNumFaces += inp->m_vertices.size() - 1; pMesh->mPrimitiveTypes |= aiPrimitiveType_LINE; } else if (inp->m_PrimitiveType == aiPrimitiveType_POINT) { - pMesh->mNumFaces += inp->m_pVertices->size(); + pMesh->mNumFaces += inp->m_vertices.size(); pMesh->mPrimitiveTypes |= aiPrimitiveType_POINT; } else { ++pMesh->mNumFaces; - if (inp->m_pVertices->size() > 3) { + if (inp->m_vertices.size() > 3) { pMesh->mPrimitiveTypes |= aiPrimitiveType_POLYGON; } else { pMesh->mPrimitiveTypes |= aiPrimitiveType_TRIANGLE; @@ -354,7 +354,7 @@ aiMesh *ObjFileImporter::createTopology( const ObjFile::Model* pModel, const Obj for (size_t index = 0; index < pObjMesh->m_Faces.size(); index++) { ObjFile::Face* const inp = pObjMesh->m_Faces[ index ]; if (inp->m_PrimitiveType == aiPrimitiveType_LINE) { - for(size_t i = 0; i < inp->m_pVertices->size() - 1; ++i) { + for(size_t i = 0; i < inp->m_vertices.size() - 1; ++i) { aiFace& f = pMesh->mFaces[ outIndex++ ]; uiIdxCount += f.mNumIndices = 2; f.mIndices = new unsigned int[2]; @@ -362,7 +362,7 @@ aiMesh *ObjFileImporter::createTopology( const ObjFile::Model* pModel, const Obj continue; } else if (inp->m_PrimitiveType == aiPrimitiveType_POINT) { - for(size_t i = 0; i < inp->m_pVertices->size(); ++i) { + for(size_t i = 0; i < inp->m_vertices.size(); ++i) { aiFace& f = pMesh->mFaces[ outIndex++ ]; uiIdxCount += f.mNumIndices = 1; f.mIndices = new unsigned int[1]; @@ -371,7 +371,7 @@ aiMesh *ObjFileImporter::createTopology( const ObjFile::Model* pModel, const Obj } aiFace *pFace = &pMesh->mFaces[ outIndex++ ]; - const unsigned int uiNumIndices = (unsigned int) pObjMesh->m_Faces[ index ]->m_pVertices->size(); + const unsigned int uiNumIndices = (unsigned int) pObjMesh->m_Faces[ index ]->m_vertices.size(); uiIdxCount += pFace->mNumIndices = (unsigned int) uiNumIndices; if (pFace->mNumIndices > 0) { pFace->mIndices = new unsigned int[ uiNumIndices ]; @@ -436,8 +436,8 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model* pModel, ObjFile::Face *pSourceFace = pObjMesh->m_Faces[ index ]; // Copy all index arrays - for ( size_t vertexIndex = 0, outVertexIndex = 0; vertexIndex < pSourceFace->m_pVertices->size(); vertexIndex++ ) { - const unsigned int vertex = pSourceFace->m_pVertices->at( vertexIndex ); + for ( size_t vertexIndex = 0, outVertexIndex = 0; vertexIndex < pSourceFace->m_vertices.size(); vertexIndex++ ) { + const unsigned int vertex = pSourceFace->m_vertices.at( vertexIndex ); if ( vertex >= pModel->m_Vertices.size() ) { throw DeadlyImportError( "OBJ: vertex index out of range" ); } @@ -445,8 +445,8 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model* pModel, pMesh->mVertices[ newIndex ] = pModel->m_Vertices[ vertex ]; // Copy all normals - if ( !pModel->m_Normals.empty() && vertexIndex < pSourceFace->m_pNormals->size()) { - const unsigned int normal = pSourceFace->m_pNormals->at( vertexIndex ); + if ( !pModel->m_Normals.empty() && vertexIndex < pSourceFace->m_normals.size()) { + const unsigned int normal = pSourceFace->m_normals.at( vertexIndex ); if ( normal >= pModel->m_Normals.size() ) { throw DeadlyImportError( "OBJ: vertex normal index out of range" ); } @@ -461,9 +461,9 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model* pModel, } // Copy all texture coordinates - if ( !pModel->m_TextureCoord.empty() && vertexIndex < pSourceFace->m_pTexturCoords->size()) + if ( !pModel->m_TextureCoord.empty() && vertexIndex < pSourceFace->m_texturCoords.size()) { - const unsigned int tex = pSourceFace->m_pTexturCoords->at( vertexIndex ); + const unsigned int tex = pSourceFace->m_texturCoords.at( vertexIndex ); ai_assert( tex < pModel->m_TextureCoord.size() ); if ( tex >= pModel->m_TextureCoord.size() ) @@ -480,7 +480,7 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model* pModel, // Get destination face aiFace *pDestFace = &pMesh->mFaces[ outIndex ]; - const bool last = ( vertexIndex == pSourceFace->m_pVertices->size() - 1 ); + const bool last = ( vertexIndex == pSourceFace->m_vertices.size() - 1 ); if (pSourceFace->m_PrimitiveType != aiPrimitiveType_LINE || !last) { pDestFace->mIndices[ outVertexIndex ] = newIndex; outVertexIndex++; @@ -498,7 +498,7 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model* pModel, if (vertexIndex) { if(!last) { pMesh->mVertices[ newIndex+1 ] = pMesh->mVertices[ newIndex ]; - if ( !pSourceFace->m_pNormals->empty() && !pModel->m_Normals.empty()) { + if ( !pSourceFace->m_normals.empty() && !pModel->m_Normals.empty()) { pMesh->mNormals[ newIndex+1 ] = pMesh->mNormals[newIndex ]; } if ( !pModel->m_TextureCoord.empty() ) { diff --git a/code/ObjFileParser.cpp b/code/ObjFileParser.cpp index f8fd08d4a..c9f49bcb3 100644 --- a/code/ObjFileParser.cpp +++ b/code/ObjFileParser.cpp @@ -403,7 +403,7 @@ static const std::string DefaultObjName = "defaultobject"; // ------------------------------------------------------------------- // Get values for a new face instance -void ObjFileParser::getFace(aiPrimitiveType type) { +void ObjFileParser::getFace( aiPrimitiveType type ) { copyNextLine(m_buffer, Buffersize); char *pPtr = m_buffer; char *pEnd = &pPtr[Buffersize]; @@ -412,9 +412,10 @@ void ObjFileParser::getFace(aiPrimitiveType type) { return; } - std::vector *pIndices = new std::vector; + ObjFile::Face *face = new ObjFile::Face( type ); + /*std::vector *pIndices = new std::vector; std::vector *pTexID = new std::vector; - std::vector *pNormalID = new std::vector; + std::vector *pNormalID = new std::vector;*/ bool hasNormal = false; const int vSize = m_pModel->m_Vertices.size(); @@ -463,15 +464,18 @@ void ObjFileParser::getFace(aiPrimitiveType type) { // Store parsed index if ( 0 == iPos ) { - pIndices->push_back( iVal-1 ); + face->m_vertices.push_back( iVal - 1 ); + //pIndices->push_back( iVal-1 ); } else if ( 1 == iPos ) { - pTexID->push_back( iVal-1 ); + face->m_texturCoords.push_back( iVal - 1 ); + //pTexID->push_back( iVal-1 ); } else if ( 2 == iPos ) { - pNormalID->push_back( iVal-1 ); + face->m_normals.push_back( iVal - 1 ); + //pNormalID->push_back( iVal-1 ); hasNormal = true; } else @@ -484,15 +488,18 @@ void ObjFileParser::getFace(aiPrimitiveType type) { // Store relatively index if ( 0 == iPos ) { - pIndices->push_back( vSize + iVal ); + face->m_vertices.push_back( vSize + iVal ); + //pIndices->push_back( vSize + iVal ); } else if ( 1 == iPos ) { - pTexID->push_back( vtSize + iVal ); + face->m_texturCoords.push_back( vtSize + iVal ); + //pTexID->push_back( vtSize + iVal ); } else if ( 2 == iPos ) { - pNormalID->push_back( vnSize + iVal ); + face->m_normals.push_back( vnSize + iVal ); + //pNormalID->push_back( vnSize + iVal ); hasNormal = true; } else @@ -504,19 +511,17 @@ void ObjFileParser::getFace(aiPrimitiveType type) { pPtr += iStep; } - if ( pIndices->empty() ) { + if ( face->m_vertices.empty() ) { DefaultLogger::get()->error("Obj: Ignoring empty face"); // skip line and clean up m_DataIt = skipLine( m_DataIt, m_DataItEnd, m_uiLine ); - delete pNormalID; + /*delete pNormalID; delete pTexID; - delete pIndices; + delete pIndices;*/ return; } - ObjFile::Face *face = new ObjFile::Face( pIndices, pNormalID, pTexID, type ); - // Set active material, if one set if( NULL != m_pModel->m_pCurrentMaterial ) { face->m_pMaterial = m_pModel->m_pCurrentMaterial; @@ -536,8 +541,8 @@ void ObjFileParser::getFace(aiPrimitiveType type) { // Store the face m_pModel->m_pCurrentMesh->m_Faces.push_back( face ); - m_pModel->m_pCurrentMesh->m_uiNumIndices += (unsigned int)face->m_pVertices->size(); - m_pModel->m_pCurrentMesh->m_uiUVCoordinates[ 0 ] += (unsigned int)face->m_pTexturCoords[0].size(); + m_pModel->m_pCurrentMesh->m_uiNumIndices += (unsigned int) face->m_vertices.size(); + m_pModel->m_pCurrentMesh->m_uiUVCoordinates[ 0 ] += (unsigned int) face->m_texturCoords.size(); if( !m_pModel->m_pCurrentMesh->m_hasNormals && hasNormal ) { m_pModel->m_pCurrentMesh->m_hasNormals = true; } diff --git a/test/unit/utTriangulate.cpp b/test/unit/utTriangulate.cpp index 96f7ef1d8..e9677d3e4 100644 --- a/test/unit/utTriangulate.cpp +++ b/test/unit/utTriangulate.cpp @@ -47,21 +47,17 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. using namespace std; using namespace Assimp; -class TriangulateProcessTest : public ::testing::Test -{ +class TriangulateProcessTest : public ::testing::Test { public: - virtual void SetUp(); virtual void TearDown(); protected: - aiMesh* pcMesh; TriangulateProcess* piProcess; }; -void TriangulateProcessTest::SetUp() -{ +void TriangulateProcessTest::SetUp() { piProcess = new TriangulateProcess(); pcMesh = new aiMesh(); @@ -72,24 +68,21 @@ void TriangulateProcessTest::SetUp() pcMesh->mPrimitiveTypes = aiPrimitiveType_POINT | aiPrimitiveType_LINE | aiPrimitiveType_LINE | aiPrimitiveType_POLYGON; - for (unsigned int m = 0, t = 0, q = 4; m < 1000; ++m) - { + for (unsigned int m = 0, t = 0, q = 4; m < 1000; ++m) { ++t; aiFace& face = pcMesh->mFaces[m]; face.mNumIndices = t; - if (4 == t) - { + if (4 == t) { face.mNumIndices = q++; t = 0; if (10 == q)q = 4; } face.mIndices = new unsigned int[face.mNumIndices]; - for (unsigned int p = 0; p < face.mNumIndices; ++p) - { - face.mIndices[p] = pcMesh->mNumVertices; + for (unsigned int p = 0; p < face.mNumIndices; ++p) { + face.mIndices[ p ] = pcMesh->mNumVertices; - // construct fully convex input data in ccw winding, xy plane + // construct fully convex input data in ccw winding, xy plane aiVector3D& v = pcMesh->mVertices[pcMesh->mNumVertices++]; v.z = 0.f; v.x = cos (p * (float)(AI_MATH_TWO_PI)/face.mNumIndices); @@ -98,51 +91,43 @@ void TriangulateProcessTest::SetUp() } } -void TriangulateProcessTest::TearDown() -{ +void TriangulateProcessTest::TearDown() { delete piProcess; delete pcMesh; } -TEST_F(TriangulateProcessTest, testTriangulation) -{ +TEST_F(TriangulateProcessTest, testTriangulation) { piProcess->TriangulateMesh(pcMesh); - for (unsigned int m = 0, t = 0, q = 4, max = 1000, idx = 0; m < max;++m) - { + for (unsigned int m = 0, t = 0, q = 4, max = 1000, idx = 0; m < max;++m) { ++t; aiFace& face = pcMesh->mFaces[m]; - if (4 == t) - { + if (4 == t) { t = 0; max += q-3; std::vector ait(q,false); - for (unsigned int i = 0, tt = q-2; i < tt; ++i,++m) - { + for (unsigned int i = 0, tt = q-2; i < tt; ++i,++m) { aiFace& face = pcMesh->mFaces[m]; EXPECT_EQ(3U, face.mNumIndices); - for (unsigned int qqq = 0; qqq < face.mNumIndices; ++qqq) - { + for (unsigned int qqq = 0; qqq < face.mNumIndices; ++qqq) { ait[face.mIndices[qqq]-idx] = true; } } - for (std::vector::const_iterator it = ait.begin(); it != ait.end(); ++it) - { + for (std::vector::const_iterator it = ait.begin(); it != ait.end(); ++it) { EXPECT_TRUE(*it); } --m; idx+=q; - if(++q == 10)q = 4; - } - else - { + if ( ++q == 10 ) { + q = 4; + } + } else { EXPECT_EQ(t, face.mNumIndices); - for (unsigned int i = 0; i < face.mNumIndices; ++i,++idx) - { + for (unsigned int i = 0; i < face.mNumIndices; ++i,++idx) { EXPECT_EQ(idx, face.mIndices[i]); } } From 568b459e243d251a0600e32b890166a90e626f50 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Wed, 9 Nov 2016 20:16:45 +0100 Subject: [PATCH 33/44] Fix review findings. --- code/ObjFileParser.cpp | 95 ++++++++++++------------------------------ 1 file changed, 27 insertions(+), 68 deletions(-) diff --git a/code/ObjFileParser.cpp b/code/ObjFileParser.cpp index c9f49bcb3..593ce3b6f 100644 --- a/code/ObjFileParser.cpp +++ b/code/ObjFileParser.cpp @@ -54,7 +54,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace Assimp { -const std::string ObjFileParser::DEFAULT_MATERIAL = AI_DEFAULT_MATERIAL_NAME; +static const std::string ObjFileParser::DEFAULT_MATERIAL = AI_DEFAULT_MATERIAL_NAME; // ------------------------------------------------------------------- // Constructor with loaded data and directories. @@ -87,16 +87,14 @@ ObjFileParser::ObjFileParser( IOStreamBuffer &streamBuffer, const std::str // ------------------------------------------------------------------- // Destructor -ObjFileParser::~ObjFileParser() -{ +ObjFileParser::~ObjFileParser() { delete m_pModel; m_pModel = NULL; } // ------------------------------------------------------------------- // Returns a pointer to the model instance. -ObjFile::Model *ObjFileParser::GetModel() const -{ +ObjFile::Model *ObjFileParser::GetModel() const { return m_pModel; } @@ -413,9 +411,6 @@ void ObjFileParser::getFace( aiPrimitiveType type ) { } ObjFile::Face *face = new ObjFile::Face( type ); - /*std::vector *pIndices = new std::vector; - std::vector *pTexID = new std::vector; - std::vector *pNormalID = new std::vector;*/ bool hasNormal = false; const int vSize = m_pModel->m_Vertices.size(); @@ -459,51 +454,28 @@ void ObjFileParser::getFace( aiPrimitiveType type ) { ++iStep; } - if ( iVal > 0 ) - { + if ( iVal > 0 ) { // Store parsed index - if ( 0 == iPos ) - { + if ( 0 == iPos ) { face->m_vertices.push_back( iVal - 1 ); - //pIndices->push_back( iVal-1 ); - } - else if ( 1 == iPos ) - { + } else if ( 1 == iPos ) { face->m_texturCoords.push_back( iVal - 1 ); - //pTexID->push_back( iVal-1 ); - } - else if ( 2 == iPos ) - { + } else if ( 2 == iPos ) { face->m_normals.push_back( iVal - 1 ); - //pNormalID->push_back( iVal-1 ); hasNormal = true; - } - else - { + } else { reportErrorTokenInFace(); } - } - else if ( iVal < 0 ) - { + } else if ( iVal < 0 ) { // Store relatively index - if ( 0 == iPos ) - { + if ( 0 == iPos ) { face->m_vertices.push_back( vSize + iVal ); - //pIndices->push_back( vSize + iVal ); - } - else if ( 1 == iPos ) - { + } else if ( 1 == iPos ) { face->m_texturCoords.push_back( vtSize + iVal ); - //pTexID->push_back( vtSize + iVal ); - } - else if ( 2 == iPos ) - { + } else if ( 2 == iPos ) { face->m_normals.push_back( vnSize + iVal ); - //pNormalID->push_back( vnSize + iVal ); hasNormal = true; - } - else - { + } else { reportErrorTokenInFace(); } } @@ -515,10 +487,6 @@ void ObjFileParser::getFace( aiPrimitiveType type ) { DefaultLogger::get()->error("Obj: Ignoring empty face"); // skip line and clean up m_DataIt = skipLine( m_DataIt, m_DataItEnd, m_uiLine ); - /*delete pNormalID; - delete pTexID; - delete pIndices;*/ - return; } @@ -552,8 +520,7 @@ void ObjFileParser::getFace( aiPrimitiveType type ) { // ------------------------------------------------------------------- // Get values for a new material description -void ObjFileParser::getMaterialDesc() -{ +void ObjFileParser::getMaterialDesc() { // Get next data for material data m_DataIt = getNextToken(m_DataIt, m_DataItEnd); if (m_DataIt == m_DataItEnd) { @@ -576,28 +543,26 @@ void ObjFileParser::getMaterialDesc() // If the current mesh has the same material, we simply ignore that 'usemtl' command // There is no need to create another object or even mesh here - if (m_pModel->m_pCurrentMaterial && m_pModel->m_pCurrentMaterial->MaterialName == aiString(strName)) + if ( m_pModel->m_pCurrentMaterial && m_pModel->m_pCurrentMaterial->MaterialName == aiString( strName ) ) { skip = true; + } - if (!skip) - { + if (!skip) { // Search for material std::map::iterator it = m_pModel->m_MaterialMap.find(strName); - if (it == m_pModel->m_MaterialMap.end()) - { + if (it == m_pModel->m_MaterialMap.end()) { // Not found, use default material m_pModel->m_pCurrentMaterial = m_pModel->m_pDefaultMaterial; DefaultLogger::get()->error("OBJ: failed to locate material " + strName + ", skipping"); strName = m_pModel->m_pDefaultMaterial->MaterialName.C_Str(); - } - else - { + } else { // Found, using detected material m_pModel->m_pCurrentMaterial = (*it).second; } - if (needsNewMesh(strName)) - createMesh(strName); + if ( needsNewMesh( strName ) ) { + createMesh( strName ); + } m_pModel->m_pCurrentMesh->m_uiMaterialIndex = getMaterialIndex(strName); } @@ -608,17 +573,12 @@ void ObjFileParser::getMaterialDesc() // ------------------------------------------------------------------- // Get a comment, values will be skipped -void ObjFileParser::getComment() -{ - while (m_DataIt != m_DataItEnd) - { - if ( '\n' == (*m_DataIt)) - { +void ObjFileParser::getComment() { + while (m_DataIt != m_DataItEnd) { + if ( '\n' == (*m_DataIt)) { ++m_DataIt; break; - } - else - { + } else { ++m_DataIt; } } @@ -626,8 +586,7 @@ void ObjFileParser::getComment() // ------------------------------------------------------------------- // Get material library from file. -void ObjFileParser::getMaterialLib() -{ +void ObjFileParser::getMaterialLib() { // Translate tuple m_DataIt = getNextToken(m_DataIt, m_DataItEnd); if( m_DataIt == m_DataItEnd ) { From c07aee21b79935fd84dac571c7ffb518d6446a06 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Wed, 9 Nov 2016 20:18:26 +0100 Subject: [PATCH 34/44] Fix build --- code/ObjFileParser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/ObjFileParser.cpp b/code/ObjFileParser.cpp index 593ce3b6f..cb3519e96 100644 --- a/code/ObjFileParser.cpp +++ b/code/ObjFileParser.cpp @@ -54,7 +54,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace Assimp { -static const std::string ObjFileParser::DEFAULT_MATERIAL = AI_DEFAULT_MATERIAL_NAME; +const std::string ObjFileParser::DEFAULT_MATERIAL = AI_DEFAULT_MATERIAL_NAME; // ------------------------------------------------------------------- // Constructor with loaded data and directories. From c21c70ade60b7e3fdbf2fbdef24ce336787f5b3f Mon Sep 17 00:00:00 2001 From: byteblob Date: Wed, 9 Nov 2016 22:43:01 +0100 Subject: [PATCH 35/44] added void to aiGetErrorString's args --- include/assimp/cimport.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/assimp/cimport.h b/include/assimp/cimport.h index 231230ca8..6d3fa4aea 100644 --- a/include/assimp/cimport.h +++ b/include/assimp/cimport.h @@ -337,7 +337,7 @@ ASSIMP_API void aiReleaseImport( * import process. NULL if there was no error. There can't be an error if you * got a non-NULL #aiScene from #aiImportFile/#aiImportFileEx/#aiApplyPostProcessing. */ -ASSIMP_API const char* aiGetErrorString(); +ASSIMP_API const char* aiGetErrorString(void); // -------------------------------------------------------------------------------- /** Returns whether a given file extension is supported by ASSIMP From 604b4e9723cca795f8a6a54c25bff751f668d473 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Thu, 10 Nov 2016 10:33:07 +0100 Subject: [PATCH 36/44] Make travis build faster. --- .travis.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.sh b/.travis.sh index fefd5292d..432a887bc 100755 --- a/.travis.sh +++ b/.travis.sh @@ -7,7 +7,7 @@ if [ $ANDROID ]; then ant -v -Dmy.dir=${TRAVIS_BUILD_DIR} -f ${TRAVIS_BUILD_DIR}/port/jassimp/build.xml ndk-jni else generate \ - && make \ + && make -j4 \ && sudo make install \ && sudo ldconfig \ && (cd test/unit; ../../bin/unit) \ From 1c5030c642cda0a10b0f2e674ecd8b2881f590e2 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Thu, 10 Nov 2016 16:26:17 +0100 Subject: [PATCH 37/44] Remove some whitespaces. --- CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1f0cc2b57..a08aa393b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -321,7 +321,6 @@ ELSE (ASSIMP_BUILD_NONFREE_C4D_IMPORTER) ADD_DEFINITIONS( -DASSIMP_BUILD_NO_C4D_IMPORTER ) ENDIF (ASSIMP_BUILD_NONFREE_C4D_IMPORTER) - ADD_SUBDIRECTORY( code/ ) IF ( ASSIMP_BUILD_ASSIMP_TOOLS ) IF ( WIN32 ) From c5d6ac2c30cca7fbb8e51c4e3636f483c20d7366 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Thu, 10 Nov 2016 21:39:32 +0100 Subject: [PATCH 38/44] ObjParser: remove deprecated code. --- code/MaterialSystem.cpp | 7 ++-- code/ObjFileParser.cpp | 77 ++++++++++------------------------------- code/ObjFileParser.h | 2 +- 3 files changed, 22 insertions(+), 64 deletions(-) diff --git a/code/MaterialSystem.cpp b/code/MaterialSystem.cpp index 672ebd9c5..21cd38f79 100644 --- a/code/MaterialSystem.cpp +++ b/code/MaterialSystem.cpp @@ -386,10 +386,9 @@ static const unsigned int DefaultNumAllocated = 5; // ------------------------------------------------------------------------------------------------ // Construction. Actually the one and only way to get an aiMaterial instance aiMaterial::aiMaterial() -: mNumProperties( 0 ) -, mNumAllocated( DefaultNumAllocated ) -, mProperties( NULL ) -{ +: mProperties( NULL ) +, mNumProperties( 0 ) +, mNumAllocated( DefaultNumAllocated ) { // Allocate 5 entries by default mProperties = new aiMaterialProperty*[ DefaultNumAllocated ]; } diff --git a/code/ObjFileParser.cpp b/code/ObjFileParser.cpp index cb3519e96..3cf9e5fd7 100644 --- a/code/ObjFileParser.cpp +++ b/code/ObjFileParser.cpp @@ -110,10 +110,7 @@ void ObjFileParser::parseFile( IOStreamBuffer &streamBuffer ) { unsigned int processed = 0; size_t lastFilePos( 0 ); - bool endOfFile( false ); std::vector buffer; - - //while ( m_DataIt != m_DataItEnd ) while ( streamBuffer.getNextLine( buffer ) ) { m_DataIt = buffer.begin(); m_DataItEnd = buffer.end(); @@ -128,8 +125,7 @@ void ObjFileParser::parseFile( IOStreamBuffer &streamBuffer ) { } // parse line - switch (*m_DataIt) - { + switch (*m_DataIt) { case 'v': // Parse a vertex texture coordinate { ++m_DataIt; @@ -228,8 +224,7 @@ pf_skip_line: // ------------------------------------------------------------------- // Copy the next word in a temporary buffer -void ObjFileParser::copyNextWord(char *pBuffer, size_t length) -{ +void ObjFileParser::copyNextWord(char *pBuffer, size_t length) { size_t index = 0; m_DataIt = getNextWord(m_DataIt, m_DataItEnd); while( m_DataIt != m_DataItEnd && !IsSpaceOrNewLine( *m_DataIt ) ) { @@ -245,37 +240,6 @@ void ObjFileParser::copyNextWord(char *pBuffer, size_t length) pBuffer[index] = '\0'; } -// ------------------------------------------------------------------- -// Copy the next line into a temporary buffer -void ObjFileParser::copyNextLine(char *pBuffer, size_t length) -{ - size_t index = 0u; - - // some OBJ files have line continuations using \ (such as in C++ et al) - bool continuation = false; - for (;m_DataIt != m_DataItEnd && index < length-1; ++m_DataIt) - { - const char c = *m_DataIt; - if (c == '\\') { - continuation = true; - continue; - } - - if (c == '\n' || c == '\r') { - if(continuation) { - pBuffer[ index++ ] = ' '; - continue; - } - break; - } - - continuation = false; - pBuffer[ index++ ] = c; - } - ai_assert(index < length); - pBuffer[ index ] = '\0'; -} - size_t ObjFileParser::getNumComponentsInLine() { size_t numComponents( 0 ); const char* tmp( &m_DataIt[0] ); @@ -289,7 +253,6 @@ size_t ObjFileParser::getNumComponentsInLine() { return numComponents; } -// ------------------------------------------------------------------- void ObjFileParser::getVector( std::vector &point3d_array ) { size_t numComponents = getNumComponentsInLine(); ai_real x, y, z; @@ -402,11 +365,12 @@ static const std::string DefaultObjName = "defaultobject"; // ------------------------------------------------------------------- // Get values for a new face instance void ObjFileParser::getFace( aiPrimitiveType type ) { - copyNextLine(m_buffer, Buffersize); - char *pPtr = m_buffer; - char *pEnd = &pPtr[Buffersize]; - pPtr = getNextToken(pPtr, pEnd); - if ( pPtr == pEnd || *pPtr == '\0' ) { + //copyNextLine(m_buffer, Buffersize); + //char *pPtr = m_DataIt; + //char *pPtr = m_buffer; + //char *pEnd = &pPtr[Buffersize]; + m_DataIt = getNextToken( m_DataIt, m_DataItEnd ); + if ( m_DataIt == m_DataItEnd || *m_DataIt == '\0' ) { return; } @@ -420,14 +384,14 @@ void ObjFileParser::getFace( aiPrimitiveType type ) { const bool vt = (!m_pModel->m_TextureCoord.empty()); const bool vn = (!m_pModel->m_Normals.empty()); int iStep = 0, iPos = 0; - while (pPtr != pEnd) { + while ( m_DataIt != m_DataItEnd ) { iStep = 1; - if ( IsLineEnd( *pPtr ) ) { + if ( IsLineEnd( *m_DataIt ) ) { break; } - if (*pPtr=='/' ) { + if ( *m_DataIt =='/' ) { if (type == aiPrimitiveType_POINT) { DefaultLogger::get()->error("Obj: Separator unexpected in point statement"); } @@ -439,11 +403,11 @@ void ObjFileParser::getFace( aiPrimitiveType type ) { } } iPos++; - } else if( IsSpaceOrNewLine( *pPtr ) ) { + } else if( IsSpaceOrNewLine( *m_DataIt ) ) { iPos = 0; } else { //OBJ USES 1 Base ARRAYS!!!! - const int iVal( ::atoi( pPtr ) ); + const int iVal( ::atoi( & ( *m_DataIt ) ) ); // increment iStep position based off of the sign and # of digits int tmp = iVal; @@ -480,7 +444,7 @@ void ObjFileParser::getFace( aiPrimitiveType type ) { } } } - pPtr += iStep; + m_DataIt += iStep; } if ( face->m_vertices.empty() ) { @@ -642,8 +606,7 @@ void ObjFileParser::getMaterialLib() { // ------------------------------------------------------------------- // Set a new material definition as the current material. -void ObjFileParser::getNewMaterial() -{ +void ObjFileParser::getNewMaterial() { m_DataIt = getNextToken(m_DataIt, m_DataItEnd); m_DataIt = getNextWord(m_DataIt, m_DataItEnd); if( m_DataIt == m_DataItEnd ) { @@ -656,17 +619,13 @@ void ObjFileParser::getNewMaterial() ++m_DataIt; } std::map::iterator it = m_pModel->m_MaterialMap.find( strMat ); - if ( it == m_pModel->m_MaterialMap.end() ) - { + if ( it == m_pModel->m_MaterialMap.end() ) { // Show a warning, if material was not found DefaultLogger::get()->warn("OBJ: Unsupported material requested: " + strMat); m_pModel->m_pCurrentMaterial = m_pModel->m_pDefaultMaterial; - } - else - { + } else { // Set new material - if ( needsNewMesh( strMat ) ) - { + if ( needsNewMesh( strMat ) ) { createMesh( strMat ); } m_pModel->m_pCurrentMesh->m_uiMaterialIndex = getMaterialIndex( strMat ); diff --git a/code/ObjFileParser.h b/code/ObjFileParser.h index d5058b624..55be305bb 100644 --- a/code/ObjFileParser.h +++ b/code/ObjFileParser.h @@ -85,7 +85,7 @@ private: /// Method to copy the new delimited word in the current line. void copyNextWord(char *pBuffer, size_t length); /// Method to copy the new line. - void copyNextLine(char *pBuffer, size_t length); +// void copyNextLine(char *pBuffer, size_t length); /// Stores the vector void getVector( std::vector &point3d_array ); /// Stores the following 3d vector. From cf7059f074755566a89dd1220fbbc1928ca19068 Mon Sep 17 00:00:00 2001 From: Alberto Taiuti Date: Thu, 10 Nov 2016 23:12:36 +0000 Subject: [PATCH 39/44] Fix obj .mtl file loading Fix the obj file loader by adding a new method which allows a name to be read considering the space in the middle between two words and use that for parsing the "mtlib" line in the .obj file parsing method. Before, the method used in the obj parsing function would have returned the string "mtlib NAME_OF_MTL" instead of "mtlib" only, which resulted in the .mtl file being never parsed. --- code/ObjFileParser.cpp | 2 +- code/ObjTools.h | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/code/ObjFileParser.cpp b/code/ObjFileParser.cpp index 3cf9e5fd7..27e4b27c4 100644 --- a/code/ObjFileParser.cpp +++ b/code/ObjFileParser.cpp @@ -178,7 +178,7 @@ void ObjFileParser::parseFile( IOStreamBuffer &streamBuffer ) { { std::string name; - getName(m_DataIt, m_DataItEnd, name); + getNameNoSpace(m_DataIt, m_DataItEnd, name); size_t nextSpace = name.find(" "); if (nextSpace != std::string::npos) diff --git a/code/ObjTools.h b/code/ObjTools.h index e58bf0c82..b0978a199 100644 --- a/code/ObjTools.h +++ b/code/ObjTools.h @@ -165,6 +165,47 @@ inline char_t getName( char_t it, char_t end, std::string &name ) return it; } +/** @brief Get a name from the current line. Do not preserve space + * in the middle, but trim it at the end. + * @param it set to current position + * @param end set to end of scratch buffer for readout + * @param name Separated name + * @return Current-iterator with new position + */ +template +inline char_t getNameNoSpace( char_t it, char_t end, std::string &name ) +{ + name = ""; + if( isEndOfBuffer( it, end ) ) { + return end; + } + + char *pStart = &( *it ); + while( !isEndOfBuffer( it, end ) && !IsLineEnd( *it ) + && !IsSpaceOrNewLine( *it ) ) { + ++it; + } + + while( isEndOfBuffer( it, end ) || IsLineEnd( *it ) + || IsSpaceOrNewLine( *it ) ) { + --it; + } + ++it; + + // Get name + // if there is no name, and the previous char is a separator, come back to start + while (&(*it) < pStart) { + ++it; + } + std::string strName( pStart, &(*it) ); + if ( strName.empty() ) + return it; + else + name = strName; + + return it; +} + /** @brief Get next word from given line * @param it set to current position * @param end set to end of scratch buffer for readout From 631eef49c3a368bf0f0712aa8f603ec4a48c96db Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Fri, 11 Nov 2016 12:49:05 +0100 Subject: [PATCH 40/44] BatchImporter: make validation configurable and add unittest for class. --- code/BaseImporter.cpp | 98 +++++++++++++++++++++---------------- code/BaseImporter.h | 15 +++--- code/Importer.h | 39 +++++++++------ test/CMakeLists.txt | 2 + test/unit/TestIOSystem.h | 29 +++++++++++ test/unit/utBatchLoader.cpp | 78 +++++++++++++++++++++++++++++ test/unit/utIOSystem.cpp | 31 +++--------- test/unit/utImporter.cpp | 2 + 8 files changed, 207 insertions(+), 87 deletions(-) create mode 100644 test/unit/TestIOSystem.h create mode 100644 test/unit/utBatchLoader.cpp diff --git a/code/BaseImporter.cpp b/code/BaseImporter.cpp index aa615e592..ca5264d3d 100644 --- a/code/BaseImporter.cpp +++ b/code/BaseImporter.cpp @@ -481,7 +481,7 @@ namespace Assimp BatchLoader::PropertyMap map; unsigned int id; - bool operator== (const std::string& f) { + bool operator== (const std::string& f) const { return file == f; } }; @@ -489,13 +489,22 @@ namespace Assimp // ------------------------------------------------------------------------------------------------ // BatchLoader::pimpl data structure -struct Assimp::BatchData -{ - BatchData() - : pIOSystem() - , pImporter() - , next_id(0xffff) - {} +struct Assimp::BatchData { + BatchData( IOSystem* pIO, bool validate ) + : pIOSystem( pIO ) + , pImporter( nullptr ) + , next_id(0xffff) + , validate( validate ) { + ai_assert( NULL != pIO ); + + pImporter = new Importer(); + pImporter->SetIOHandler( pIO ); + } + + ~BatchData() { + pImporter->SetIOHandler( NULL ); /* get pointer back into our possession */ + delete pImporter; + } // IO system to be used for all imports IOSystem* pIOSystem; @@ -511,53 +520,59 @@ struct Assimp::BatchData // Id for next item unsigned int next_id; + + // Validation enabled state + bool validate; }; +typedef std::list::iterator LoadReqIt; + // ------------------------------------------------------------------------------------------------ -BatchLoader::BatchLoader(IOSystem* pIO) +BatchLoader::BatchLoader(IOSystem* pIO, bool validate ) { ai_assert(NULL != pIO); - data = new BatchData(); - data->pIOSystem = pIO; - - data->pImporter = new Importer(); - data->pImporter->SetIOHandler(data->pIOSystem); + m_data = new BatchData( pIO, validate ); } // ------------------------------------------------------------------------------------------------ BatchLoader::~BatchLoader() { - // delete all scenes wthat have not been polled by the user - for (std::list::iterator it = data->requests.begin();it != data->requests.end(); ++it) { - + // delete all scenes what have not been polled by the user + for ( LoadReqIt it = m_data->requests.begin();it != m_data->requests.end(); ++it) { delete (*it).scene; } - data->pImporter->SetIOHandler(NULL); /* get pointer back into our possession */ - delete data->pImporter; - delete data; + delete m_data; } +// ------------------------------------------------------------------------------------------------ +void BatchLoader::setValidation( bool enabled ) { + m_data->validate = enabled; +} // ------------------------------------------------------------------------------------------------ -unsigned int BatchLoader::AddLoadRequest (const std::string& file, +bool BatchLoader::getValidation() const { + return m_data->validate; +} + +// ------------------------------------------------------------------------------------------------ +unsigned int BatchLoader::AddLoadRequest(const std::string& file, unsigned int steps /*= 0*/, const PropertyMap* map /*= NULL*/) { ai_assert(!file.empty()); // check whether we have this loading request already - std::list::iterator it; - for (it = data->requests.begin();it != data->requests.end(); ++it) { - + for ( LoadReqIt it = m_data->requests.begin();it != m_data->requests.end(); ++it) { // Call IOSystem's path comparison function here - if (data->pIOSystem->ComparePaths((*it).file,file)) { - + if ( m_data->pIOSystem->ComparePaths((*it).file,file)) { if (map) { - if (!((*it).map == *map)) + if ( !( ( *it ).map == *map ) ) { continue; + } } - else if (!(*it).map.empty()) + else if ( !( *it ).map.empty() ) { continue; + } (*it).refCnt++; return (*it).id; @@ -565,20 +580,18 @@ unsigned int BatchLoader::AddLoadRequest (const std::string& file, } // no, we don't have it. So add it to the queue ... - data->requests.push_back(LoadRequest(file,steps,map,data->next_id)); - return data->next_id++; + m_data->requests.push_back(LoadRequest(file,steps,map, m_data->next_id)); + return m_data->next_id++; } // ------------------------------------------------------------------------------------------------ -aiScene* BatchLoader::GetImport (unsigned int which) +aiScene* BatchLoader::GetImport( unsigned int which ) { - for (std::list::iterator it = data->requests.begin();it != data->requests.end(); ++it) { - + for ( LoadReqIt it = m_data->requests.begin();it != m_data->requests.end(); ++it) { if ((*it).id == which && (*it).loaded) { - aiScene* sc = (*it).scene; if (!(--(*it).refCnt)) { - data->requests.erase(it); + m_data->requests.erase(it); } return sc; } @@ -590,14 +603,15 @@ aiScene* BatchLoader::GetImport (unsigned int which) void BatchLoader::LoadAll() { // no threaded implementation for the moment - for (std::list::iterator it = data->requests.begin();it != data->requests.end(); ++it) { + for ( LoadReqIt it = m_data->requests.begin();it != m_data->requests.end(); ++it) { // force validation in debug builds unsigned int pp = (*it).flags; -#ifdef ASSIMP_BUILD_DEBUG - pp |= aiProcess_ValidateDataStructure; -#endif + if ( m_data->validate ) { + pp |= aiProcess_ValidateDataStructure; + } + // setup config properties if necessary - ImporterPimpl* pimpl = data->pImporter->Pimpl(); + ImporterPimpl* pimpl = m_data->pImporter->Pimpl(); pimpl->mFloatProperties = (*it).map.floats; pimpl->mIntProperties = (*it).map.ints; pimpl->mStringProperties = (*it).map.strings; @@ -608,8 +622,8 @@ void BatchLoader::LoadAll() DefaultLogger::get()->info("%%% BEGIN EXTERNAL FILE %%%"); DefaultLogger::get()->info("File: " + (*it).file); } - data->pImporter->ReadFile((*it).file,pp); - (*it).scene = data->pImporter->GetOrphanedScene(); + m_data->pImporter->ReadFile((*it).file,pp); + (*it).scene = m_data->pImporter->GetOrphanedScene(); (*it).loaded = true; DefaultLogger::get()->info("%%% END EXTERNAL FILE %%%"); diff --git a/code/BaseImporter.h b/code/BaseImporter.h index 5c9ddfa5e..7c8932a3f 100644 --- a/code/BaseImporter.h +++ b/code/BaseImporter.h @@ -347,7 +347,12 @@ public: // static utilities static void ConvertUTF8toISO8859_1( std::string& data); - enum TextFileMode { ALLOW_EMPTY, FORBID_EMPTY }; + // ------------------------------------------------------------------- + /// @brief Enum to define, if empty files are ok or not. + enum TextFileMode { + ALLOW_EMPTY, + FORBID_EMPTY + }; // ------------------------------------------------------------------- /** Utility for text file loaders which copies the contents of the @@ -382,14 +387,10 @@ public: // static utilities } } - - protected: - - /** Error description in case there was one. */ + /// Error description in case there was one. std::string m_ErrorText; - - /** Currently set progress handler */ + /// Currently set progress handler. ProgressHandler* m_progress; }; diff --git a/code/Importer.h b/code/Importer.h index a35fb80d9..a0df1a6c1 100644 --- a/code/Importer.h +++ b/code/Importer.h @@ -39,6 +39,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /** @file Importer.h mostly internal stuff for use by #Assimp::Importer */ +#pragma once #ifndef INCLUDED_AI_IMPORTER_H #define INCLUDED_AI_IMPORTER_H @@ -133,12 +134,11 @@ struct BatchData; * could, this has not yet been implemented at the moment). * * @note The class may not be used by more than one thread*/ -class BatchLoader +class ASSIMP_API BatchLoader { // friend of Importer public: - //! @cond never // ------------------------------------------------------------------- /** Wraps a full list of configuration properties for an importer. @@ -162,15 +162,29 @@ public: //! @endcond public: - - // ------------------------------------------------------------------- /** Construct a batch loader from a given IO system to be used - * to access external files */ - explicit BatchLoader(IOSystem* pIO); + * to access external files + */ + explicit BatchLoader(IOSystem* pIO, bool validate = false ); + + // ------------------------------------------------------------------- + /** The class destructor. + */ ~BatchLoader(); - + // ------------------------------------------------------------------- + /** Sets the validation step. True for enable validation during postprocess. + * @param enable True for validation. + */ + void setValidation( bool enabled ); + + // ------------------------------------------------------------------- + /** Returns the current validation step. + * @return The current validation step. + */ + bool getValidation() const; + // ------------------------------------------------------------------- /** Add a new file to the list of files to be loaded. * @param file File to be loaded @@ -185,7 +199,6 @@ public: const PropertyMap* map = NULL ); - // ------------------------------------------------------------------- /** Get an imported scene. * This polls the import from the internal request list. @@ -199,20 +212,16 @@ public: unsigned int which ); - // ------------------------------------------------------------------- /** Waits until all scenes have been loaded. This returns * immediately if no scenes are queued.*/ void LoadAll(); private: - // No need to have that in the public API ... - BatchData* data; + BatchData *m_data; }; -} +} // Namespace Assimp - - -#endif +#endif // INCLUDED_AI_IMPORTER_H diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f2584753d..b1428ce2d 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -55,7 +55,9 @@ SOURCE_GROUP( unit FILES ) SET( TEST_SRCS + unit/TestIOSystem.h unit/AssimpAPITest.cpp + unit/utBatchLoader.cpp unit/utBlenderIntermediate.cpp unit/utBlendImportAreaLight.cpp unit/utBlendImportMaterials.cpp diff --git a/test/unit/TestIOSystem.h b/test/unit/TestIOSystem.h new file mode 100644 index 000000000..cf7962f98 --- /dev/null +++ b/test/unit/TestIOSystem.h @@ -0,0 +1,29 @@ +#pragma once + +#include "UnitTestPCH.h" + +#include + +using namespace std; +using namespace Assimp; + +static const string Sep = "/"; +class TestIOSystem : public IOSystem { +public: + TestIOSystem() : IOSystem() {} + virtual ~TestIOSystem() {} + virtual bool Exists( const char* ) const { + return true; + } + virtual char getOsSeparator() const { + return Sep[ 0 ]; + } + + virtual IOStream* Open( const char* pFile, const char* pMode = "rb" ) { + return NULL; + } + + virtual void Close( IOStream* pFile ) { + // empty + } +}; diff --git a/test/unit/utBatchLoader.cpp b/test/unit/utBatchLoader.cpp new file mode 100644 index 000000000..b3d74a0aa --- /dev/null +++ b/test/unit/utBatchLoader.cpp @@ -0,0 +1,78 @@ +/* +--------------------------------------------------------------------------- +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 "Importer.h" +#include "TestIOSystem.h" + +using namespace ::Assimp; + +class BatchLoaderTest : public ::testing::Test { +public: + virtual void SetUp() { + m_io = new TestIOSystem(); + } + + virtual void TearDown() { + delete m_io; + } + +protected: + TestIOSystem* m_io; +}; + +TEST_F( BatchLoaderTest, createTest ) { + bool ok( true ); + try { + BatchLoader loader( m_io ); + } catch ( ... ) { + ok = false; + } +} + +TEST_F( BatchLoaderTest, validateAccessTest ) { + BatchLoader loader1( m_io ); + EXPECT_FALSE( loader1.getValidation() ); + loader1.setValidation( true ); + EXPECT_TRUE( loader1.getValidation() ); + + BatchLoader loader2( m_io, true ); + EXPECT_TRUE( loader2.getValidation() ); +} diff --git a/test/unit/utIOSystem.cpp b/test/unit/utIOSystem.cpp index b091e8c36..dfae55320 100644 --- a/test/unit/utIOSystem.cpp +++ b/test/unit/utIOSystem.cpp @@ -39,37 +39,22 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --------------------------------------------------------------------------- */ #include "UnitTestPCH.h" +#include "TestIOSystem.h" #include using namespace std; using namespace Assimp; -static const string Sep = "/"; -class TestIOSystem : public IOSystem { -public: - TestIOSystem() : IOSystem() {} - virtual ~TestIOSystem() {} - virtual bool Exists( const char* ) const { - return true; - } - virtual char getOsSeparator() const { - return Sep[ 0 ]; - } - - virtual IOStream* Open(const char* pFile, const char* pMode = "rb") { - return NULL; - } - - virtual void Close( IOStream* pFile) { - // empty - } -}; - class IOSystemTest : public ::testing::Test { public: - virtual void SetUp() { pImp = new TestIOSystem(); } - virtual void TearDown() { delete pImp; } + virtual void SetUp() { + pImp = new TestIOSystem(); + } + + virtual void TearDown() { + delete pImp; + } protected: TestIOSystem* pImp; diff --git a/test/unit/utImporter.cpp b/test/unit/utImporter.cpp index db71f8206..6e2d03a63 100644 --- a/test/unit/utImporter.cpp +++ b/test/unit/utImporter.cpp @@ -270,3 +270,5 @@ TEST_F(ImporterTest, testMultipleReads) EXPECT_TRUE(pImp->ReadFile(ASSIMP_TEST_MODELS_DIR "/X/BCN_Epileptic.X",flags)); //EXPECT_TRUE(pImp->ReadFile(ASSIMP_TEST_MODELS_DIR "/X/dwarf.x",flags)); # is in nonbsd } + +// ------------------------------------------------------------------------------------------------ From fdd01bda8343b65981498d3c96d8d253290e4b99 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Fri, 11 Nov 2016 12:49:05 +0100 Subject: [PATCH 41/44] BatchImporter: make validation configurable and add unittest for class. --- code/BaseImporter.cpp | 98 +++++++++++++++++++++---------------- code/BaseImporter.h | 15 +++--- code/Importer.h | 39 +++++++++------ test/CMakeLists.txt | 2 + test/unit/TestIOSystem.h | 29 +++++++++++ test/unit/utBatchLoader.cpp | 78 +++++++++++++++++++++++++++++ test/unit/utIOSystem.cpp | 31 +++--------- test/unit/utImporter.cpp | 2 + 8 files changed, 207 insertions(+), 87 deletions(-) create mode 100644 test/unit/TestIOSystem.h create mode 100644 test/unit/utBatchLoader.cpp diff --git a/code/BaseImporter.cpp b/code/BaseImporter.cpp index aa615e592..ca5264d3d 100644 --- a/code/BaseImporter.cpp +++ b/code/BaseImporter.cpp @@ -481,7 +481,7 @@ namespace Assimp BatchLoader::PropertyMap map; unsigned int id; - bool operator== (const std::string& f) { + bool operator== (const std::string& f) const { return file == f; } }; @@ -489,13 +489,22 @@ namespace Assimp // ------------------------------------------------------------------------------------------------ // BatchLoader::pimpl data structure -struct Assimp::BatchData -{ - BatchData() - : pIOSystem() - , pImporter() - , next_id(0xffff) - {} +struct Assimp::BatchData { + BatchData( IOSystem* pIO, bool validate ) + : pIOSystem( pIO ) + , pImporter( nullptr ) + , next_id(0xffff) + , validate( validate ) { + ai_assert( NULL != pIO ); + + pImporter = new Importer(); + pImporter->SetIOHandler( pIO ); + } + + ~BatchData() { + pImporter->SetIOHandler( NULL ); /* get pointer back into our possession */ + delete pImporter; + } // IO system to be used for all imports IOSystem* pIOSystem; @@ -511,53 +520,59 @@ struct Assimp::BatchData // Id for next item unsigned int next_id; + + // Validation enabled state + bool validate; }; +typedef std::list::iterator LoadReqIt; + // ------------------------------------------------------------------------------------------------ -BatchLoader::BatchLoader(IOSystem* pIO) +BatchLoader::BatchLoader(IOSystem* pIO, bool validate ) { ai_assert(NULL != pIO); - data = new BatchData(); - data->pIOSystem = pIO; - - data->pImporter = new Importer(); - data->pImporter->SetIOHandler(data->pIOSystem); + m_data = new BatchData( pIO, validate ); } // ------------------------------------------------------------------------------------------------ BatchLoader::~BatchLoader() { - // delete all scenes wthat have not been polled by the user - for (std::list::iterator it = data->requests.begin();it != data->requests.end(); ++it) { - + // delete all scenes what have not been polled by the user + for ( LoadReqIt it = m_data->requests.begin();it != m_data->requests.end(); ++it) { delete (*it).scene; } - data->pImporter->SetIOHandler(NULL); /* get pointer back into our possession */ - delete data->pImporter; - delete data; + delete m_data; } +// ------------------------------------------------------------------------------------------------ +void BatchLoader::setValidation( bool enabled ) { + m_data->validate = enabled; +} // ------------------------------------------------------------------------------------------------ -unsigned int BatchLoader::AddLoadRequest (const std::string& file, +bool BatchLoader::getValidation() const { + return m_data->validate; +} + +// ------------------------------------------------------------------------------------------------ +unsigned int BatchLoader::AddLoadRequest(const std::string& file, unsigned int steps /*= 0*/, const PropertyMap* map /*= NULL*/) { ai_assert(!file.empty()); // check whether we have this loading request already - std::list::iterator it; - for (it = data->requests.begin();it != data->requests.end(); ++it) { - + for ( LoadReqIt it = m_data->requests.begin();it != m_data->requests.end(); ++it) { // Call IOSystem's path comparison function here - if (data->pIOSystem->ComparePaths((*it).file,file)) { - + if ( m_data->pIOSystem->ComparePaths((*it).file,file)) { if (map) { - if (!((*it).map == *map)) + if ( !( ( *it ).map == *map ) ) { continue; + } } - else if (!(*it).map.empty()) + else if ( !( *it ).map.empty() ) { continue; + } (*it).refCnt++; return (*it).id; @@ -565,20 +580,18 @@ unsigned int BatchLoader::AddLoadRequest (const std::string& file, } // no, we don't have it. So add it to the queue ... - data->requests.push_back(LoadRequest(file,steps,map,data->next_id)); - return data->next_id++; + m_data->requests.push_back(LoadRequest(file,steps,map, m_data->next_id)); + return m_data->next_id++; } // ------------------------------------------------------------------------------------------------ -aiScene* BatchLoader::GetImport (unsigned int which) +aiScene* BatchLoader::GetImport( unsigned int which ) { - for (std::list::iterator it = data->requests.begin();it != data->requests.end(); ++it) { - + for ( LoadReqIt it = m_data->requests.begin();it != m_data->requests.end(); ++it) { if ((*it).id == which && (*it).loaded) { - aiScene* sc = (*it).scene; if (!(--(*it).refCnt)) { - data->requests.erase(it); + m_data->requests.erase(it); } return sc; } @@ -590,14 +603,15 @@ aiScene* BatchLoader::GetImport (unsigned int which) void BatchLoader::LoadAll() { // no threaded implementation for the moment - for (std::list::iterator it = data->requests.begin();it != data->requests.end(); ++it) { + for ( LoadReqIt it = m_data->requests.begin();it != m_data->requests.end(); ++it) { // force validation in debug builds unsigned int pp = (*it).flags; -#ifdef ASSIMP_BUILD_DEBUG - pp |= aiProcess_ValidateDataStructure; -#endif + if ( m_data->validate ) { + pp |= aiProcess_ValidateDataStructure; + } + // setup config properties if necessary - ImporterPimpl* pimpl = data->pImporter->Pimpl(); + ImporterPimpl* pimpl = m_data->pImporter->Pimpl(); pimpl->mFloatProperties = (*it).map.floats; pimpl->mIntProperties = (*it).map.ints; pimpl->mStringProperties = (*it).map.strings; @@ -608,8 +622,8 @@ void BatchLoader::LoadAll() DefaultLogger::get()->info("%%% BEGIN EXTERNAL FILE %%%"); DefaultLogger::get()->info("File: " + (*it).file); } - data->pImporter->ReadFile((*it).file,pp); - (*it).scene = data->pImporter->GetOrphanedScene(); + m_data->pImporter->ReadFile((*it).file,pp); + (*it).scene = m_data->pImporter->GetOrphanedScene(); (*it).loaded = true; DefaultLogger::get()->info("%%% END EXTERNAL FILE %%%"); diff --git a/code/BaseImporter.h b/code/BaseImporter.h index 5c9ddfa5e..7c8932a3f 100644 --- a/code/BaseImporter.h +++ b/code/BaseImporter.h @@ -347,7 +347,12 @@ public: // static utilities static void ConvertUTF8toISO8859_1( std::string& data); - enum TextFileMode { ALLOW_EMPTY, FORBID_EMPTY }; + // ------------------------------------------------------------------- + /// @brief Enum to define, if empty files are ok or not. + enum TextFileMode { + ALLOW_EMPTY, + FORBID_EMPTY + }; // ------------------------------------------------------------------- /** Utility for text file loaders which copies the contents of the @@ -382,14 +387,10 @@ public: // static utilities } } - - protected: - - /** Error description in case there was one. */ + /// Error description in case there was one. std::string m_ErrorText; - - /** Currently set progress handler */ + /// Currently set progress handler. ProgressHandler* m_progress; }; diff --git a/code/Importer.h b/code/Importer.h index a35fb80d9..a0df1a6c1 100644 --- a/code/Importer.h +++ b/code/Importer.h @@ -39,6 +39,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /** @file Importer.h mostly internal stuff for use by #Assimp::Importer */ +#pragma once #ifndef INCLUDED_AI_IMPORTER_H #define INCLUDED_AI_IMPORTER_H @@ -133,12 +134,11 @@ struct BatchData; * could, this has not yet been implemented at the moment). * * @note The class may not be used by more than one thread*/ -class BatchLoader +class ASSIMP_API BatchLoader { // friend of Importer public: - //! @cond never // ------------------------------------------------------------------- /** Wraps a full list of configuration properties for an importer. @@ -162,15 +162,29 @@ public: //! @endcond public: - - // ------------------------------------------------------------------- /** Construct a batch loader from a given IO system to be used - * to access external files */ - explicit BatchLoader(IOSystem* pIO); + * to access external files + */ + explicit BatchLoader(IOSystem* pIO, bool validate = false ); + + // ------------------------------------------------------------------- + /** The class destructor. + */ ~BatchLoader(); - + // ------------------------------------------------------------------- + /** Sets the validation step. True for enable validation during postprocess. + * @param enable True for validation. + */ + void setValidation( bool enabled ); + + // ------------------------------------------------------------------- + /** Returns the current validation step. + * @return The current validation step. + */ + bool getValidation() const; + // ------------------------------------------------------------------- /** Add a new file to the list of files to be loaded. * @param file File to be loaded @@ -185,7 +199,6 @@ public: const PropertyMap* map = NULL ); - // ------------------------------------------------------------------- /** Get an imported scene. * This polls the import from the internal request list. @@ -199,20 +212,16 @@ public: unsigned int which ); - // ------------------------------------------------------------------- /** Waits until all scenes have been loaded. This returns * immediately if no scenes are queued.*/ void LoadAll(); private: - // No need to have that in the public API ... - BatchData* data; + BatchData *m_data; }; -} +} // Namespace Assimp - - -#endif +#endif // INCLUDED_AI_IMPORTER_H diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f2584753d..b1428ce2d 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -55,7 +55,9 @@ SOURCE_GROUP( unit FILES ) SET( TEST_SRCS + unit/TestIOSystem.h unit/AssimpAPITest.cpp + unit/utBatchLoader.cpp unit/utBlenderIntermediate.cpp unit/utBlendImportAreaLight.cpp unit/utBlendImportMaterials.cpp diff --git a/test/unit/TestIOSystem.h b/test/unit/TestIOSystem.h new file mode 100644 index 000000000..cf7962f98 --- /dev/null +++ b/test/unit/TestIOSystem.h @@ -0,0 +1,29 @@ +#pragma once + +#include "UnitTestPCH.h" + +#include + +using namespace std; +using namespace Assimp; + +static const string Sep = "/"; +class TestIOSystem : public IOSystem { +public: + TestIOSystem() : IOSystem() {} + virtual ~TestIOSystem() {} + virtual bool Exists( const char* ) const { + return true; + } + virtual char getOsSeparator() const { + return Sep[ 0 ]; + } + + virtual IOStream* Open( const char* pFile, const char* pMode = "rb" ) { + return NULL; + } + + virtual void Close( IOStream* pFile ) { + // empty + } +}; diff --git a/test/unit/utBatchLoader.cpp b/test/unit/utBatchLoader.cpp new file mode 100644 index 000000000..b3d74a0aa --- /dev/null +++ b/test/unit/utBatchLoader.cpp @@ -0,0 +1,78 @@ +/* +--------------------------------------------------------------------------- +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 "Importer.h" +#include "TestIOSystem.h" + +using namespace ::Assimp; + +class BatchLoaderTest : public ::testing::Test { +public: + virtual void SetUp() { + m_io = new TestIOSystem(); + } + + virtual void TearDown() { + delete m_io; + } + +protected: + TestIOSystem* m_io; +}; + +TEST_F( BatchLoaderTest, createTest ) { + bool ok( true ); + try { + BatchLoader loader( m_io ); + } catch ( ... ) { + ok = false; + } +} + +TEST_F( BatchLoaderTest, validateAccessTest ) { + BatchLoader loader1( m_io ); + EXPECT_FALSE( loader1.getValidation() ); + loader1.setValidation( true ); + EXPECT_TRUE( loader1.getValidation() ); + + BatchLoader loader2( m_io, true ); + EXPECT_TRUE( loader2.getValidation() ); +} diff --git a/test/unit/utIOSystem.cpp b/test/unit/utIOSystem.cpp index b091e8c36..dfae55320 100644 --- a/test/unit/utIOSystem.cpp +++ b/test/unit/utIOSystem.cpp @@ -39,37 +39,22 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --------------------------------------------------------------------------- */ #include "UnitTestPCH.h" +#include "TestIOSystem.h" #include using namespace std; using namespace Assimp; -static const string Sep = "/"; -class TestIOSystem : public IOSystem { -public: - TestIOSystem() : IOSystem() {} - virtual ~TestIOSystem() {} - virtual bool Exists( const char* ) const { - return true; - } - virtual char getOsSeparator() const { - return Sep[ 0 ]; - } - - virtual IOStream* Open(const char* pFile, const char* pMode = "rb") { - return NULL; - } - - virtual void Close( IOStream* pFile) { - // empty - } -}; - class IOSystemTest : public ::testing::Test { public: - virtual void SetUp() { pImp = new TestIOSystem(); } - virtual void TearDown() { delete pImp; } + virtual void SetUp() { + pImp = new TestIOSystem(); + } + + virtual void TearDown() { + delete pImp; + } protected: TestIOSystem* pImp; diff --git a/test/unit/utImporter.cpp b/test/unit/utImporter.cpp index db71f8206..6e2d03a63 100644 --- a/test/unit/utImporter.cpp +++ b/test/unit/utImporter.cpp @@ -270,3 +270,5 @@ TEST_F(ImporterTest, testMultipleReads) EXPECT_TRUE(pImp->ReadFile(ASSIMP_TEST_MODELS_DIR "/X/BCN_Epileptic.X",flags)); //EXPECT_TRUE(pImp->ReadFile(ASSIMP_TEST_MODELS_DIR "/X/dwarf.x",flags)); # is in nonbsd } + +// ------------------------------------------------------------------------------------------------ From 70d5bb8c7b8e0767892326398f3bdec0e2f0c27b Mon Sep 17 00:00:00 2001 From: Alberto Taiuti Date: Sat, 12 Nov 2016 01:29:46 +0000 Subject: [PATCH 42/44] Make assimp build cherry-picked importers in CMake Modify assimp's cmake to exclude the build of all the importers by default; the user has then to manually select the ones needed by setting the relative option. From the explanation as written in the CMakeLists itself: --- This option allows to select whether to build all the importers and then manually select which ones not to build (old behaviour), or if to exclude all importers from build and manually select the ones to actually build. By default, exclude all importers and manually select which ones to use. To have all importers excluded, simply do not set this option in the parent CmakeLists. Then, set the option for the importer(s) needed in the parent CMakeLists, e.g.: OPTION(ASSIMP_BUILD_OBJ_IMPORTER "" TRUE) To have assimp build all the importers, set the option to true, then manually exclude which importers you don't need, e.g.: OPTION(ASSIMP_BUILD_OBJ_IMPORTER "" FALSE) NOTE: In order to use this method of exclusion, the tools build must be disabled; their code references certain importers/exporters which would be excluded. If you need the tools, either manually add the importers/exporters the code references (you will see linkage errors), or just enable the build of all the importers as explained above. --- As mentioned there, set the main CMakeLists not to build the tools and the tests by default, since they use certain exporters and importers which, with this method, are not necessarily used/built. --- CMakeLists.txt | 4 +-- code/CMakeLists.txt | 71 +++++++++++++++++++++++++++++++++++---------- 2 files changed, 58 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a08aa393b..a8936b4aa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,7 +66,7 @@ OPTION( ASSIMP_BUILD_ZLIB ) option( ASSIMP_BUILD_ASSIMP_TOOLS "If the supplementary tools for Assimp are built in addition to the library." - ON + OFF ) option ( ASSIMP_BUILD_SAMPLES "If the official samples are built as well (needs Glut)." @@ -74,7 +74,7 @@ option ( ASSIMP_BUILD_SAMPLES ) OPTION ( ASSIMP_BUILD_TESTS "If the test suite for Assimp is built in addition to the library." - ON + OFF ) IF(MSVC) set (CMAKE_PREFIX_PATH "D:\\libs\\devil") diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index ac7002a98..178c768a3 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -184,21 +184,62 @@ IF ( ASSIMP_BUILD_NONFREE_C4D_IMPORTER ) SOURCE_GROUP( C4D FILES ${C4D_SRCS}) ENDIF ( ASSIMP_BUILD_NONFREE_C4D_IMPORTER ) -# macro to add the CMake Option ADD_ASSIMP_IMPORTER_ which enables compile of loader -# this way selective loaders can be compiled (reduces filesize + compile time) -MACRO(ADD_ASSIMP_IMPORTER name) - OPTION(ASSIMP_BUILD_${name}_IMPORTER "build the ${name} importer" TRUE) - IF(ASSIMP_BUILD_${name}_IMPORTER) - LIST(APPEND ASSIMP_LOADER_SRCS ${ARGN}) - SET(ASSIMP_IMPORTERS_ENABLED "${ASSIMP_IMPORTERS_ENABLED} ${name}") - SET(${name}_SRCS ${ARGN}) - SOURCE_GROUP(${name} FILES ${ARGN}) - ELSE() - SET(${name}_SRC "") - SET(ASSIMP_IMPORTERS_DISABLED "${ASSIMP_IMPORTERS_DISABLED} ${name}") - add_definitions(-DASSIMP_BUILD_NO_${name}_IMPORTER) - ENDIF() -ENDMACRO() +# This option allows to select whether to build all the importers and then +# manually select which ones not to build (old behaviour), or if to +# exclude all importers from build and manually select the ones to actually +# build. +# By default, exclude all importers and manually select which ones to use. +# +# To have all importers excluded, simply do not set this option in the parent +# CmakeLists. Then, set the option for the importer(s) needed in the parent +# CMakeLists, e.g.: +# OPTION(ASSIMP_BUILD_OBJ_IMPORTER "" TRUE) +# +# To have assimp build all the importers, set the option to true, then manually +# exclude which importers you don't need, e.g.: +# OPTION(ASSIMP_BUILD_OBJ_IMPORTER "" FALSE) +# +# NOTE: In order to use this method of exclusion, the tools build must be disabled; +# their code references certain importers/exporters which would be excluded. +# If you need the tools, either manually add the importers/exporters the code +# references (you will see linkage errors), or just enable the build of all the +# importers as explained above. +OPTION(ASSIMP_BUILD_ALL_AND_EXCLUDE "Build all importers and select which ones + to not build" FALSE) +IF(ASSIMP_BUILD_ALL_AND_EXCLUDE) + # macro to add the CMake Option ADD_ASSIMP_IMPORTER_ which enables compile of loader + # this way selective loaders can be compiled (reduces filesize + compile time) + MACRO(ADD_ASSIMP_IMPORTER name) + OPTION(ASSIMP_BUILD_${name}_IMPORTER "build the ${name} importer" TRUE) + IF(ASSIMP_BUILD_${name}_IMPORTER) + LIST(APPEND ASSIMP_LOADER_SRCS ${ARGN}) + SET(ASSIMP_IMPORTERS_ENABLED "${ASSIMP_IMPORTERS_ENABLED} ${name}") + SET(${name}_SRCS ${ARGN}) + SOURCE_GROUP(${name} FILES ${ARGN}) + ELSE() + SET(${name}_SRC "") + SET(ASSIMP_IMPORTERS_DISABLED "${ASSIMP_IMPORTERS_DISABLED} ${name}") + add_definitions(-DASSIMP_BUILD_NO_${name}_IMPORTER) + ENDIF() + ENDMACRO() +ELSE(ASSIMP_BUILD_ALL_AND_EXCLUDE) + MACRO(ADD_ASSIMP_IMPORTER name) + OPTION(ASSIMP_BUILD_${name}_IMPORTER "build the ${name} importer" FALSE) + MESSAGE(STATUS "Setting false for ${name}") + IF(ASSIMP_BUILD_${name}_IMPORTER) + LIST(APPEND ASSIMP_LOADER_SRCS ${ARGN}) + SET(ASSIMP_IMPORTERS_ENABLED "${ASSIMP_IMPORTERS_ENABLED} ${name}") + SET(${name}_SRCS ${ARGN}) + SOURCE_GROUP(${name} FILES ${ARGN}) + MESSAGE(STATUS "Setting true for ${name}") + ELSE() + SET(${name}_SRC "") + SET(ASSIMP_IMPORTERS_DISABLED "${ASSIMP_IMPORTERS_DISABLED} ${name}") + add_definitions(-DASSIMP_BUILD_NO_${name}_IMPORTER) + MESSAGE(STATUS "Setting false for ${name}") + ENDIF() + ENDMACRO() +ENDIF(ASSIMP_BUILD_ALL_AND_EXCLUDE) SET(ASSIMP_LOADER_SRCS "") SET(ASSIMP_IMPORTERS_ENABLED "") # list of enabled importers From ce4f696312f7a593922d974a1654fbd6e6cda2e3 Mon Sep 17 00:00:00 2001 From: Alberto Taiuti Date: Sat, 12 Nov 2016 02:10:51 +0000 Subject: [PATCH 43/44] Revert "Make assimp build cherry-picked importers in CMake" This reverts commit 70d5bb8c7b8e0767892326398f3bdec0e2f0c27b. --- CMakeLists.txt | 4 +-- code/CMakeLists.txt | 71 ++++++++++----------------------------------- 2 files changed, 17 insertions(+), 58 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a8936b4aa..a08aa393b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,7 +66,7 @@ OPTION( ASSIMP_BUILD_ZLIB ) option( ASSIMP_BUILD_ASSIMP_TOOLS "If the supplementary tools for Assimp are built in addition to the library." - OFF + ON ) option ( ASSIMP_BUILD_SAMPLES "If the official samples are built as well (needs Glut)." @@ -74,7 +74,7 @@ option ( ASSIMP_BUILD_SAMPLES ) OPTION ( ASSIMP_BUILD_TESTS "If the test suite for Assimp is built in addition to the library." - OFF + ON ) IF(MSVC) set (CMAKE_PREFIX_PATH "D:\\libs\\devil") diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index 178c768a3..ac7002a98 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -184,62 +184,21 @@ IF ( ASSIMP_BUILD_NONFREE_C4D_IMPORTER ) SOURCE_GROUP( C4D FILES ${C4D_SRCS}) ENDIF ( ASSIMP_BUILD_NONFREE_C4D_IMPORTER ) -# This option allows to select whether to build all the importers and then -# manually select which ones not to build (old behaviour), or if to -# exclude all importers from build and manually select the ones to actually -# build. -# By default, exclude all importers and manually select which ones to use. -# -# To have all importers excluded, simply do not set this option in the parent -# CmakeLists. Then, set the option for the importer(s) needed in the parent -# CMakeLists, e.g.: -# OPTION(ASSIMP_BUILD_OBJ_IMPORTER "" TRUE) -# -# To have assimp build all the importers, set the option to true, then manually -# exclude which importers you don't need, e.g.: -# OPTION(ASSIMP_BUILD_OBJ_IMPORTER "" FALSE) -# -# NOTE: In order to use this method of exclusion, the tools build must be disabled; -# their code references certain importers/exporters which would be excluded. -# If you need the tools, either manually add the importers/exporters the code -# references (you will see linkage errors), or just enable the build of all the -# importers as explained above. -OPTION(ASSIMP_BUILD_ALL_AND_EXCLUDE "Build all importers and select which ones - to not build" FALSE) -IF(ASSIMP_BUILD_ALL_AND_EXCLUDE) - # macro to add the CMake Option ADD_ASSIMP_IMPORTER_ which enables compile of loader - # this way selective loaders can be compiled (reduces filesize + compile time) - MACRO(ADD_ASSIMP_IMPORTER name) - OPTION(ASSIMP_BUILD_${name}_IMPORTER "build the ${name} importer" TRUE) - IF(ASSIMP_BUILD_${name}_IMPORTER) - LIST(APPEND ASSIMP_LOADER_SRCS ${ARGN}) - SET(ASSIMP_IMPORTERS_ENABLED "${ASSIMP_IMPORTERS_ENABLED} ${name}") - SET(${name}_SRCS ${ARGN}) - SOURCE_GROUP(${name} FILES ${ARGN}) - ELSE() - SET(${name}_SRC "") - SET(ASSIMP_IMPORTERS_DISABLED "${ASSIMP_IMPORTERS_DISABLED} ${name}") - add_definitions(-DASSIMP_BUILD_NO_${name}_IMPORTER) - ENDIF() - ENDMACRO() -ELSE(ASSIMP_BUILD_ALL_AND_EXCLUDE) - MACRO(ADD_ASSIMP_IMPORTER name) - OPTION(ASSIMP_BUILD_${name}_IMPORTER "build the ${name} importer" FALSE) - MESSAGE(STATUS "Setting false for ${name}") - IF(ASSIMP_BUILD_${name}_IMPORTER) - LIST(APPEND ASSIMP_LOADER_SRCS ${ARGN}) - SET(ASSIMP_IMPORTERS_ENABLED "${ASSIMP_IMPORTERS_ENABLED} ${name}") - SET(${name}_SRCS ${ARGN}) - SOURCE_GROUP(${name} FILES ${ARGN}) - MESSAGE(STATUS "Setting true for ${name}") - ELSE() - SET(${name}_SRC "") - SET(ASSIMP_IMPORTERS_DISABLED "${ASSIMP_IMPORTERS_DISABLED} ${name}") - add_definitions(-DASSIMP_BUILD_NO_${name}_IMPORTER) - MESSAGE(STATUS "Setting false for ${name}") - ENDIF() - ENDMACRO() -ENDIF(ASSIMP_BUILD_ALL_AND_EXCLUDE) +# macro to add the CMake Option ADD_ASSIMP_IMPORTER_ which enables compile of loader +# this way selective loaders can be compiled (reduces filesize + compile time) +MACRO(ADD_ASSIMP_IMPORTER name) + OPTION(ASSIMP_BUILD_${name}_IMPORTER "build the ${name} importer" TRUE) + IF(ASSIMP_BUILD_${name}_IMPORTER) + LIST(APPEND ASSIMP_LOADER_SRCS ${ARGN}) + SET(ASSIMP_IMPORTERS_ENABLED "${ASSIMP_IMPORTERS_ENABLED} ${name}") + SET(${name}_SRCS ${ARGN}) + SOURCE_GROUP(${name} FILES ${ARGN}) + ELSE() + SET(${name}_SRC "") + SET(ASSIMP_IMPORTERS_DISABLED "${ASSIMP_IMPORTERS_DISABLED} ${name}") + add_definitions(-DASSIMP_BUILD_NO_${name}_IMPORTER) + ENDIF() +ENDMACRO() SET(ASSIMP_LOADER_SRCS "") SET(ASSIMP_IMPORTERS_ENABLED "") # list of enabled importers From eceb61b854b6736ccc28e19da3806ae550b6d24b Mon Sep 17 00:00:00 2001 From: Jared Mulconry Date: Mon, 14 Nov 2016 22:52:29 +1100 Subject: [PATCH 44/44] Fixed a compile error on MSVC14 x64 caused by the /bigobj flag failing to be set for the 1 and 2-suffixed versions introduced in commit 0a25b076b8968b7ea2aa96d7d1b4381be2d72ce6. --- code/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index ac7002a98..3f0b69670 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -463,7 +463,7 @@ ADD_ASSIMP_IMPORTER( IFC STEPFileEncoding.h ) if (MSVC AND ASSIMP_BUILD_IFC_IMPORTER) - set_source_files_properties(IFCReaderGen.cpp PROPERTIES COMPILE_FLAGS "/bigobj") + set_source_files_properties(IFCReaderGen1.cpp IFCReaderGen2.cpp PROPERTIES COMPILE_FLAGS "/bigobj") endif (MSVC AND ASSIMP_BUILD_IFC_IMPORTER) ADD_ASSIMP_IMPORTER( XGL