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