/src/assimp/code/AssetLib/X/XFileHelper.h
Line | Count | Source |
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 Defines the helper data structures for importing XFiles */ |
43 | | #ifndef AI_XFILEHELPER_H_INC |
44 | | #define AI_XFILEHELPER_H_INC |
45 | | |
46 | | #include <cstdint> |
47 | | #include <string> |
48 | | #include <vector> |
49 | | |
50 | | #include <assimp/anim.h> |
51 | | #include <assimp/mesh.h> |
52 | | #include <assimp/quaternion.h> |
53 | | #include <assimp/types.h> |
54 | | |
55 | | namespace Assimp { |
56 | | namespace XFile { |
57 | | |
58 | | /** Helper structure representing a XFile mesh face */ |
59 | | struct Face { |
60 | | std::vector<unsigned int> mIndices; |
61 | | }; |
62 | | |
63 | | /** Helper structure representing a texture filename inside a material and its potential source */ |
64 | | struct TexEntry { |
65 | | std::string mName; |
66 | | bool mIsNormalMap; // true if the texname was specified in a NormalmapFilename tag |
67 | | |
68 | | TexEntry() AI_NO_EXCEPT : |
69 | 0 | mIsNormalMap(false) { |
70 | 0 | // empty |
71 | 0 | } |
72 | | TexEntry(const std::string &pName, bool pIsNormalMap = false) : |
73 | 0 | mName(pName), mIsNormalMap(pIsNormalMap) { |
74 | | // empty |
75 | 0 | } |
76 | | }; |
77 | | |
78 | | /** Helper structure representing a XFile material */ |
79 | | struct Material { |
80 | | std::string mName; |
81 | | bool mIsReference; // if true, mName holds a name by which the actual material can be found in the material list |
82 | | aiColor4D mDiffuse; |
83 | | ai_real mSpecularExponent; |
84 | | aiColor3D mSpecular; |
85 | | aiColor3D mEmissive; |
86 | | std::vector<TexEntry> mTextures; |
87 | | size_t sceneIndex; ///< the index under which it was stored in the scene's material list |
88 | | |
89 | | Material() AI_NO_EXCEPT : |
90 | 0 | mIsReference(false), |
91 | | mSpecularExponent(), |
92 | 0 | sceneIndex(SIZE_MAX) { |
93 | | // empty |
94 | 0 | } |
95 | | }; |
96 | | |
97 | | /** Helper structure to represent a bone weight */ |
98 | | struct BoneWeight { |
99 | | unsigned int mVertex; |
100 | | ai_real mWeight; |
101 | | }; |
102 | | |
103 | | /** Helper structure to represent a bone in a mesh */ |
104 | | struct Bone { |
105 | | std::string mName; |
106 | | std::vector<BoneWeight> mWeights; |
107 | | aiMatrix4x4 mOffsetMatrix; |
108 | | }; |
109 | | |
110 | | /** Helper structure to represent an XFile mesh */ |
111 | | struct Mesh { |
112 | | std::string mName; |
113 | | std::vector<aiVector3D> mPositions; |
114 | | std::vector<Face> mPosFaces; |
115 | | std::vector<aiVector3D> mNormals; |
116 | | std::vector<Face> mNormFaces; |
117 | | unsigned int mNumTextures; |
118 | | std::vector<aiVector2D> mTexCoords[AI_MAX_NUMBER_OF_TEXTURECOORDS]; |
119 | | unsigned int mNumColorSets; |
120 | | std::vector<aiColor4D> mColors[AI_MAX_NUMBER_OF_COLOR_SETS]; |
121 | | |
122 | | std::vector<unsigned int> mFaceMaterials; |
123 | | std::vector<Material> mMaterials; |
124 | | |
125 | | std::vector<Bone> mBones; |
126 | | |
127 | | explicit Mesh(const std::string &pName = std::string()) AI_NO_EXCEPT |
128 | 0 | : mName(pName), |
129 | 0 | mNumTextures(0), |
130 | 0 | mNumColorSets(0) { |
131 | | // empty |
132 | 0 | } |
133 | | }; |
134 | | |
135 | | /** Helper structure to represent a XFile frame */ |
136 | | struct Node { |
137 | | std::string mName; |
138 | | aiMatrix4x4 mTrafoMatrix; |
139 | | Node *mParent; |
140 | | std::vector<Node *> mChildren; |
141 | | std::vector<Mesh *> mMeshes; |
142 | | |
143 | | Node() AI_NO_EXCEPT |
144 | | : mTrafoMatrix(), |
145 | 0 | mParent(nullptr) { |
146 | 0 | // empty |
147 | 0 | } |
148 | | explicit Node(Node *pParent) : |
149 | 0 | mTrafoMatrix(), mParent(pParent) { |
150 | | // empty |
151 | 0 | } |
152 | | |
153 | 0 | ~Node() { |
154 | 0 | for (unsigned int a = 0; a < mChildren.size(); ++a) { |
155 | 0 | delete mChildren[a]; |
156 | 0 | } |
157 | 0 | for (unsigned int a = 0; a < mMeshes.size(); ++a) { |
158 | 0 | delete mMeshes[a]; |
159 | 0 | } |
160 | 0 | } |
161 | | }; |
162 | | |
163 | | struct MatrixKey { |
164 | | double mTime; |
165 | | aiMatrix4x4 mMatrix; |
166 | | }; |
167 | | |
168 | | /** Helper structure representing a single animated bone in a XFile */ |
169 | | struct AnimBone { |
170 | | std::string mBoneName; |
171 | | std::vector<aiVectorKey> mPosKeys; // either three separate key sequences for position, rotation, scaling |
172 | | std::vector<aiQuatKey> mRotKeys; |
173 | | std::vector<aiVectorKey> mScaleKeys; |
174 | | std::vector<MatrixKey> mTrafoKeys; // or a combined key sequence of transformation matrices. |
175 | | }; |
176 | | |
177 | | /** Helper structure to represent an animation set in a XFile */ |
178 | | struct Animation { |
179 | | std::string mName; |
180 | | std::vector<AnimBone *> mAnims; |
181 | | |
182 | 0 | ~Animation() { |
183 | 0 | for (unsigned int a = 0; a < mAnims.size(); a++) |
184 | 0 | delete mAnims[a]; |
185 | 0 | } |
186 | | }; |
187 | | |
188 | | /** Helper structure analogue to aiScene */ |
189 | | struct Scene { |
190 | | Node *mRootNode; |
191 | | |
192 | | std::vector<Mesh *> mGlobalMeshes; // global meshes found outside of any frames |
193 | | std::vector<Material> mGlobalMaterials; // global materials found outside of any meshes. |
194 | | |
195 | | std::vector<Animation *> mAnims; |
196 | | unsigned int mAnimTicksPerSecond; |
197 | | |
198 | | Scene() AI_NO_EXCEPT |
199 | 0 | : mRootNode(nullptr), |
200 | 0 | mAnimTicksPerSecond(0) { |
201 | | // empty |
202 | 0 | } |
203 | 0 | ~Scene() { |
204 | 0 | delete mRootNode; |
205 | 0 | mRootNode = nullptr; |
206 | 0 | for (unsigned int a = 0; a < mGlobalMeshes.size(); ++a) { |
207 | 0 | delete mGlobalMeshes[a]; |
208 | 0 | } |
209 | 0 | for (unsigned int a = 0; a < mAnims.size(); ++a) { |
210 | 0 | delete mAnims[a]; |
211 | 0 | } |
212 | 0 | } |
213 | | }; |
214 | | |
215 | | } // end of namespace XFile |
216 | | } // end of namespace Assimp |
217 | | |
218 | | #endif // AI_XFILEHELPER_H_INC |