vrshoot
diff libs/assimp/SceneCombiner.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/SceneCombiner.h Sat Feb 01 19:58:19 2014 +0200 1.3 @@ -0,0 +1,365 @@ 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 +/** @file Declares a helper class, "SceneCombiner" providing various 1.45 + * utilities to merge scenes. 1.46 + */ 1.47 +#ifndef AI_SCENE_COMBINER_H_INC 1.48 +#define AI_SCENE_COMBINER_H_INC 1.49 + 1.50 +#include "assimp/ai_assert.h" 1.51 + 1.52 +namespace Assimp { 1.53 + 1.54 +// --------------------------------------------------------------------------- 1.55 +/** \brief Helper data structure for SceneCombiner. 1.56 + * 1.57 + * Describes to which node a scene must be attached to. 1.58 + */ 1.59 +struct AttachmentInfo 1.60 +{ 1.61 + AttachmentInfo() 1.62 + : scene (NULL) 1.63 + , attachToNode (NULL) 1.64 + {} 1.65 + 1.66 + AttachmentInfo(aiScene* _scene, aiNode* _attachToNode) 1.67 + : scene (_scene) 1.68 + , attachToNode (_attachToNode) 1.69 + {} 1.70 + 1.71 + aiScene* scene; 1.72 + aiNode* attachToNode; 1.73 +}; 1.74 + 1.75 +// --------------------------------------------------------------------------- 1.76 +struct NodeAttachmentInfo 1.77 +{ 1.78 + NodeAttachmentInfo() 1.79 + : node (NULL) 1.80 + , attachToNode (NULL) 1.81 + , resolved (false) 1.82 + , src_idx (SIZE_MAX) 1.83 + {} 1.84 + 1.85 + NodeAttachmentInfo(aiNode* _scene, aiNode* _attachToNode,size_t idx) 1.86 + : node (_scene) 1.87 + , attachToNode (_attachToNode) 1.88 + , resolved (false) 1.89 + , src_idx (idx) 1.90 + {} 1.91 + 1.92 + aiNode* node; 1.93 + aiNode* attachToNode; 1.94 + bool resolved; 1.95 + size_t src_idx; 1.96 +}; 1.97 + 1.98 +// --------------------------------------------------------------------------- 1.99 +/** @def AI_INT_MERGE_SCENE_GEN_UNIQUE_NAMES 1.100 + * Generate unique names for all named scene items 1.101 + */ 1.102 +#define AI_INT_MERGE_SCENE_GEN_UNIQUE_NAMES 0x1 1.103 + 1.104 +/** @def AI_INT_MERGE_SCENE_GEN_UNIQUE_MATNAMES 1.105 + * Generate unique names for materials, too. 1.106 + * This is not absolutely required to pass the validation. 1.107 + */ 1.108 +#define AI_INT_MERGE_SCENE_GEN_UNIQUE_MATNAMES 0x2 1.109 + 1.110 +/** @def AI_INT_MERGE_SCENE_DUPLICATES_DEEP_CPY 1.111 + * Use deep copies of duplicate scenes 1.112 + */ 1.113 +#define AI_INT_MERGE_SCENE_DUPLICATES_DEEP_CPY 0x4 1.114 + 1.115 +/** @def AI_INT_MERGE_SCENE_RESOLVE_CROSS_ATTACHMENTS 1.116 + * If attachment nodes are not found in the given master scene, 1.117 + * search the other imported scenes for them in an any order. 1.118 + */ 1.119 +#define AI_INT_MERGE_SCENE_RESOLVE_CROSS_ATTACHMENTS 0x8 1.120 + 1.121 +/** @def AI_INT_MERGE_SCENE_GEN_UNIQUE_NAMES_IF_NECESSARY 1.122 + * Can be combined with AI_INT_MERGE_SCENE_GEN_UNIQUE_NAMES. 1.123 + * Unique names are generated, but only if this is absolutely 1.124 + * required to avoid name conflicts. 1.125 + */ 1.126 +#define AI_INT_MERGE_SCENE_GEN_UNIQUE_NAMES_IF_NECESSARY 0x10 1.127 + 1.128 + 1.129 +typedef std::pair<aiBone*,unsigned int> BoneSrcIndex; 1.130 + 1.131 +// --------------------------------------------------------------------------- 1.132 +/** @brief Helper data structure for SceneCombiner::MergeBones. 1.133 + */ 1.134 +struct BoneWithHash : public std::pair<uint32_t,aiString*> { 1.135 + std::vector<BoneSrcIndex> pSrcBones; 1.136 +}; 1.137 + 1.138 + 1.139 +// --------------------------------------------------------------------------- 1.140 +/** @brief Utility for SceneCombiner 1.141 + */ 1.142 +struct SceneHelper 1.143 +{ 1.144 + SceneHelper () 1.145 + : scene (NULL) 1.146 + , idlen (0) 1.147 + { 1.148 + id[0] = 0; 1.149 + } 1.150 + 1.151 + SceneHelper (aiScene* _scene) 1.152 + : scene (_scene) 1.153 + , idlen (0) 1.154 + { 1.155 + id[0] = 0; 1.156 + } 1.157 + 1.158 + AI_FORCE_INLINE aiScene* operator-> () const 1.159 + { 1.160 + return scene; 1.161 + } 1.162 + 1.163 + // scene we're working on 1.164 + aiScene* scene; 1.165 + 1.166 + // prefix to be added to all identifiers in the scene ... 1.167 + char id [32]; 1.168 + 1.169 + // and its strlen() 1.170 + unsigned int idlen; 1.171 + 1.172 + // hash table to quickly check whether a name is contained in the scene 1.173 + std::set<unsigned int> hashes; 1.174 +}; 1.175 + 1.176 +// --------------------------------------------------------------------------- 1.177 +/** \brief Static helper class providing various utilities to merge two 1.178 + * scenes. It is intended as internal utility and NOT for use by 1.179 + * applications. 1.180 + * 1.181 + * The class is currently being used by various postprocessing steps 1.182 + * and loaders (ie. LWS). 1.183 + */ 1.184 +class SceneCombiner 1.185 +{ 1.186 + // class cannot be instanced 1.187 + SceneCombiner() {} 1.188 + 1.189 +public: 1.190 + 1.191 + // ------------------------------------------------------------------- 1.192 + /** Merges two or more scenes. 1.193 + * 1.194 + * @param dest Receives a pointer to the destination scene. If the 1.195 + * pointer doesn't point to NULL when the function is called, the 1.196 + * existing scene is cleared and refilled. 1.197 + * @param src Non-empty list of scenes to be merged. The function 1.198 + * deletes the input scenes afterwards. There may be duplicate scenes. 1.199 + * @param flags Combination of the AI_INT_MERGE_SCENE flags defined above 1.200 + */ 1.201 + static void MergeScenes(aiScene** dest,std::vector<aiScene*>& src, 1.202 + unsigned int flags = 0); 1.203 + 1.204 + 1.205 + // ------------------------------------------------------------------- 1.206 + /** Merges two or more scenes and attaches all sceenes to a specific 1.207 + * position in the node graph of the masteer scene. 1.208 + * 1.209 + * @param dest Receives a pointer to the destination scene. If the 1.210 + * pointer doesn't point to NULL when the function is called, the 1.211 + * existing scene is cleared and refilled. 1.212 + * @param master Master scene. It will be deleted afterwards. All 1.213 + * other scenes will be inserted in its node graph. 1.214 + * @param src Non-empty list of scenes to be merged along with their 1.215 + * corresponding attachment points in the master scene. The function 1.216 + * deletes the input scenes afterwards. There may be duplicate scenes. 1.217 + * @param flags Combination of the AI_INT_MERGE_SCENE flags defined above 1.218 + */ 1.219 + static void MergeScenes(aiScene** dest, aiScene* master, 1.220 + std::vector<AttachmentInfo>& src, 1.221 + unsigned int flags = 0); 1.222 + 1.223 + 1.224 + // ------------------------------------------------------------------- 1.225 + /** Merges two or more meshes 1.226 + * 1.227 + * The meshes should have equal vertex formats. Only components 1.228 + * that are provided by ALL meshes will be present in the output mesh. 1.229 + * An exception is made for VColors - they are set to black. The 1.230 + * meshes should have the same material indices, too. The output 1.231 + * material index is always the material index of the first mesh. 1.232 + * 1.233 + * @param dest Destination mesh. Must be empty. 1.234 + * @param flags Currently no parameters 1.235 + * @param begin First mesh to be processed 1.236 + * @param end Points to the mesh after the last mesh to be processed 1.237 + */ 1.238 + static void MergeMeshes(aiMesh** dest,unsigned int flags, 1.239 + std::vector<aiMesh*>::const_iterator begin, 1.240 + std::vector<aiMesh*>::const_iterator end); 1.241 + 1.242 + 1.243 + // ------------------------------------------------------------------- 1.244 + /** Merges two or more bones 1.245 + * 1.246 + * @param out Mesh to receive the output bone list 1.247 + * @param flags Currently no parameters 1.248 + * @param begin First mesh to be processed 1.249 + * @param end Points to the mesh after the last mesh to be processed 1.250 + */ 1.251 + static void MergeBones(aiMesh* out,std::vector<aiMesh*>::const_iterator it, 1.252 + std::vector<aiMesh*>::const_iterator end); 1.253 + 1.254 + 1.255 + // ------------------------------------------------------------------- 1.256 + /** Builds a list of uniquely named bones in a mesh list 1.257 + * 1.258 + * @param asBones Receives the output list 1.259 + * @param it First mesh to be processed 1.260 + * @param end Last mesh to be processed 1.261 + */ 1.262 + static void BuildUniqueBoneList(std::list<BoneWithHash>& asBones, 1.263 + std::vector<aiMesh*>::const_iterator it, 1.264 + std::vector<aiMesh*>::const_iterator end); 1.265 + 1.266 + // ------------------------------------------------------------------- 1.267 + /** Add a name prefix to all nodes in a scene. 1.268 + * 1.269 + * @param Current node. This function is called recursively. 1.270 + * @param prefix Prefix to be added to all nodes 1.271 + * @param len STring length 1.272 + */ 1.273 + static void AddNodePrefixes(aiNode* node, const char* prefix, 1.274 + unsigned int len); 1.275 + 1.276 + // ------------------------------------------------------------------- 1.277 + /** Add an offset to all mesh indices in a node graph 1.278 + * 1.279 + * @param Current node. This function is called recursively. 1.280 + * @param offset Offset to be added to all mesh indices 1.281 + */ 1.282 + static void OffsetNodeMeshIndices (aiNode* node, unsigned int offset); 1.283 + 1.284 + // ------------------------------------------------------------------- 1.285 + /** Attach a list of node graphs to well-defined nodes in a master 1.286 + * graph. This is a helper for MergeScenes() 1.287 + * 1.288 + * @param master Master scene 1.289 + * @param srcList List of source scenes along with their attachment 1.290 + * points. If an attachment point is NULL (or does not exist in 1.291 + * the master graph), a scene is attached to the root of the master 1.292 + * graph (as an additional child node) 1.293 + * @duplicates List of duplicates. If elem[n] == n the scene is not 1.294 + * a duplicate. Otherwise elem[n] links scene n to its first occurence. 1.295 + */ 1.296 + static void AttachToGraph ( aiScene* master, 1.297 + std::vector<NodeAttachmentInfo>& srcList); 1.298 + 1.299 + static void AttachToGraph (aiNode* attach, 1.300 + std::vector<NodeAttachmentInfo>& srcList); 1.301 + 1.302 + 1.303 + // ------------------------------------------------------------------- 1.304 + /** Get a deep copy of a scene 1.305 + * 1.306 + * @param dest Receives a pointer to the destination scene 1.307 + * @param src Source scene - remains unmodified. 1.308 + */ 1.309 + static void CopyScene(aiScene** dest,const aiScene* source,bool allocate = true); 1.310 + 1.311 + 1.312 + // ------------------------------------------------------------------- 1.313 + /** Get a flat copy of a scene 1.314 + * 1.315 + * Only the first hierarchy layer is copied. All pointer members of 1.316 + * aiScene are shared by source and destination scene. If the 1.317 + * pointer doesn't point to NULL when the function is called, the 1.318 + * existing scene is cleared and refilled. 1.319 + * @param dest Receives a pointer to the destination scene 1.320 + * @param src Source scene - remains unmodified. 1.321 + */ 1.322 + static void CopySceneFlat(aiScene** dest,const aiScene* source); 1.323 + 1.324 + 1.325 + // ------------------------------------------------------------------- 1.326 + /** Get a deep copy of a mesh 1.327 + * 1.328 + * @param dest Receives a pointer to the destination mesh 1.329 + * @param src Source mesh - remains unmodified. 1.330 + */ 1.331 + static void Copy (aiMesh** dest, const aiMesh* src); 1.332 + 1.333 + // similar to Copy(): 1.334 + static void Copy (aiMaterial** dest, const aiMaterial* src); 1.335 + static void Copy (aiTexture** dest, const aiTexture* src); 1.336 + static void Copy (aiAnimation** dest, const aiAnimation* src); 1.337 + static void Copy (aiCamera** dest, const aiCamera* src); 1.338 + static void Copy (aiBone** dest, const aiBone* src); 1.339 + static void Copy (aiLight** dest, const aiLight* src); 1.340 + static void Copy (aiNodeAnim** dest, const aiNodeAnim* src); 1.341 + 1.342 + // recursive, of course 1.343 + static void Copy (aiNode** dest, const aiNode* src); 1.344 + 1.345 + 1.346 +private: 1.347 + 1.348 + // ------------------------------------------------------------------- 1.349 + // Same as AddNodePrefixes, but with an additional check 1.350 + static void AddNodePrefixesChecked(aiNode* node, const char* prefix, 1.351 + unsigned int len, 1.352 + std::vector<SceneHelper>& input, 1.353 + unsigned int cur); 1.354 + 1.355 + // ------------------------------------------------------------------- 1.356 + // Add node identifiers to a hashing set 1.357 + static void AddNodeHashes(aiNode* node, std::set<unsigned int>& hashes); 1.358 + 1.359 + 1.360 + // ------------------------------------------------------------------- 1.361 + // Search for duplicate names 1.362 + static bool FindNameMatch(const aiString& name, 1.363 + std::vector<SceneHelper>& input, unsigned int cur); 1.364 +}; 1.365 + 1.366 +} 1.367 + 1.368 +#endif // !! AI_SCENE_COMBINER_H_INC