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