Merge branch 'master' of https://github.com/assimp/assimp
authorKim Kulling <kim.kulling@goolemail.com>
Thu, 25 May 2017 20:40:36 +0000 (22:40 +0200)
committerKim Kulling <kim.kulling@goolemail.com>
Thu, 25 May 2017 20:40:36 +0000 (22:40 +0200)
1  2 
code/ObjFileMtlImporter.h
code/ObjFileParser.cpp
code/ObjFileParser.h
code/ObjTools.h
test/CMakeLists.txt
test/unit/utObjTools.cpp

@@@ -113,4 -113,4 +113,4 @@@ private
  
  } // Namespace Assimp
  
--#endif
++#endif // OBJFILEMTLIMPORTER_H_INC
@@@ -57,8 -57,8 +57,17 @@@ namespace Assimp 
  
  const std::string ObjFileParser::DEFAULT_MATERIAL = AI_DEFAULT_MATERIAL_NAME;
  
--// -------------------------------------------------------------------
--//  Constructor with loaded data and directories.
++ObjFileParser::ObjFileParser()
++: m_DataIt()
++, m_DataItEnd()
++, m_pModel( NULL )
++, m_uiLine( 0 )
++, m_pIO( nullptr )
++, m_progress( nullptr )
++, m_originalObjFileName( "" ) {
++    // empty
++}
++
  ObjFileParser::ObjFileParser( IOStreamBuffer<char> &streamBuffer, const std::string &modelName,
                                IOSystem *io, ProgressHandler* progress,
                                const std::string &originalObjFileName) :
      parseFile( streamBuffer );
  }
  
--// -------------------------------------------------------------------
--//  Destructor
  ObjFileParser::~ObjFileParser() {
      delete m_pModel;
      m_pModel = NULL;
  }
  
--// -------------------------------------------------------------------
--//  Returns a pointer to the model instance.
++void ObjFileParser::setBuffer( std::vector<char> &buffer ) {
++    m_DataIt = buffer.begin();
++    m_DataItEnd = buffer.end();
++}
++
  ObjFile::Model *ObjFileParser::GetModel() const {
      return m_pModel;
  }
++
  void ignoreNewLines(IOStreamBuffer<char> &streamBuffer, std::vector<char> &buffer)
  {
      auto curPosition = buffer.begin();
          }
      } while (*curPosition!='\n');
  }
--// -------------------------------------------------------------------
--//  File parsing method.
++
  void ObjFileParser::parseFile( IOStreamBuffer<char> &streamBuffer ) {
      // only update every 100KB or it'll be too slow
      //const unsigned int updateProgressEveryBytes = 100 * 1024;
              progressCounter++;
              m_progress->UpdateFileRead( progressOffset + processed * 2, progressTotal );
          }
--              ignoreNewLines(streamBuffer, buffer);
++              //ignoreNewLines(streamBuffer, buffer);
          // parse line
          switch (*m_DataIt) {
          case 'v': // Parse a vertex texture coordinate
@@@ -243,11 -243,11 +253,14 @@@ pf_skip_line
      }
  }
  
