GraphicsAPI_2020C
SceneCombiner.h
1 /*
2 Open Asset Import Library (assimp)
3 ----------------------------------------------------------------------
4 
5 Copyright (c) 2006-2017, assimp team
6 
7 All rights reserved.
8 
9 Redistribution and use of this software in source and binary forms,
10 with or without modification, are permitted provided that the
11 following conditions are met:
12 
13 * Redistributions of source code must retain the above
14  copyright notice, this list of conditions and the
15  following disclaimer.
16 
17 * Redistributions in binary form must reproduce the above
18  copyright notice, this list of conditions and the
19  following disclaimer in the documentation and/or other
20  materials provided with the distribution.
21 
22 * Neither the name of the assimp team, nor the names of its
23  contributors may be used to endorse or promote products
24  derived from this software without specific prior
25  written permission of the assimp team.
26 
27 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 
39 ----------------------------------------------------------------------
40 */
41 
45 #ifndef AI_SCENE_COMBINER_H_INC
46 #define AI_SCENE_COMBINER_H_INC
47 
48 #include <assimp/ai_assert.h>
49 #include <assimp/types.h>
50 #include <assimp/Defines.h>
51 #include <stddef.h>
52 #include <set>
53 #include <list>
54 #include <stdint.h>
55 
56 #include <vector>
57 
58 struct aiScene;
59 struct aiNode;
60 struct aiMaterial;
61 struct aiTexture;
62 struct aiCamera;
63 struct aiLight;
64 struct aiMetadata;
65 struct aiBone;
66 struct aiMesh;
67 struct aiAnimation;
68 struct aiNodeAnim;
69 
70 namespace Assimp {
71 
72 // ---------------------------------------------------------------------------
78 {
80  : scene (NULL)
81  , attachToNode (NULL)
82  {}
83 
84  AttachmentInfo(aiScene* _scene, aiNode* _attachToNode)
85  : scene (_scene)
86  , attachToNode (_attachToNode)
87  {}
88 
89  aiScene* scene;
90  aiNode* attachToNode;
91 };
92 
93 // ---------------------------------------------------------------------------
95 {
97  : node (NULL)
98  , attachToNode (NULL)
99  , resolved (false)
100  , src_idx (SIZE_MAX)
101  {}
102 
103  NodeAttachmentInfo(aiNode* _scene, aiNode* _attachToNode,size_t idx)
104  : node (_scene)
105  , attachToNode (_attachToNode)
106  , resolved (false)
107  , src_idx (idx)
108  {}
109 
110  aiNode* node;
111  aiNode* attachToNode;
112  bool resolved;
113  size_t src_idx;
114 };
115 
116 // ---------------------------------------------------------------------------
120 #define AI_INT_MERGE_SCENE_GEN_UNIQUE_NAMES 0x1
121 
126 #define AI_INT_MERGE_SCENE_GEN_UNIQUE_MATNAMES 0x2
127 
131 #define AI_INT_MERGE_SCENE_DUPLICATES_DEEP_CPY 0x4
132 
137 #define AI_INT_MERGE_SCENE_RESOLVE_CROSS_ATTACHMENTS 0x8
138 
144 #define AI_INT_MERGE_SCENE_GEN_UNIQUE_NAMES_IF_NECESSARY 0x10
145 
146 typedef std::pair<aiBone*,unsigned int> BoneSrcIndex;
147 
148 // ---------------------------------------------------------------------------
151 struct BoneWithHash : public std::pair<uint32_t,aiString*> {
152  std::vector<BoneSrcIndex> pSrcBones;
153 };
154 
155 // ---------------------------------------------------------------------------
159 {
160  SceneHelper ()
161  : scene (NULL)
162  , idlen (0)
163  {
164  id[0] = 0;
165  }
166 
167  explicit SceneHelper (aiScene* _scene)
168  : scene (_scene)
169  , idlen (0)
170  {
171  id[0] = 0;
172  }
173 
174  AI_FORCE_INLINE aiScene* operator-> () const
175  {
176  return scene;
177  }
178 
179  // scene we're working on
180  aiScene* scene;
181 
182  // prefix to be added to all identifiers in the scene ...
183  char id [32];
184 
185  // and its strlen()
186  unsigned int idlen;
187 
188  // hash table to quickly check whether a name is contained in the scene
189  std::set<unsigned int> hashes;
190 };
191 
192 // ---------------------------------------------------------------------------
200 class ASSIMP_API SceneCombiner {
201  // class cannot be instanced
202  SceneCombiner() {
203  // empty
204  }
205 
206  ~SceneCombiner() {
207  // empty
208  }
209 
210 public:
211  // -------------------------------------------------------------------
221  static void MergeScenes(aiScene** dest,std::vector<aiScene*>& src,
222  unsigned int flags = 0);
223 
224  // -------------------------------------------------------------------
238  static void MergeScenes(aiScene** dest, aiScene* master,
239  std::vector<AttachmentInfo>& src,
240  unsigned int flags = 0);
241 
242  // -------------------------------------------------------------------
256  static void MergeMeshes(aiMesh** dest,unsigned int flags,
257  std::vector<aiMesh*>::const_iterator begin,
258  std::vector<aiMesh*>::const_iterator end);
259 
260  // -------------------------------------------------------------------
268  static void MergeBones(aiMesh* out,std::vector<aiMesh*>::const_iterator it,
269  std::vector<aiMesh*>::const_iterator end);
270 
271  // -------------------------------------------------------------------
282  static void MergeMaterials(aiMaterial** dest,
283  std::vector<aiMaterial*>::const_iterator begin,
284  std::vector<aiMaterial*>::const_iterator end);
285 
286  // -------------------------------------------------------------------
293  static void BuildUniqueBoneList(std::list<BoneWithHash>& asBones,
294  std::vector<aiMesh*>::const_iterator it,
295  std::vector<aiMesh*>::const_iterator end);
296 
297  // -------------------------------------------------------------------
304  static void AddNodePrefixes(aiNode* node, const char* prefix,
305  unsigned int len);
306 
307  // -------------------------------------------------------------------
313  static void OffsetNodeMeshIndices (aiNode* node, unsigned int offset);
314 
315  // -------------------------------------------------------------------
327  static void AttachToGraph ( aiScene* master,
328  std::vector<NodeAttachmentInfo>& srcList);
329 
330  static void AttachToGraph (aiNode* attach,
331  std::vector<NodeAttachmentInfo>& srcList);
332 
333 
334  // -------------------------------------------------------------------
340  static void CopyScene(aiScene** dest,const aiScene* source,bool allocate = true);
341 
342 
343  // -------------------------------------------------------------------
353  static void CopySceneFlat(aiScene** dest,const aiScene* source);
354 
355 
356  // -------------------------------------------------------------------
362  static void Copy (aiMesh** dest, const aiMesh* src);
363 
364  // similar to Copy():
365  static void Copy (aiMaterial** dest, const aiMaterial* src);
366  static void Copy (aiTexture** dest, const aiTexture* src);
367  static void Copy (aiAnimation** dest, const aiAnimation* src);
368  static void Copy (aiCamera** dest, const aiCamera* src);
369  static void Copy (aiBone** dest, const aiBone* src);
370  static void Copy (aiLight** dest, const aiLight* src);
371  static void Copy (aiNodeAnim** dest, const aiNodeAnim* src);
372  static void Copy (aiMetadata** dest, const aiMetadata* src);
373 
374  // recursive, of course
375  static void Copy (aiNode** dest, const aiNode* src);
376 
377 
378 private:
379 
380  // -------------------------------------------------------------------
381  // Same as AddNodePrefixes, but with an additional check
382  static void AddNodePrefixesChecked(aiNode* node, const char* prefix,
383  unsigned int len,
384  std::vector<SceneHelper>& input,
385  unsigned int cur);
386 
387  // -------------------------------------------------------------------
388  // Add node identifiers to a hashing set
389  static void AddNodeHashes(aiNode* node, std::set<unsigned int>& hashes);
390 
391 
392  // -------------------------------------------------------------------
393  // Search for duplicate names
394  static bool FindNameMatch(const aiString& name,
395  std::vector<SceneHelper>& input, unsigned int cur);
396 };
397 
398 }
399 
400 #endif // !! AI_SCENE_COMBINER_H_INC
An animation consists of key-frame data for a number of nodes.
Definition: anim.h:411
Static helper class providing various utilities to merge two scenes.
Definition: SceneCombiner.h:200
Basic data types and primitives, such as vectors or colors.
Assimp&#39;s CPP-API and all internal APIs.
Definition: DefaultIOStream.h:51
A node in the imported hierarchy.
Definition: scene.h:78
enum aiMorphingMethod
Definition: mesh.h:496
Helper structure to describe a light source.
Definition: light.h:113
Helper structure to describe a virtual camera.
Definition: camera.h:100
Definition: SceneCombiner.h:94
Helper data structure for SceneCombiner::MergeBones.
Definition: SceneCombiner.h:151
A single bone of a mesh.
Definition: mesh.h:234
Represents an UTF-8 string, zero byte terminated.
Definition: types.h:252
Helper structure to describe an embedded texture.
Definition: texture.h:133
The root structure of the imported data.
Definition: scene.h:240
Describes the animation of a single node.
Definition: anim.h:271
Helper data structure for SceneCombiner.
Definition: SceneCombiner.h:77
Utility for SceneCombiner.
Definition: SceneCombiner.h:158
Container for holding metadata.
Definition: metadata.h:114
Data structure for a material.
Definition: material.h:642