vrshoot

view libs/assimp/XFileHelper.h @ 0:b2f14e535253

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 01 Feb 2014 19:58:19 +0200
parents
children
line source
1 /*
2 Open Asset Import Library (assimp)
3 ----------------------------------------------------------------------
5 Copyright (c) 2006-2012, assimp team
6 All rights reserved.
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:
12 * Redistributions of source code must retain the above
13 copyright notice, this list of conditions and the
14 following disclaimer.
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.
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.
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.
38 ----------------------------------------------------------------------
39 */
42 /** @file Defines the helper data structures for importing XFiles */
43 #ifndef AI_XFILEHELPER_H_INC
44 #define AI_XFILEHELPER_H_INC
46 #include <string>
47 #include <vector>
49 #include "assimp/types.h"
50 #include "assimp/quaternion.h"
51 #include "assimp/mesh.h"
52 #include "assimp/anim.h"
54 namespace Assimp
55 {
56 namespace XFile
57 {
59 /** Helper structure representing a XFile mesh face */
60 struct Face
61 {
62 std::vector<unsigned int> mIndices;
63 };
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
71 TexEntry() { mIsNormalMap = false; }
72 TexEntry( const std::string& pName, bool pIsNormalMap = false)
73 : mName( pName), mIsNormalMap( pIsNormalMap)
74 { /* done */ }
75 };
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;
88 size_t sceneIndex; ///< the index under which it was stored in the scene's material list
90 Material() { mIsReference = false; sceneIndex = SIZE_MAX; }
91 };
93 /** Helper structure to represent a bone weight */
94 struct BoneWeight
95 {
96 unsigned int mVertex;
97 float mWeight;
98 };
100 /** Helper structure to represent a bone in a mesh */
101 struct Bone
102 {
103 std::string mName;
104 std::vector<BoneWeight> mWeights;
105 aiMatrix4x4 mOffsetMatrix;
106 };
108 /** Helper structure to represent an XFile mesh */
109 struct Mesh
110 {
111 std::vector<aiVector3D> mPositions;
112 std::vector<Face> mPosFaces;
113 std::vector<aiVector3D> mNormals;
114 std::vector<Face> mNormFaces;
115 unsigned int mNumTextures;
116 std::vector<aiVector2D> mTexCoords[AI_MAX_NUMBER_OF_TEXTURECOORDS];
117 unsigned int mNumColorSets;
118 std::vector<aiColor4D> mColors[AI_MAX_NUMBER_OF_COLOR_SETS];
120 std::vector<unsigned int> mFaceMaterials;
121 std::vector<Material> mMaterials;
123 std::vector<Bone> mBones;
125 Mesh() { mNumTextures = 0; mNumColorSets = 0; }
126 };
128 /** Helper structure to represent a XFile frame */
129 struct Node
130 {
131 std::string mName;
132 aiMatrix4x4 mTrafoMatrix;
133 Node* mParent;
134 std::vector<Node*> mChildren;
135 std::vector<Mesh*> mMeshes;
137 Node() { mParent = NULL; }
138 Node( Node* pParent) { mParent = pParent; }
139 ~Node()
140 {
141 for( unsigned int a = 0; a < mChildren.size(); a++)
142 delete mChildren[a];
143 for( unsigned int a = 0; a < mMeshes.size(); a++)
144 delete mMeshes[a];
145 }
146 };
148 struct MatrixKey
149 {
150 double mTime;
151 aiMatrix4x4 mMatrix;
152 };
154 /** Helper structure representing a single animated bone in a XFile */
155 struct AnimBone
156 {
157 std::string mBoneName;
158 std::vector<aiVectorKey> mPosKeys; // either three separate key sequences for position, rotation, scaling
159 std::vector<aiQuatKey> mRotKeys;
160 std::vector<aiVectorKey> mScaleKeys;
161 std::vector<MatrixKey> mTrafoKeys; // or a combined key sequence of transformation matrices.
162 };
164 /** Helper structure to represent an animation set in a XFile */
165 struct Animation
166 {
167 std::string mName;
168 std::vector<AnimBone*> mAnims;
170 ~Animation()
171 {
172 for( unsigned int a = 0; a < mAnims.size(); a++)
173 delete mAnims[a];
174 }
175 };
177 /** Helper structure analogue to aiScene */
178 struct Scene
179 {
180 Node* mRootNode;
182 std::vector<Mesh*> mGlobalMeshes; // global meshes found outside of any frames
183 std::vector<Material> mGlobalMaterials; // global materials found outside of any meshes.
185 std::vector<Animation*> mAnims;
186 unsigned int mAnimTicksPerSecond;
188 Scene() { mRootNode = NULL; mAnimTicksPerSecond = 0; }
189 ~Scene()
190 {
191 delete mRootNode;
192 for( unsigned int a = 0; a < mGlobalMeshes.size(); a++)
193 delete mGlobalMeshes[a];
194 for( unsigned int a = 0; a < mAnims.size(); a++)
195 delete mAnims[a];
196 }
197 };
199 } // end of namespace XFile
200 } // end of namespace Assimp
202 #endif // AI_XFILEHELPER_H_INC