/src/assimp/code/AssetLib/X/XFileParser.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | Open Asset Import Library (assimp) |
3 | | ---------------------------------------------------------------------- |
4 | | |
5 | | Copyright (c) 2006-2025, assimp team |
6 | | |
7 | | All rights reserved. |
8 | | |
9 | | Redistribution and use of this software in source and binary forms, |
10 | | with or without modification, are permitted provided that the |
11 | | following 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 | | |
27 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
28 | | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
29 | | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
30 | | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
31 | | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
32 | | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
33 | | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
34 | | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
35 | | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
36 | | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
37 | | OF 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 | | |
51 | | namespace Assimp { |
52 | | namespace XFile { |
53 | | struct Node; |
54 | | struct Mesh; |
55 | | struct Scene; |
56 | | struct Material; |
57 | | struct Animation; |
58 | | struct AnimBone; |
59 | | } |
60 | | |
61 | | /** |
62 | | * @brief 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 | | public: |
67 | | /// Constructor. Creates a data structure out of the XFile given in the memory block. |
68 | | /// @param pBuffer Null-terminated memory buffer containing the XFile |
69 | | explicit XFileParser( const std::vector<char>& pBuffer); |
70 | | |
71 | | /// Destructor. Destroys all imported data along with it |
72 | | ~XFileParser(); |
73 | | |
74 | | /// Returns the temporary representation of the imported data. |
75 | 0 | XFile::Scene* GetImportedData() const { return mScene; } |
76 | | |
77 | | protected: |
78 | | void ParseFile(); |
79 | | void ParseDataObjectTemplate(); |
80 | | void ParseDataObjectFrame( XFile::Node *pParent); |
81 | | void ParseDataObjectTransformationMatrix( aiMatrix4x4& pMatrix); |
82 | | void ParseDataObjectMesh( XFile::Mesh* pMesh); |
83 | | void ParseDataObjectSkinWeights( XFile::Mesh* pMesh); |
84 | | void ParseDataObjectSkinMeshHeader( XFile::Mesh* pMesh); |
85 | | void ParseDataObjectMeshNormals( XFile::Mesh* pMesh); |
86 | | void ParseDataObjectMeshTextureCoords( XFile::Mesh* pMesh); |
87 | | void ParseDataObjectMeshVertexColors( XFile::Mesh* pMesh); |
88 | | void ParseDataObjectMeshMaterialList( XFile::Mesh* pMesh); |
89 | | void ParseDataObjectMaterial( XFile::Material* pMaterial); |
90 | | void ParseDataObjectAnimTicksPerSecond(); |
91 | | void ParseDataObjectAnimationSet(); |
92 | | void ParseDataObjectAnimation( XFile::Animation* pAnim); |
93 | | void ParseDataObjectAnimationKey( XFile::AnimBone *pAnimBone); |
94 | | void ParseDataObjectTextureFilename( std::string& pName); |
95 | | void ParseUnknownDataObject(); |
96 | | |
97 | | //! places pointer to next begin of a token, and ignores comments |
98 | | void FindNextNoneWhiteSpace(); |
99 | | |
100 | | //! returns next valid token. Returns empty string if no token there |
101 | | std::string GetNextToken(); |
102 | | |
103 | | //! reads header of data object including the opening brace. |
104 | | //! returns false if error happened, and writes name of object |
105 | | //! if there is one |
106 | | void readHeadOfDataObject(std::string *poName = nullptr); |
107 | | |
108 | | //! checks for closing curly brace, throws exception if not there |
109 | | void CheckForClosingBrace(); |
110 | | |
111 | | //! checks for one following semicolon, throws exception if not there |
112 | | void CheckForSemicolon(); |
113 | | |
114 | | //! checks for a separator char, either a ',' or a ';' |
115 | | void CheckForSeparator(); |
116 | | |
117 | | /// tests and possibly consumes a separator char, but does nothing if there was no separator |
118 | | void TestForSeparator(); |
119 | | |
120 | | //! reads a x file style string |
121 | | void GetNextTokenAsString( std::string& poString); |
122 | | |
123 | | void ReadUntilEndOfLine(); |
124 | | |
125 | | unsigned short ReadBinWord(); |
126 | | unsigned int ReadBinDWord(); |
127 | | unsigned int ReadInt(); |
128 | | ai_real ReadFloat(); |
129 | | aiVector2D ReadVector2(); |
130 | | aiVector3D ReadVector3(); |
131 | | aiColor3D ReadRGB(); |
132 | | aiColor4D ReadRGBA(); |
133 | | |
134 | | /** Throws an exception with a line number and the given text. */ |
135 | | template<typename... T> |
136 | | AI_WONT_RETURN void ThrowException(T&&... args) AI_WONT_RETURN_SUFFIX; |
137 | | |
138 | | /** |
139 | | * @brief 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); |
143 | | |
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 in bytes, either 4 or 8 |
148 | | unsigned int mBinaryNumCount; /// < counter for number arrays in binary format |
149 | | const char* mP; |
150 | | const char* mEnd; |
151 | | unsigned int mLineNumber; ///< Line number when reading in text format |
152 | | XFile::Scene* mScene; ///< Imported data |
153 | | }; |
154 | | |
155 | | } //! ns Assimp |
156 | | |
157 | | #endif // AI_XFILEPARSER_H_INC |