vrshoot

diff libs/assimp/ColladaLoader.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/ColladaLoader.h	Sat Feb 01 19:58:19 2014 +0200
     1.3 @@ -0,0 +1,241 @@
     1.4 +/** Defines the collada loader class */
     1.5 +
     1.6 +/*
     1.7 +Open Asset Import Library (assimp)
     1.8 +----------------------------------------------------------------------
     1.9 +
    1.10 +Copyright (c) 2006-2012, assimp team
    1.11 +All rights reserved.
    1.12 +
    1.13 +Redistribution and use of this software in source and binary forms, 
    1.14 +with or without modification, are permitted provided that the 
    1.15 +following conditions are met:
    1.16 +
    1.17 +* Redistributions of source code must retain the above
    1.18 +copyright notice, this list of conditions and the
    1.19 +following disclaimer.
    1.20 +
    1.21 +* Redistributions in binary form must reproduce the above
    1.22 +copyright notice, this list of conditions and the
    1.23 +following disclaimer in the documentation and/or other
    1.24 +materials provided with the distribution.
    1.25 +
    1.26 +* Neither the name of the assimp team, nor the names of its
    1.27 +contributors may be used to endorse or promote products
    1.28 +derived from this software without specific prior
    1.29 +written permission of the assimp team.
    1.30 +
    1.31 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
    1.32 +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
    1.33 +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    1.34 +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
    1.35 +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    1.36 +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
    1.37 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    1.38 +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
    1.39 +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
    1.40 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
    1.41 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.42 +
    1.43 +----------------------------------------------------------------------
    1.44 +*/
    1.45 +
    1.46 +#ifndef AI_COLLADALOADER_H_INC
    1.47 +#define AI_COLLADALOADER_H_INC
    1.48 +
    1.49 +#include "BaseImporter.h"
    1.50 +#include "ColladaParser.h"
    1.51 +
    1.52 +namespace Assimp
    1.53 +{
    1.54 +
    1.55 +struct ColladaMeshIndex
    1.56 +{
    1.57 +	std::string mMeshID;
    1.58 +	size_t mSubMesh;
    1.59 +	std::string mMaterial;
    1.60 +	ColladaMeshIndex( const std::string& pMeshID, size_t pSubMesh, const std::string& pMaterial) 
    1.61 +		: mMeshID( pMeshID), mSubMesh( pSubMesh), mMaterial( pMaterial)
    1.62 +	{   }
    1.63 +
    1.64 +	bool operator < (const ColladaMeshIndex& p) const
    1.65 +	{
    1.66 +		if( mMeshID == p.mMeshID) 
    1.67 +		{
    1.68 +			if( mSubMesh == p.mSubMesh)
    1.69 +				return mMaterial < p.mMaterial;
    1.70 +			else 
    1.71 +				return mSubMesh < p.mSubMesh;
    1.72 +		} else
    1.73 +		{
    1.74 +			return mMeshID < p.mMeshID;
    1.75 +		}
    1.76 +	}
    1.77 +};
    1.78 +
    1.79 +/** Loader class to read Collada scenes. Collada is over-engineered to death, with every new iteration bringing
    1.80 + * more useless stuff, so I limited the data to what I think is useful for games. 
    1.81 +*/
    1.82 +class ColladaLoader : public BaseImporter
    1.83 +{
    1.84 +public:
    1.85 +	ColladaLoader();
    1.86 +	~ColladaLoader();
    1.87 +
    1.88 +
    1.89 +public:
    1.90 +	/** Returns whether the class can handle the format of the given file. 
    1.91 +	 * See BaseImporter::CanRead() for details.	*/
    1.92 +	bool CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const;
    1.93 +
    1.94 +protected:
    1.95 +	/** Return importer meta information.
    1.96 +	 * See #BaseImporter::GetInfo for the details
    1.97 +	 */
    1.98 +	const aiImporterDesc* GetInfo () const;
    1.99 +
   1.100 +	void SetupProperties(const Importer* pImp);
   1.101 +
   1.102 +	/** Imports the given file into the given scene structure. 
   1.103 +	 * See BaseImporter::InternReadFile() for details
   1.104 +	 */
   1.105 +	void InternReadFile( const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler);
   1.106 +
   1.107 +	/** Recursively constructs a scene node for the given parser node and returns it. */
   1.108 +	aiNode* BuildHierarchy( const ColladaParser& pParser, const Collada::Node* pNode);
   1.109 +
   1.110 +	/** Resolve node instances */
   1.111 +	void ResolveNodeInstances( const ColladaParser& pParser, const Collada::Node* pNode,
   1.112 +		std::vector<const Collada::Node*>& resolved);
   1.113 +
   1.114 +	/** Builds meshes for the given node and references them */
   1.115 +	void BuildMeshesForNode( const ColladaParser& pParser, const Collada::Node* pNode, 
   1.116 +		aiNode* pTarget);
   1.117 +
   1.118 +	/** Creates a mesh for the given ColladaMesh face subset and returns the newly created mesh */
   1.119 +	aiMesh* CreateMesh( const ColladaParser& pParser, const Collada::Mesh* pSrcMesh, const Collada::SubMesh& pSubMesh, 
   1.120 +		const Collada::Controller* pSrcController, size_t pStartVertex, size_t pStartFace);
   1.121 +
   1.122 +	/** Builds cameras for the given node and references them */
   1.123 +	void BuildCamerasForNode( const ColladaParser& pParser, const Collada::Node* pNode, 
   1.124 +		aiNode* pTarget);
   1.125 +
   1.126 +	/** Builds lights for the given node and references them */
   1.127 +	void BuildLightsForNode( const ColladaParser& pParser, const Collada::Node* pNode, 
   1.128 +		aiNode* pTarget);
   1.129 +
   1.130 +	/** Stores all meshes in the given scene */
   1.131 +	void StoreSceneMeshes( aiScene* pScene);
   1.132 +
   1.133 +	/** Stores all materials in the given scene */
   1.134 +	void StoreSceneMaterials( aiScene* pScene);
   1.135 +
   1.136 +	/** Stores all lights in the given scene */
   1.137 +	void StoreSceneLights( aiScene* pScene);
   1.138 +
   1.139 +	/** Stores all cameras in the given scene */
   1.140 +	void StoreSceneCameras( aiScene* pScene);
   1.141 +
   1.142 +	/** Stores all textures in the given scene */
   1.143 +	void StoreSceneTextures( aiScene* pScene);
   1.144 +
   1.145 +	/** Stores all animations 
   1.146 +	 * @param pScene target scene to store the anims
   1.147 +	 */
   1.148 +	void StoreAnimations( aiScene* pScene, const ColladaParser& pParser);
   1.149 +
   1.150 +	/** Stores all animations for the given source anim and its nested child animations
   1.151 +	 * @param pScene target scene to store the anims
   1.152 +	 * @param pSrcAnim the source animation to process
   1.153 +	 * @param pPrefix Prefix to the name in case of nested animations
   1.154 +	 */
   1.155 +	void StoreAnimations( aiScene* pScene, const ColladaParser& pParser, const Collada::Animation* pSrcAnim, const std::string pPrefix);
   1.156 +
   1.157 +	/** Constructs the animation for the given source anim */
   1.158 +	void CreateAnimation( aiScene* pScene, const ColladaParser& pParser, const Collada::Animation* pSrcAnim, const std::string& pName);
   1.159 +	
   1.160 +	/** Constructs materials from the collada material definitions */
   1.161 +	void BuildMaterials( ColladaParser& pParser, aiScene* pScene);
   1.162 +
   1.163 +	/** Fill materials from the collada material definitions */
   1.164 +	void FillMaterials( const ColladaParser& pParser, aiScene* pScene);
   1.165 +
   1.166 +	/** Resolve UV channel mappings*/
   1.167 +	void ApplyVertexToEffectSemanticMapping(Collada::Sampler& sampler,
   1.168 +		const Collada::SemanticMappingTable& table);
   1.169 +
   1.170 +	/** Add a texture and all of its sampling properties to a material*/
   1.171 +	void AddTexture ( aiMaterial& mat, const ColladaParser& pParser,
   1.172 +		const Collada::Effect& effect,
   1.173 +		const Collada::Sampler& sampler,
   1.174 +		aiTextureType type, unsigned int idx = 0);
   1.175 +
   1.176 +	/** Resolves the texture name for the given effect texture entry */
   1.177 +	aiString FindFilenameForEffectTexture( const ColladaParser& pParser, 
   1.178 +		const Collada::Effect& pEffect, const std::string& pName);
   1.179 +
   1.180 +	/** Converts a path read from a collada file to the usual representation */
   1.181 +	void ConvertPath( aiString& ss);
   1.182 +
   1.183 +	/** Reads a float value from an accessor and its data array.
   1.184 +	 * @param pAccessor The accessor to use for reading
   1.185 +	 * @param pData The data array to read from
   1.186 +	 * @param pIndex The index of the element to retrieve
   1.187 +	 * @param pOffset Offset into the element, for multipart elements such as vectors or matrices
   1.188 +	 * @return the specified value
   1.189 +	 */
   1.190 +	float ReadFloat( const Collada::Accessor& pAccessor, const Collada::Data& pData, size_t pIndex, size_t pOffset) const;
   1.191 +
   1.192 +	/** Reads a string value from an accessor and its data array.
   1.193 +	 * @param pAccessor The accessor to use for reading
   1.194 +	 * @param pData The data array to read from
   1.195 +	 * @param pIndex The index of the element to retrieve
   1.196 +	 * @return the specified value
   1.197 +	 */
   1.198 +	const std::string& ReadString( const Collada::Accessor& pAccessor, const Collada::Data& pData, size_t pIndex) const;
   1.199 +
   1.200 +	/** Recursively collects all nodes into the given array */
   1.201 +	void CollectNodes( const aiNode* pNode, std::vector<const aiNode*>& poNodes) const;
   1.202 +
   1.203 +	/** Finds a node in the collada scene by the given name */
   1.204 +	const Collada::Node* FindNode( const Collada::Node* pNode, const std::string& pName) const;
   1.205 +	/** Finds a node in the collada scene by the given SID */
   1.206 +	const Collada::Node* FindNodeBySID( const Collada::Node* pNode, const std::string& pSID) const;
   1.207 +
   1.208 +	/** Finds a proper name for a node derived from the collada-node's properties */
   1.209 +	std::string FindNameForNode( const Collada::Node* pNode) const;
   1.210 +
   1.211 +protected:
   1.212 +	/** Filename, for a verbose error message */
   1.213 +	std::string mFileName;
   1.214 +
   1.215 +	/** Which mesh-material compound was stored under which mesh ID */
   1.216 +	std::map<ColladaMeshIndex, size_t> mMeshIndexByID;
   1.217 +
   1.218 +	/** Which material was stored under which index in the scene */
   1.219 +	std::map<std::string, size_t> mMaterialIndexByName;
   1.220 +
   1.221 +	/** Accumulated meshes for the target scene */
   1.222 +	std::vector<aiMesh*> mMeshes;
   1.223 +
   1.224 +	/** Temporary material list */
   1.225 +	std::vector<std::pair<Collada::Effect*, aiMaterial*> > newMats;
   1.226 +
   1.227 +	/** Temporary camera list */
   1.228 +	std::vector<aiCamera*> mCameras;
   1.229 +
   1.230 +	/** Temporary light list */
   1.231 +	std::vector<aiLight*> mLights;
   1.232 +
   1.233 +	/** Temporary texture list */
   1.234 +	std::vector<aiTexture*> mTextures;
   1.235 +
   1.236 +	/** Accumulated animations for the target scene */
   1.237 +	std::vector<aiAnimation*> mAnims;
   1.238 +
   1.239 +	bool noSkeletonMesh;
   1.240 +};
   1.241 +
   1.242 +} // end of namespace Assimp
   1.243 +
   1.244 +#endif // AI_COLLADALOADER_H_INC