Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 
 

163 řádky
5.4 KiB

  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2012, 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 "../include/assimp/types.h"
  39. namespace Assimp
  40. {
  41. namespace XFile
  42. {
  43. struct Node;
  44. struct Mesh;
  45. struct Scene;
  46. struct Material;
  47. struct Animation;
  48. struct AnimBone;
  49. }
  50. /** The XFileParser reads a XFile either in text or binary form and builds a temporary
  51. * data structure out of it.
  52. */
  53. class XFileParser
  54. {
  55. public:
  56. /** Constructor. Creates a data structure out of the XFile given in the memory block.
  57. * @param pBuffer Null-terminated memory buffer containing the XFile
  58. */
  59. XFileParser( const std::vector<char>& pBuffer);
  60. /** Destructor. Destroys all imported data along with it */
  61. ~XFileParser();
  62. /** Returns the temporary representation of the imported data */
  63. XFile::Scene* GetImportedData() const { return mScene; }
  64. protected:
  65. void ParseFile();
  66. void ParseDataObjectTemplate();
  67. void ParseDataObjectFrame( XFile::Node *pParent);
  68. void ParseDataObjectTransformationMatrix( aiMatrix4x4& pMatrix);
  69. void ParseDataObjectMesh( XFile::Mesh* pMesh);
  70. void ParseDataObjectSkinWeights( XFile::Mesh* pMesh);
  71. void ParseDataObjectSkinMeshHeader( XFile::Mesh* pMesh);
  72. void ParseDataObjectMeshNormals( XFile::Mesh* pMesh);
  73. void ParseDataObjectMeshTextureCoords( XFile::Mesh* pMesh);
  74. void ParseDataObjectMeshVertexColors( XFile::Mesh* pMesh);
  75. void ParseDataObjectMeshMaterialList( XFile::Mesh* pMesh);
  76. void ParseDataObjectMaterial( XFile::Material* pMaterial);
  77. void ParseDataObjectAnimTicksPerSecond();
  78. void ParseDataObjectAnimationSet();
  79. void ParseDataObjectAnimation( XFile::Animation* pAnim);
  80. void ParseDataObjectAnimationKey( XFile::AnimBone *pAnimBone);
  81. void ParseDataObjectTextureFilename( std::string& pName);
  82. void ParseUnknownDataObject();
  83. //! places pointer to next begin of a token, and ignores comments
  84. void FindNextNoneWhiteSpace();
  85. //! returns next parseable token. Returns empty string if no token there
  86. std::string GetNextToken();
  87. //! reads header of dataobject including the opening brace.
  88. //! returns false if error happened, and writes name of object
  89. //! if there is one
  90. void readHeadOfDataObject( std::string* poName = NULL);
  91. //! checks for closing curly brace, throws exception if not there
  92. void CheckForClosingBrace();
  93. //! checks for one following semicolon, throws exception if not there
  94. void CheckForSemicolon();
  95. //! checks for a separator char, either a ',' or a ';'
  96. void CheckForSeparator();
  97. /// tests and possibly consumes a separator char, but does nothing if there was no separator
  98. void TestForSeparator();
  99. //! reads a x file style string
  100. void GetNextTokenAsString( std::string& poString);
  101. void ReadUntilEndOfLine();
  102. unsigned short ReadBinWord();
  103. unsigned int ReadBinDWord();
  104. unsigned int ReadInt();
  105. float ReadFloat();
  106. aiVector2D ReadVector2();
  107. aiVector3D ReadVector3();
  108. aiColor3D ReadRGB();
  109. aiColor4D ReadRGBA();
  110. /** Throws an exception with a line number and the given text. */
  111. void ThrowException( const std::string& pText);
  112. /** Filters the imported hierarchy for some degenerated cases that some exporters produce.
  113. * @param pData The sub-hierarchy to filter
  114. */
  115. void FilterHierarchy( XFile::Node* pNode);
  116. protected:
  117. unsigned int mMajorVersion, mMinorVersion; ///< version numbers
  118. bool mIsBinaryFormat; ///< true if the file is in binary, false if it's in text form
  119. unsigned int mBinaryFloatSize; ///< float size in bytes, either 4 or 8
  120. // counter for number arrays in binary format
  121. unsigned int mBinaryNumCount;
  122. const char* P;
  123. const char* End;
  124. /// Line number when reading in text format
  125. unsigned int mLineNumber;
  126. /// Imported data
  127. XFile::Scene* mScene;
  128. };
  129. }
  130. #endif // AI_XFILEPARSER_H_INC