--// -------------------------------------------------------------------
--//  Copy the next word in a temporary buffer
  void ObjFileParser::copyNextWord(char *pBuffer, size_t length) {
      size_t index = 0;
      m_DataIt = getNextWord<DataArrayIt>(m_DataIt, m_DataItEnd);
++    if ( *m_DataIt == '\\' ) {
++        m_DataIt++;
++        m_DataIt++;
++        m_DataIt = getNextWord<DataArrayIt>( m_DataIt, m_DataItEnd );
++    }
      while( m_DataIt != m_DataItEnd && !IsSpaceOrNewLine( *m_DataIt ) ) {
          pBuffer[index] = *m_DataIt;
          index++;
  size_t ObjFileParser::getNumComponentsInLine() {
      size_t numComponents( 0 );
      const char* tmp( &m_DataIt[0] );
--    while( !IsLineEnd( *tmp ) ) {
++    while( !IsLineEnd( *tmp ) ) {        
          if ( !SkipSpaces( &tmp ) ) {
              break;
          }
@@@ -300,8 -300,8 +313,6 @@@ void ObjFileParser::getVector( std::vec
      m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
  }
  
--// -------------------------------------------------------------------
--//  Get values for a new 3D vector instance
  void ObjFileParser::getVector3( std::vector<aiVector3D> &point3d_array ) {
      ai_real x, y, z;
      copyNextWord(m_buffer, Buffersize);
@@@ -65,7 -65,7 +65,7 @@@ class ProgressHandler
  
  /// \class  ObjFileParser
  /// \brief  Parser for a obj waveform file
--class ObjFileParser {
++class ASSIMP_API ObjFileParser {
  public:
      static const size_t Buffersize = 4096;
      typedef std::vector<char> DataArray;
      typedef std::vector<char>::const_iterator ConstDataArrayIt;
  
  public:
--    /// \brief  Constructor with data array.
--    ObjFileParser( IOStreamBuffer<char> &streamBuffer, const std::string &strModelName, IOSystem* io, ProgressHandler* progress, const std::string &originalObjFileName);
--    /// \brief  Destructor
++    /// @brief  The default constructor.
++    ObjFileParser();
++    /// @brief  Constructor with data array.
++    ObjFileParser( IOStreamBuffer<char> &streamBuffer, const std::string &modelName, IOSystem* io, ProgressHandler* progress, const std::string &originalObjFileName);
++    /// @brief  Destructor
      ~ObjFileParser();
--    /// \brief  Model getter.
++    /// @brief  If you want to load in-core data.
++    void setBuffer( std::vector<char> &buffer );
++    /// @brief  Model getter.
      ObjFile::Model *GetModel() const;
  
--private:
++protected:
      /// Parse the loaded file
      void parseFile( IOStreamBuffer<char> &streamBuffer );
      /// Method to copy the new delimited word in the current line.
diff --cc code/ObjTools.h
@@@ -79,8 -79,8 +79,10 @@@ inline Char_T getNextWord( Char_T pBuff
  {
      while ( !isEndOfBuffer( pBuffer, pEnd ) )
      {
--        if( !IsSpaceOrNewLine( *pBuffer ) || IsLineEnd( *pBuffer ) )
--            break;
++        if ( !IsSpaceOrNewLine( *pBuffer ) || IsLineEnd( *pBuffer ) ) {
++            //if ( *pBuffer != '\\' )
++                break;
++        }
          pBuffer++;
      }
      return pBuffer;
@@@ -38,7 -38,7 +38,6 @@@
  #----------------------------------------------------------------------
  cmake_minimum_required( VERSION 2.6 )
  
--#INCLUDE( AddGTest )
  include( CTest )
  enable_testing()
  
@@@ -106,9 -106,10 +105,11 @@@ SET( TEST_SRC
    unit/SceneDiffer.cpp
    unit/utSIBImporter.cpp
    unit/utObjImportExport.cpp
 +  unit/utObjTools.cpp
+   unit/utOpenGEXImportExport.cpp
    unit/utPretransformVertices.cpp
    unit/utPLYImportExport.cpp
+   unit/utPMXImporter.cpp
    unit/utRemoveComments.cpp
    unit/utRemoveComponent.cpp
    unit/utRemoveRedundantMaterials.cpp
index d332f0f,0000000..cacace4
mode 100644,000000..100644
--- /dev/null
@@@ -1,65 -1,0 +1,93 @@@
-     std::string data( "vn - 2.061493116917992e-15 - 0.9009688496589661 \ \n- 0.4338837265968323 " );
 +/*
 +---------------------------------------------------------------------------
 +Open Asset Import Library (assimp)
 +---------------------------------------------------------------------------
 +
 +Copyright (c) 2006-2017, 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 "ObjTools.h"
++#include "ObjFileParser.h"
 +
 +using namespace ::Assimp;
 +
 +class utObjTools : public ::testing::Test {
 +    // empty
 +};
 +
++class TestObjFileParser : public ObjFileParser {
++public:
++    TestObjFileParser() : ObjFileParser(){}
++    ~TestObjFileParser() {}
++    void testCopyNextWord( char *pBuffer, size_t length ) {
++        copyNextWord( pBuffer, length );
++    }
++
++};
 +TEST_F( utObjTools, skipDataLine_OneLine_Success ) {
 +    std::vector<char> buffer;
 +    std::string data( "v -0.5 -0.5 0.5\nend" );
 +    buffer.resize( data.size() );
 +    ::memcpy( &buffer[ 0 ], &data[ 0 ], data.size() );
 +    std::vector<char>::iterator itBegin( buffer.begin() ), itEnd( buffer.end() );
 +    unsigned int line = 0;
 +    std::vector<char>::iterator current = skipLine<std::vector<char>::iterator>( itBegin, itEnd, line );
 +    EXPECT_EQ( 'e', *current );
 +}
 +
 +TEST_F( utObjTools, skipDataLine_TwoLines_Success ) {
++    TestObjFileParser test_parser;
++    std::string data( "vn -2.061493116917992e-15 -0.9009688496589661 \\n-0.4338837265968323" );
++    std::vector<char> buffer;
++    buffer.resize( data.size() );
++    ::memcpy( &buffer[ 0 ], &data[ 0 ], data.size() );
++    test_parser.setBuffer( buffer );
++    static const size_t Size = 4096UL;
++    char data_buffer[ Size ];
++    
++    test_parser.testCopyNextWord( data_buffer, Size );
++    EXPECT_EQ( 0, strncmp( data_buffer, "vn", 2 ) );
++
++    test_parser.testCopyNextWord( data_buffer, Size );
++    EXPECT_EQ( data_buffer[0], '-' );
++
++    test_parser.testCopyNextWord( data_buffer, Size );
++    EXPECT_EQ( data_buffer[0], '-' );
 +
++    test_parser.testCopyNextWord( data_buffer, Size );
++    EXPECT_EQ( data_buffer[ 0 ], '-' );
 +}