From 0bae2bbfa7011b86d44a314e3919f244113127db Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Fri, 7 Oct 2016 09:19:10 +0200 Subject: [PATCH 01/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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" // ----------------------------------------------------------------------------------