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