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