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