vrshoot

annotate libs/assimp/ColladaLoader.h @ 3:c179c72369be

rename candy->vr
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 03 Feb 2014 08:52:13 +0200
parents
children
rev   line source
nuclear@0 1 /** Defines the collada loader class */
nuclear@0 2
nuclear@0 3 /*
nuclear@0 4 Open Asset Import Library (assimp)
nuclear@0 5 ----------------------------------------------------------------------
nuclear@0 6
nuclear@0 7 Copyright (c) 2006-2012, assimp team
nuclear@0 8 All rights reserved.
nuclear@0 9
nuclear@0 10 Redistribution and use of this software in source and binary forms,
nuclear@0 11 with or without modification, are permitted provided that the
nuclear@0 12 following conditions are met:
nuclear@0 13
nuclear@0 14 * Redistributions of source code must retain the above
nuclear@0 15 copyright notice, this list of conditions and the
nuclear@0 16 following disclaimer.
nuclear@0 17
nuclear@0 18 * Redistributions in binary form must reproduce the above
nuclear@0 19 copyright notice, this list of conditions and the
nuclear@0 20 following disclaimer in the documentation and/or other
nuclear@0 21 materials provided with the distribution.
nuclear@0 22
nuclear@0 23 * Neither the name of the assimp team, nor the names of its
nuclear@0 24 contributors may be used to endorse or promote products
nuclear@0 25 derived from this software without specific prior
nuclear@0 26 written permission of the assimp team.
nuclear@0 27
nuclear@0 28 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
nuclear@0 29 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
nuclear@0 30 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
nuclear@0 31 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
nuclear@0 32 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
nuclear@0 33 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
nuclear@0 34 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
nuclear@0 35 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
nuclear@0 36 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
nuclear@0 37 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
nuclear@0 38 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
nuclear@0 39
nuclear@0 40 ----------------------------------------------------------------------
nuclear@0 41 */
nuclear@0 42
nuclear@0 43 #ifndef AI_COLLADALOADER_H_INC
nuclear@0 44 #define AI_COLLADALOADER_H_INC
nuclear@0 45
nuclear@0 46 #include "BaseImporter.h"
nuclear@0 47 #include "ColladaParser.h"
nuclear@0 48
nuclear@0 49 namespace Assimp
nuclear@0 50 {
nuclear@0 51
nuclear@0 52 struct ColladaMeshIndex
nuclear@0 53 {
nuclear@0 54 std::string mMeshID;
nuclear@0 55 size_t mSubMesh;
nuclear@0 56 std::string mMaterial;
nuclear@0 57 ColladaMeshIndex( const std::string& pMeshID, size_t pSubMesh, const std::string& pMaterial)
nuclear@0 58 : mMeshID( pMeshID), mSubMesh( pSubMesh), mMaterial( pMaterial)
nuclear@0 59 { }
nuclear@0 60
nuclear@0 61 bool operator < (const ColladaMeshIndex& p) const
nuclear@0 62 {
nuclear@0 63 if( mMeshID == p.mMeshID)
nuclear@0 64 {
nuclear@0 65 if( mSubMesh == p.mSubMesh)
nuclear@0 66 return mMaterial < p.mMaterial;
nuclear@0 67 else
nuclear@0 68 return mSubMesh < p.mSubMesh;
nuclear@0 69 } else
nuclear@0 70 {
nuclear@0 71 return mMeshID < p.mMeshID;
nuclear@0 72 }
nuclear@0 73 }
nuclear@0 74 };
nuclear@0 75
nuclear@0 76 /** Loader class to read Collada scenes. Collada is over-engineered to death, with every new iteration bringing
nuclear@0 77 * more useless stuff, so I limited the data to what I think is useful for games.
nuclear@0 78 */
nuclear@0 79 class ColladaLoader : public BaseImporter
nuclear@0 80 {
nuclear@0 81 public:
nuclear@0 82 ColladaLoader();
nuclear@0 83 ~ColladaLoader();
nuclear@0 84
nuclear@0 85
nuclear@0 86 public:
nuclear@0 87 /** Returns whether the class can handle the format of the given file.
nuclear@0 88 * See BaseImporter::CanRead() for details. */
nuclear@0 89 bool CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const;
nuclear@0 90
nuclear@0 91 protected:
nuclear@0 92 /** Return importer meta information.
nuclear@0 93 * See #BaseImporter::GetInfo for the details
nuclear@0 94 */
nuclear@0 95 const aiImporterDesc* GetInfo () const;
nuclear@0 96
nuclear@0 97 void SetupProperties(const Importer* pImp);
nuclear@0 98
nuclear@0 99 /** Imports the given file into the given scene structure.
nuclear@0 100 * See BaseImporter::InternReadFile() for details
nuclear@0 101 */
nuclear@0 102 void InternReadFile( const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler);
nuclear@0 103
nuclear@0 104 /** Recursively constructs a scene node for the given parser node and returns it. */
nuclear@0 105 aiNode* BuildHierarchy( const ColladaParser& pParser, const Collada::Node* pNode);
nuclear@0 106
nuclear@0 107 /** Resolve node instances */
nuclear@0 108 void ResolveNodeInstances( const ColladaParser& pParser, const Collada::Node* pNode,
nuclear@0 109 std::vector<const Collada::Node*>& resolved);
nuclear@0 110
nuclear@0 111 /** Builds meshes for the given node and references them */
nuclear@0 112 void BuildMeshesForNode( const ColladaParser& pParser, const Collada::Node* pNode,
nuclear@0 113 aiNode* pTarget);
nuclear@0 114
nuclear@0 115 /** Creates a mesh for the given ColladaMesh face subset and returns the newly created mesh */
nuclear@0 116 aiMesh* CreateMesh( const ColladaParser& pParser, const Collada::Mesh* pSrcMesh, const Collada::SubMesh& pSubMesh,
nuclear@0 117 const Collada::Controller* pSrcController, size_t pStartVertex, size_t pStartFace);
nuclear@0 118
nuclear@0 119 /** Builds cameras for the given node and references them */
nuclear@0 120 void BuildCamerasForNode( const ColladaParser& pParser, const Collada::Node* pNode,
nuclear@0 121 aiNode* pTarget);
nuclear@0 122
nuclear@0 123 /** Builds lights for the given node and references them */
nuclear@0 124 void BuildLightsForNode( const ColladaParser& pParser, const Collada::Node* pNode,
nuclear@0 125 aiNode* pTarget);
nuclear@0 126
nuclear@0 127 /** Stores all meshes in the given scene */
nuclear@0 128 void StoreSceneMeshes( aiScene* pScene);
nuclear@0 129
nuclear@0 130 /** Stores all materials in the given scene */
nuclear@0 131 void StoreSceneMaterials( aiScene* pScene);
nuclear@0 132
nuclear@0 133 /** Stores all lights in the given scene */
nuclear@0 134 void StoreSceneLights( aiScene* pScene);
nuclear@0 135
nuclear@0 136 /** Stores all cameras in the given scene */
nuclear@0 137 void StoreSceneCameras( aiScene* pScene);
nuclear@0 138
nuclear@0 139 /** Stores all textures in the given scene */
nuclear@0 140 void StoreSceneTextures( aiScene* pScene);
nuclear@0 141
nuclear@0 142 /** Stores all animations
nuclear@0 143 * @param pScene target scene to store the anims
nuclear@0 144 */
nuclear@0 145 void StoreAnimations( aiScene* pScene, const ColladaParser& pParser);
nuclear@0 146
nuclear@0 147 /** Stores all animations for the given source anim and its nested child animations
nuclear@0 148 * @param pScene target scene to store the anims
nuclear@0 149 * @param pSrcAnim the source animation to process
nuclear@0 150 * @param pPrefix Prefix to the name in case of nested animations
nuclear@0 151 */
nuclear@0 152 void StoreAnimations( aiScene* pScene, const ColladaParser& pParser, const Collada::Animation* pSrcAnim, const std::string pPrefix);
nuclear@0 153
nuclear@0 154 /** Constructs the animation for the given source anim */
nuclear@0 155 void CreateAnimation( aiScene* pScene, const ColladaParser& pParser, const Collada::Animation* pSrcAnim, const std::string& pName);
nuclear@0 156
nuclear@0 157 /** Constructs materials from the collada material definitions */
nuclear@0 158 void BuildMaterials( ColladaParser& pParser, aiScene* pScene);
nuclear@0 159
nuclear@0 160 /** Fill materials from the collada material definitions */
nuclear@0 161 void FillMaterials( const ColladaParser& pParser, aiScene* pScene);
nuclear@0 162
nuclear@0 163 /** Resolve UV channel mappings*/
nuclear@0 164 void ApplyVertexToEffectSemanticMapping(Collada::Sampler& sampler,
nuclear@0 165 const Collada::SemanticMappingTable& table);
nuclear@0 166
nuclear@0 167 /** Add a texture and all of its sampling properties to a material*/
nuclear@0 168 void AddTexture ( aiMaterial& mat, const ColladaParser& pParser,
nuclear@0 169 const Collada::Effect& effect,
nuclear@0 170 const Collada::Sampler& sampler,
nuclear@0 171 aiTextureType type, unsigned int idx = 0);
nuclear@0 172
nuclear@0 173 /** Resolves the texture name for the given effect texture entry */
nuclear@0 174 aiString FindFilenameForEffectTexture( const ColladaParser& pParser,
nuclear@0 175 const Collada::Effect& pEffect, const std::string& pName);
nuclear@0 176
nuclear@0 177 /** Converts a path read from a collada file to the usual representation */
nuclear@0 178 void ConvertPath( aiString& ss);
nuclear@0 179
nuclear@0 180 /** Reads a float value from an accessor and its data array.
nuclear@0 181 * @param pAccessor The accessor to use for reading
nuclear@0 182 * @param pData The data array to read from
nuclear@0 183 * @param pIndex The index of the element to retrieve
nuclear@0 184 * @param pOffset Offset into the element, for multipart elements such as vectors or matrices
nuclear@0 185 * @return the specified value
nuclear@0 186 */
nuclear@0 187 float ReadFloat( const Collada::Accessor& pAccessor, const Collada::Data& pData, size_t pIndex, size_t pOffset) const;
nuclear@0 188
nuclear@0 189 /** Reads a string value from an accessor and its data array.
nuclear@0 190 * @param pAccessor The accessor to use for reading
nuclear@0 191 * @param pData The data array to read from
nuclear@0 192 * @param pIndex The index of the element to retrieve
nuclear@0 193 * @return the specified value
nuclear@0 194 */
nuclear@0 195 const std::string& ReadString( const Collada::Accessor& pAccessor, const Collada::Data& pData, size_t pIndex) const;
nuclear@0 196
nuclear@0 197 /** Recursively collects all nodes into the given array */
nuclear@0 198 void CollectNodes( const aiNode* pNode, std::vector<const aiNode*>& poNodes) const;
nuclear@0 199
nuclear@0 200 /** Finds a node in the collada scene by the given name */
nuclear@0 201 const Collada::Node* FindNode( const Collada::Node* pNode, const std::string& pName) const;
nuclear@0 202 /** Finds a node in the collada scene by the given SID */
nuclear@0 203 const Collada::Node* FindNodeBySID( const Collada::Node* pNode, const std::string& pSID) const;
nuclear@0 204
nuclear@0 205 /** Finds a proper name for a node derived from the collada-node's properties */
nuclear@0 206 std::string FindNameForNode( const Collada::Node* pNode) const;
nuclear@0 207
nuclear@0 208 protected:
nuclear@0 209 /** Filename, for a verbose error message */
nuclear@0 210 std::string mFileName;
nuclear@0 211
nuclear@0 212 /** Which mesh-material compound was stored under which mesh ID */
nuclear@0 213 std::map<ColladaMeshIndex, size_t> mMeshIndexByID;
nuclear@0 214
nuclear@0 215 /** Which material was stored under which index in the scene */
nuclear@0 216 std::map<std::string, size_t> mMaterialIndexByName;
nuclear@0 217
nuclear@0 218 /** Accumulated meshes for the target scene */
nuclear@0 219 std::vector<aiMesh*> mMeshes;
nuclear@0 220
nuclear@0 221 /** Temporary material list */
nuclear@0 222 std::vector<std::pair<Collada::Effect*, aiMaterial*> > newMats;
nuclear@0 223
nuclear@0 224 /** Temporary camera list */
nuclear@0 225 std::vector<aiCamera*> mCameras;
nuclear@0 226
nuclear@0 227 /** Temporary light list */
nuclear@0 228 std::vector<aiLight*> mLights;
nuclear@0 229
nuclear@0 230 /** Temporary texture list */
nuclear@0 231 std::vector<aiTexture*> mTextures;
nuclear@0 232
nuclear@0 233 /** Accumulated animations for the target scene */
nuclear@0 234 std::vector<aiAnimation*> mAnims;
nuclear@0 235
nuclear@0 236 bool noSkeletonMesh;
nuclear@0 237 };
nuclear@0 238
nuclear@0 239 } // end of namespace Assimp
nuclear@0 240
nuclear@0 241 #endif // AI_COLLADALOADER_H_INC