XFileParser.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /** @file Helper class to parse a XFile into a temporary structure */
  2. #ifndef AI_XFILEPARSER_H_INC
  3. #define AI_XFILEPARSER_H_INC
  4. #include <string>
  5. #include <vector>
  6. #include "../include/aiTypes.h"
  7. namespace Assimp
  8. {
  9. namespace XFile
  10. {
  11. struct Node;
  12. struct Mesh;
  13. struct Scene;
  14. struct Material;
  15. struct Animation;
  16. struct AnimBone;
  17. }
  18. /** The XFileParser reads a XFile either in text or binary form and builds a temporary
  19. * data structure out of it.
  20. */
  21. class XFileParser
  22. {
  23. public:
  24. /** Constructor. Creates a data structure out of the XFile given in the memory block.
  25. * @param pBuffer Memory buffer containing the XFile
  26. */
  27. XFileParser( const std::vector<char>& pBuffer);
  28. /** Destructor. Destroys all imported data along with it */
  29. ~XFileParser();
  30. /** Returns the temporary representation of the imported data */
  31. const XFile::Scene* GetImportedData() const { return mScene; }
  32. protected:
  33. void ParseFile();
  34. void ParseDataObjectTemplate();
  35. void ParseDataObjectFrame( XFile::Node *pParent);
  36. void ParseDataObjectTransformationMatrix( aiMatrix4x4& pMatrix);
  37. void ParseDataObjectMesh( XFile::Mesh* pMesh);
  38. void ParseDataObjectSkinWeights( XFile::Mesh* pMesh);
  39. void ParseDataObjectSkinMeshHeader( XFile::Mesh* pMesh);
  40. void ParseDataObjectMeshNormals( XFile::Mesh* pMesh);
  41. void ParseDataObjectMeshTextureCoords( XFile::Mesh* pMesh);
  42. void ParseDataObjectMeshVertexColors( XFile::Mesh* pMesh);
  43. void ParseDataObjectMeshMaterialList( XFile::Mesh* pMesh);
  44. void ParseDataObjectMaterial( XFile::Material* pMaterial);
  45. void ParseDataObjectAnimTicksPerSecond();
  46. void ParseDataObjectAnimationSet();
  47. void ParseDataObjectAnimation( XFile::Animation* pAnim);
  48. void ParseDataObjectAnimationKey( XFile::AnimBone *pAnimBone);
  49. void ParseDataObjectTextureFilename( std::string& pName);
  50. void ParseUnknownDataObject();
  51. //! places pointer to next begin of a token, and ignores comments
  52. void FindNextNoneWhiteSpace();
  53. //! returns next parseable token. Returns empty string if no token there
  54. std::string GetNextToken();
  55. //! reads header of dataobject including the opening brace.
  56. //! returns false if error happened, and writes name of object
  57. //! if there is one
  58. void readHeadOfDataObject( std::string* poName = NULL);
  59. //! checks for closing curly brace, throws exception if not there
  60. void CheckForClosingBrace();
  61. //! checks for one following semicolon, throws exception if not there
  62. void CheckForSemicolon();
  63. //! checks for a separator char, either a ',' or a ';'
  64. void CheckForSeparator();
  65. //! reads a x file style string
  66. void GetNextTokenAsString( std::string& poString);
  67. void ReadUntilEndOfLine();
  68. unsigned short ReadBinWord();
  69. unsigned int ReadBinDWord();
  70. unsigned int ReadInt();
  71. float ReadFloat();
  72. aiVector2D ReadVector2();
  73. aiVector3D ReadVector3();
  74. aiColor3D ReadRGB();
  75. aiColor4D ReadRGBA();
  76. /** Throws an exception with a line number and the given text. */
  77. void ThrowException( const std::string& pText);
  78. /** Filters the imported hierarchy for some degenerated cases that some exporters produce.
  79. * @param pData The sub-hierarchy to filter
  80. */
  81. void FilterHierarchy( XFile::Node* pNode);
  82. protected:
  83. unsigned int mMajorVersion, mMinorVersion; ///< version numbers
  84. bool mIsBinaryFormat; ///< true if the file is in binary, false if it's in text form
  85. unsigned int mBinaryFloatSize; ///< float size, either 32 or 64 bits
  86. // counter for number arrays in binary format
  87. unsigned int mBinaryNumCount;
  88. const char* P;
  89. const char* End;
  90. /// Line number when reading in text format
  91. unsigned int mLineNumber;
  92. /// Imported data
  93. XFile::Scene* mScene;
  94. };
  95. }
  96. #endif // AI_XFILEPARSER_H_INC