nuclear@0: /** Defines the collada loader class */ nuclear@0: nuclear@0: /* nuclear@0: Open Asset Import Library (assimp) nuclear@0: ---------------------------------------------------------------------- nuclear@0: nuclear@0: Copyright (c) 2006-2012, assimp team nuclear@0: All rights reserved. nuclear@0: nuclear@0: Redistribution and use of this software in source and binary forms, nuclear@0: with or without modification, are permitted provided that the nuclear@0: following conditions are met: nuclear@0: nuclear@0: * Redistributions of source code must retain the above nuclear@0: copyright notice, this list of conditions and the nuclear@0: following disclaimer. nuclear@0: nuclear@0: * Redistributions in binary form must reproduce the above nuclear@0: copyright notice, this list of conditions and the nuclear@0: following disclaimer in the documentation and/or other nuclear@0: materials provided with the distribution. nuclear@0: nuclear@0: * Neither the name of the assimp team, nor the names of its nuclear@0: contributors may be used to endorse or promote products nuclear@0: derived from this software without specific prior nuclear@0: written permission of the assimp team. nuclear@0: nuclear@0: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS nuclear@0: "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT nuclear@0: LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR nuclear@0: A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT nuclear@0: OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, nuclear@0: SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT nuclear@0: LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, nuclear@0: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY nuclear@0: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT nuclear@0: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE nuclear@0: OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. nuclear@0: nuclear@0: ---------------------------------------------------------------------- nuclear@0: */ nuclear@0: nuclear@0: #ifndef AI_COLLADALOADER_H_INC nuclear@0: #define AI_COLLADALOADER_H_INC nuclear@0: nuclear@0: #include "BaseImporter.h" nuclear@0: #include "ColladaParser.h" nuclear@0: nuclear@0: namespace Assimp nuclear@0: { nuclear@0: nuclear@0: struct ColladaMeshIndex nuclear@0: { nuclear@0: std::string mMeshID; nuclear@0: size_t mSubMesh; nuclear@0: std::string mMaterial; nuclear@0: ColladaMeshIndex( const std::string& pMeshID, size_t pSubMesh, const std::string& pMaterial) nuclear@0: : mMeshID( pMeshID), mSubMesh( pSubMesh), mMaterial( pMaterial) nuclear@0: { } nuclear@0: nuclear@0: bool operator < (const ColladaMeshIndex& p) const nuclear@0: { nuclear@0: if( mMeshID == p.mMeshID) nuclear@0: { nuclear@0: if( mSubMesh == p.mSubMesh) nuclear@0: return mMaterial < p.mMaterial; nuclear@0: else nuclear@0: return mSubMesh < p.mSubMesh; nuclear@0: } else nuclear@0: { nuclear@0: return mMeshID < p.mMeshID; nuclear@0: } nuclear@0: } nuclear@0: }; nuclear@0: nuclear@0: /** Loader class to read Collada scenes. Collada is over-engineered to death, with every new iteration bringing nuclear@0: * more useless stuff, so I limited the data to what I think is useful for games. nuclear@0: */ nuclear@0: class ColladaLoader : public BaseImporter nuclear@0: { nuclear@0: public: nuclear@0: ColladaLoader(); nuclear@0: ~ColladaLoader(); nuclear@0: nuclear@0: nuclear@0: public: nuclear@0: /** Returns whether the class can handle the format of the given file. nuclear@0: * See BaseImporter::CanRead() for details. */ nuclear@0: bool CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const; nuclear@0: nuclear@0: protected: nuclear@0: /** Return importer meta information. nuclear@0: * See #BaseImporter::GetInfo for the details nuclear@0: */ nuclear@0: const aiImporterDesc* GetInfo () const; nuclear@0: nuclear@0: void SetupProperties(const Importer* pImp); nuclear@0: nuclear@0: /** Imports the given file into the given scene structure. nuclear@0: * See BaseImporter::InternReadFile() for details nuclear@0: */ nuclear@0: void InternReadFile( const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler); nuclear@0: nuclear@0: /** Recursively constructs a scene node for the given parser node and returns it. */ nuclear@0: aiNode* BuildHierarchy( const ColladaParser& pParser, const Collada::Node* pNode); nuclear@0: nuclear@0: /** Resolve node instances */ nuclear@0: void ResolveNodeInstances( const ColladaParser& pParser, const Collada::Node* pNode, nuclear@0: std::vector& resolved); nuclear@0: nuclear@0: /** Builds meshes for the given node and references them */ nuclear@0: void BuildMeshesForNode( const ColladaParser& pParser, const Collada::Node* pNode, nuclear@0: aiNode* pTarget); nuclear@0: nuclear@0: /** Creates a mesh for the given ColladaMesh face subset and returns the newly created mesh */ nuclear@0: aiMesh* CreateMesh( const ColladaParser& pParser, const Collada::Mesh* pSrcMesh, const Collada::SubMesh& pSubMesh, nuclear@0: const Collada::Controller* pSrcController, size_t pStartVertex, size_t pStartFace); nuclear@0: nuclear@0: /** Builds cameras for the given node and references them */ nuclear@0: void BuildCamerasForNode( const ColladaParser& pParser, const Collada::Node* pNode, nuclear@0: aiNode* pTarget); nuclear@0: nuclear@0: /** Builds lights for the given node and references them */ nuclear@0: void BuildLightsForNode( const ColladaParser& pParser, const Collada::Node* pNode, nuclear@0: aiNode* pTarget); nuclear@0: nuclear@0: /** Stores all meshes in the given scene */ nuclear@0: void StoreSceneMeshes( aiScene* pScene); nuclear@0: nuclear@0: /** Stores all materials in the given scene */ nuclear@0: void StoreSceneMaterials( aiScene* pScene); nuclear@0: nuclear@0: /** Stores all lights in the given scene */ nuclear@0: void StoreSceneLights( aiScene* pScene); nuclear@0: nuclear@0: /** Stores all cameras in the given scene */ nuclear@0: void StoreSceneCameras( aiScene* pScene); nuclear@0: nuclear@0: /** Stores all textures in the given scene */ nuclear@0: void StoreSceneTextures( aiScene* pScene); nuclear@0: nuclear@0: /** Stores all animations nuclear@0: * @param pScene target scene to store the anims nuclear@0: */ nuclear@0: void StoreAnimations( aiScene* pScene, const ColladaParser& pParser); nuclear@0: nuclear@0: /** Stores all animations for the given source anim and its nested child animations nuclear@0: * @param pScene target scene to store the anims nuclear@0: * @param pSrcAnim the source animation to process nuclear@0: * @param pPrefix Prefix to the name in case of nested animations nuclear@0: */ nuclear@0: void StoreAnimations( aiScene* pScene, const ColladaParser& pParser, const Collada::Animation* pSrcAnim, const std::string pPrefix); nuclear@0: nuclear@0: /** Constructs the animation for the given source anim */ nuclear@0: void CreateAnimation( aiScene* pScene, const ColladaParser& pParser, const Collada::Animation* pSrcAnim, const std::string& pName); nuclear@0: nuclear@0: /** Constructs materials from the collada material definitions */ nuclear@0: void BuildMaterials( ColladaParser& pParser, aiScene* pScene); nuclear@0: nuclear@0: /** Fill materials from the collada material definitions */ nuclear@0: void FillMaterials( const ColladaParser& pParser, aiScene* pScene); nuclear@0: nuclear@0: /** Resolve UV channel mappings*/ nuclear@0: void ApplyVertexToEffectSemanticMapping(Collada::Sampler& sampler, nuclear@0: const Collada::SemanticMappingTable& table); nuclear@0: nuclear@0: /** Add a texture and all of its sampling properties to a material*/ nuclear@0: void AddTexture ( aiMaterial& mat, const ColladaParser& pParser, nuclear@0: const Collada::Effect& effect, nuclear@0: const Collada::Sampler& sampler, nuclear@0: aiTextureType type, unsigned int idx = 0); nuclear@0: nuclear@0: /** Resolves the texture name for the given effect texture entry */ nuclear@0: aiString FindFilenameForEffectTexture( const ColladaParser& pParser, nuclear@0: const Collada::Effect& pEffect, const std::string& pName); nuclear@0: nuclear@0: /** Converts a path read from a collada file to the usual representation */ nuclear@0: void ConvertPath( aiString& ss); nuclear@0: nuclear@0: /** Reads a float value from an accessor and its data array. nuclear@0: * @param pAccessor The accessor to use for reading nuclear@0: * @param pData The data array to read from nuclear@0: * @param pIndex The index of the element to retrieve nuclear@0: * @param pOffset Offset into the element, for multipart elements such as vectors or matrices nuclear@0: * @return the specified value nuclear@0: */ nuclear@0: float ReadFloat( const Collada::Accessor& pAccessor, const Collada::Data& pData, size_t pIndex, size_t pOffset) const; nuclear@0: nuclear@0: /** Reads a string value from an accessor and its data array. nuclear@0: * @param pAccessor The accessor to use for reading nuclear@0: * @param pData The data array to read from nuclear@0: * @param pIndex The index of the element to retrieve nuclear@0: * @return the specified value nuclear@0: */ nuclear@0: const std::string& ReadString( const Collada::Accessor& pAccessor, const Collada::Data& pData, size_t pIndex) const; nuclear@0: nuclear@0: /** Recursively collects all nodes into the given array */ nuclear@0: void CollectNodes( const aiNode* pNode, std::vector& poNodes) const; nuclear@0: nuclear@0: /** Finds a node in the collada scene by the given name */ nuclear@0: const Collada::Node* FindNode( const Collada::Node* pNode, const std::string& pName) const; nuclear@0: /** Finds a node in the collada scene by the given SID */ nuclear@0: const Collada::Node* FindNodeBySID( const Collada::Node* pNode, const std::string& pSID) const; nuclear@0: nuclear@0: /** Finds a proper name for a node derived from the collada-node's properties */ nuclear@0: std::string FindNameForNode( const Collada::Node* pNode) const; nuclear@0: nuclear@0: protected: nuclear@0: /** Filename, for a verbose error message */ nuclear@0: std::string mFileName; nuclear@0: nuclear@0: /** Which mesh-material compound was stored under which mesh ID */ nuclear@0: std::map mMeshIndexByID; nuclear@0: nuclear@0: /** Which material was stored under which index in the scene */ nuclear@0: std::map mMaterialIndexByName; nuclear@0: nuclear@0: /** Accumulated meshes for the target scene */ nuclear@0: std::vector mMeshes; nuclear@0: nuclear@0: /** Temporary material list */ nuclear@0: std::vector > newMats; nuclear@0: nuclear@0: /** Temporary camera list */ nuclear@0: std::vector mCameras; nuclear@0: nuclear@0: /** Temporary light list */ nuclear@0: std::vector mLights; nuclear@0: nuclear@0: /** Temporary texture list */ nuclear@0: std::vector mTextures; nuclear@0: nuclear@0: /** Accumulated animations for the target scene */ nuclear@0: std::vector mAnims; nuclear@0: nuclear@0: bool noSkeletonMesh; nuclear@0: }; nuclear@0: nuclear@0: } // end of namespace Assimp nuclear@0: nuclear@0: #endif // AI_COLLADALOADER_H_INC