vrshoot

view libs/assimp/XFileParser.h @ 0:b2f14e535253

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