XFileParser.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2020, assimp team
  5. All rights reserved.
  6. Redistribution and use of this software in source and binary forms,
  7. with or without modification, are permitted provided that the
  8. following conditions are met:
  9. * Redistributions of source code must retain the above
  10. copyright notice, this list of conditions and the
  11. following disclaimer.
  12. * Redistributions in binary form must reproduce the above
  13. copyright notice, this list of conditions and the
  14. following disclaimer in the documentation and/or other
  15. materials provided with the distribution.
  16. * Neither the name of the assimp team, nor the names of its
  17. contributors may be used to endorse or promote products
  18. derived from this software without specific prior
  19. written permission of the assimp team.
  20. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. ----------------------------------------------------------------------
  32. */
  33. /** @file Helper class to parse a XFile into a temporary structure */
  34. #ifndef AI_XFILEPARSER_H_INC
  35. #define AI_XFILEPARSER_H_INC
  36. #include <string>
  37. #include <vector>
  38. #include <assimp/types.h>
  39. namespace Assimp {
  40. namespace XFile {
  41. struct Node;
  42. struct Mesh;
  43. struct Scene;
  44. struct Material;
  45. struct Animation;
  46. struct AnimBone;
  47. }
  48. /**
  49. * @brief The XFileParser reads a XFile either in text or binary form and builds a temporary
  50. * data structure out of it.
  51. */
  52. class XFileParser {
  53. public:
  54. /// Constructor. Creates a data structure out of the XFile given in the memory block.
  55. /// @param pBuffer Null-terminated memory buffer containing the XFile
  56. explicit XFileParser( const std::vector<char>& pBuffer);
  57. /// Destructor. Destroys all imported data along with it
  58. ~XFileParser();
  59. /// Returns the temporary representation of the imported data.
  60. XFile::Scene* GetImportedData() const { return mScene; }
  61. protected:
  62. void ParseFile();
  63. void ParseDataObjectTemplate();
  64. void ParseDataObjectFrame( XFile::Node *pParent);
  65. void ParseDataObjectTransformationMatrix( aiMatrix4x4& pMatrix);
  66. void ParseDataObjectMesh( XFile::Mesh* pMesh);
  67. void ParseDataObjectSkinWeights( XFile::Mesh* pMesh);
  68. void ParseDataObjectSkinMeshHeader( XFile::Mesh* pMesh);
  69. void ParseDataObjectMeshNormals( XFile::Mesh* pMesh);
  70. void ParseDataObjectMeshTextureCoords( XFile::Mesh* pMesh);
  71. void ParseDataObjectMeshVertexColors( XFile::Mesh* pMesh);
  72. void ParseDataObjectMeshMaterialList( XFile::Mesh* pMesh);
  73. void ParseDataObjectMaterial( XFile::Material* pMaterial);
  74. void ParseDataObjectAnimTicksPerSecond();
  75. void ParseDataObjectAnimationSet();
  76. void ParseDataObjectAnimation( XFile::Animation* pAnim);
  77. void ParseDataObjectAnimationKey( XFile::AnimBone *pAnimBone);
  78. void ParseDataObjectTextureFilename( std::string& pName);
  79. void ParseUnknownDataObject();
  80. //! places pointer to next begin of a token, and ignores comments
  81. void FindNextNoneWhiteSpace();
  82. //! returns next valid token. Returns empty string if no token there
  83. std::string GetNextToken();
  84. //! reads header of data object including the opening brace.
  85. //! returns false if error happened, and writes name of object
  86. //! if there is one
  87. void readHeadOfDataObject(std::string *poName = nullptr);
  88. //! checks for closing curly brace, throws exception if not there
  89. void CheckForClosingBrace();
  90. //! checks for one following semicolon, throws exception if not there
  91. void CheckForSemicolon();
  92. //! checks for a separator char, either a ',' or a ';'
  93. void CheckForSeparator();
  94. /// tests and possibly consumes a separator char, but does nothing if there was no separator
  95. void TestForSeparator();
  96. //! reads a x file style string
  97. void GetNextTokenAsString( std::string& poString);
  98. void ReadUntilEndOfLine();
  99. unsigned short ReadBinWord();
  100. unsigned int ReadBinDWord();
  101. unsigned int ReadInt();
  102. ai_real ReadFloat();
  103. aiVector2D ReadVector2();
  104. aiVector3D ReadVector3();
  105. aiColor3D ReadRGB();
  106. aiColor4D ReadRGBA();
  107. /** Throws an exception with a line number and the given text. */
  108. AI_WONT_RETURN void ThrowException( const std::string& pText) AI_WONT_RETURN_SUFFIX;
  109. /**
  110. * @brief Filters the imported hierarchy for some degenerated cases that some exporters produce.
  111. * @param pData The sub-hierarchy to filter
  112. */
  113. void FilterHierarchy( XFile::Node* pNode);
  114. protected:
  115. unsigned int mMajorVersion, mMinorVersion; ///< version numbers
  116. bool mIsBinaryFormat; ///< true if the file is in binary, false if it's in text form
  117. unsigned int mBinaryFloatSize; ///< float size in bytes, either 4 or 8
  118. unsigned int mBinaryNumCount; /// < counter for number arrays in binary format
  119. const char* mP;
  120. const char* mEnd;
  121. unsigned int mLineNumber; ///< Line number when reading in text format
  122. XFile::Scene* mScene; ///< Imported data
  123. };
  124. } //! ns Assimp
  125. #endif // AI_XFILEPARSER_H_INC