vrshoot

view libs/assimp/ColladaLoader.h @ 1:e7ca128b8713

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