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