vrshoot
diff 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 diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/libs/assimp/XFileHelper.h Sat Feb 01 19:58:19 2014 +0200 1.3 @@ -0,0 +1,202 @@ 1.4 +/* 1.5 +Open Asset Import Library (assimp) 1.6 +---------------------------------------------------------------------- 1.7 + 1.8 +Copyright (c) 2006-2012, assimp team 1.9 +All rights reserved. 1.10 + 1.11 +Redistribution and use of this software in source and binary forms, 1.12 +with or without modification, are permitted provided that the 1.13 +following conditions are met: 1.14 + 1.15 +* Redistributions of source code must retain the above 1.16 + copyright notice, this list of conditions and the 1.17 + following disclaimer. 1.18 + 1.19 +* Redistributions in binary form must reproduce the above 1.20 + copyright notice, this list of conditions and the 1.21 + following disclaimer in the documentation and/or other 1.22 + materials provided with the distribution. 1.23 + 1.24 +* Neither the name of the assimp team, nor the names of its 1.25 + contributors may be used to endorse or promote products 1.26 + derived from this software without specific prior 1.27 + written permission of the assimp team. 1.28 + 1.29 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.30 +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.31 +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1.32 +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1.33 +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 1.34 +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 1.35 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 1.36 +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 1.37 +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1.38 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1.39 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.40 + 1.41 +---------------------------------------------------------------------- 1.42 +*/ 1.43 + 1.44 + 1.45 +/** @file Defines the helper data structures for importing XFiles */ 1.46 +#ifndef AI_XFILEHELPER_H_INC 1.47 +#define AI_XFILEHELPER_H_INC 1.48 + 1.49 +#include <string> 1.50 +#include <vector> 1.51 + 1.52 +#include "assimp/types.h" 1.53 +#include "assimp/quaternion.h" 1.54 +#include "assimp/mesh.h" 1.55 +#include "assimp/anim.h" 1.56 + 1.57 +namespace Assimp 1.58 +{ 1.59 +namespace XFile 1.60 +{ 1.61 + 1.62 +/** Helper structure representing a XFile mesh face */ 1.63 +struct Face 1.64 +{ 1.65 + std::vector<unsigned int> mIndices; 1.66 +}; 1.67 + 1.68 +/** Helper structure representing a texture filename inside a material and its potential source */ 1.69 +struct TexEntry 1.70 +{ 1.71 + std::string mName; 1.72 + bool mIsNormalMap; // true if the texname was specified in a NormalmapFilename tag 1.73 + 1.74 + TexEntry() { mIsNormalMap = false; } 1.75 + TexEntry( const std::string& pName, bool pIsNormalMap = false) 1.76 + : mName( pName), mIsNormalMap( pIsNormalMap) 1.77 + { /* done */ } 1.78 +}; 1.79 + 1.80 +/** Helper structure representing a XFile material */ 1.81 +struct Material 1.82 +{ 1.83 + std::string mName; 1.84 + bool mIsReference; // if true, mName holds a name by which the actual material can be found in the material list 1.85 + aiColor4D mDiffuse; 1.86 + float mSpecularExponent; 1.87 + aiColor3D mSpecular; 1.88 + aiColor3D mEmissive; 1.89 + std::vector<TexEntry> mTextures; 1.90 + 1.91 + size_t sceneIndex; ///< the index under which it was stored in the scene's material list 1.92 + 1.93 + Material() { mIsReference = false; sceneIndex = SIZE_MAX; } 1.94 +}; 1.95 + 1.96 +/** Helper structure to represent a bone weight */ 1.97 +struct BoneWeight 1.98 +{ 1.99 + unsigned int mVertex; 1.100 + float mWeight; 1.101 +}; 1.102 + 1.103 +/** Helper structure to represent a bone in a mesh */ 1.104 +struct Bone 1.105 +{ 1.106 + std::string mName; 1.107 + std::vector<BoneWeight> mWeights; 1.108 + aiMatrix4x4 mOffsetMatrix; 1.109 +}; 1.110 + 1.111 +/** Helper structure to represent an XFile mesh */ 1.112 +struct Mesh 1.113 +{ 1.114 + std::vector<aiVector3D> mPositions; 1.115 + std::vector<Face> mPosFaces; 1.116 + std::vector<aiVector3D> mNormals; 1.117 + std::vector<Face> mNormFaces; 1.118 + unsigned int mNumTextures; 1.119 + std::vector<aiVector2D> mTexCoords[AI_MAX_NUMBER_OF_TEXTURECOORDS]; 1.120 + unsigned int mNumColorSets; 1.121 + std::vector<aiColor4D> mColors[AI_MAX_NUMBER_OF_COLOR_SETS]; 1.122 + 1.123 + std::vector<unsigned int> mFaceMaterials; 1.124 + std::vector<Material> mMaterials; 1.125 + 1.126 + std::vector<Bone> mBones; 1.127 + 1.128 + Mesh() { mNumTextures = 0; mNumColorSets = 0; } 1.129 +}; 1.130 + 1.131 +/** Helper structure to represent a XFile frame */ 1.132 +struct Node 1.133 +{ 1.134 + std::string mName; 1.135 + aiMatrix4x4 mTrafoMatrix; 1.136 + Node* mParent; 1.137 + std::vector<Node*> mChildren; 1.138 + std::vector<Mesh*> mMeshes; 1.139 + 1.140 + Node() { mParent = NULL; } 1.141 + Node( Node* pParent) { mParent = pParent; } 1.142 + ~Node() 1.143 + { 1.144 + for( unsigned int a = 0; a < mChildren.size(); a++) 1.145 + delete mChildren[a]; 1.146 + for( unsigned int a = 0; a < mMeshes.size(); a++) 1.147 + delete mMeshes[a]; 1.148 + } 1.149 +}; 1.150 + 1.151 +struct MatrixKey 1.152 +{ 1.153 + double mTime; 1.154 + aiMatrix4x4 mMatrix; 1.155 +}; 1.156 + 1.157 +/** Helper structure representing a single animated bone in a XFile */ 1.158 +struct AnimBone 1.159 +{ 1.160 + std::string mBoneName; 1.161 + std::vector<aiVectorKey> mPosKeys; // either three separate key sequences for position, rotation, scaling 1.162 + std::vector<aiQuatKey> mRotKeys; 1.163 + std::vector<aiVectorKey> mScaleKeys; 1.164 + std::vector<MatrixKey> mTrafoKeys; // or a combined key sequence of transformation matrices. 1.165 +}; 1.166 + 1.167 +/** Helper structure to represent an animation set in a XFile */ 1.168 +struct Animation 1.169 +{ 1.170 + std::string mName; 1.171 + std::vector<AnimBone*> mAnims; 1.172 + 1.173 + ~Animation() 1.174 + { 1.175 + for( unsigned int a = 0; a < mAnims.size(); a++) 1.176 + delete mAnims[a]; 1.177 + } 1.178 +}; 1.179 + 1.180 +/** Helper structure analogue to aiScene */ 1.181 +struct Scene 1.182 +{ 1.183 + Node* mRootNode; 1.184 + 1.185 + std::vector<Mesh*> mGlobalMeshes; // global meshes found outside of any frames 1.186 + std::vector<Material> mGlobalMaterials; // global materials found outside of any meshes. 1.187 + 1.188 + std::vector<Animation*> mAnims; 1.189 + unsigned int mAnimTicksPerSecond; 1.190 + 1.191 + Scene() { mRootNode = NULL; mAnimTicksPerSecond = 0; } 1.192 + ~Scene() 1.193 + { 1.194 + delete mRootNode; 1.195 + for( unsigned int a = 0; a < mGlobalMeshes.size(); a++) 1.196 + delete mGlobalMeshes[a]; 1.197 + for( unsigned int a = 0; a < mAnims.size(); a++) 1.198 + delete mAnims[a]; 1.199 + } 1.200 +}; 1.201 + 1.202 +} // end of namespace XFile 1.203 +} // end of namespace Assimp 1.204 + 1.205 +#endif // AI_XFILEHELPER_H_INC