Path Tracer
SceneCombiner.h
1 /*
2 Open Asset Import Library (assimp)
3 ----------------------------------------------------------------------
4 
5 Copyright (c) 2006-2020, assimp team
6 
7 
8 All rights reserved.
9 
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:
13 
14 * Redistributions of source code must retain the above
15  copyright notice, this list of conditions and the
16  following disclaimer.
17 
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.
22 
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.
27 
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.
39 
40 ----------------------------------------------------------------------
41 */
42 
46 #pragma once
47 #ifndef AI_SCENE_COMBINER_H_INC
48 #define AI_SCENE_COMBINER_H_INC
49 
50 #ifdef __GNUC__
51 #pragma GCC system_header
52 #endif
53 
54 #include <assimp/Defines.h>
55 #include <assimp/ai_assert.h>
56 #include <assimp/types.h>
57 
58 #include <stddef.h>
59 #include <stdint.h>
60 #include <list>
61 #include <set>
62 #include <vector>
63 
64 struct aiScene;
65 struct aiNode;
66 struct aiMaterial;
67 struct aiTexture;
68 struct aiCamera;
69 struct aiLight;
70 struct aiMetadata;
71 struct aiBone;
72 struct aiMesh;
73 struct aiAnimMesh;
74 struct aiAnimation;
75 struct aiNodeAnim;
76 struct aiMeshMorphAnim;
77 
78 namespace Assimp {
79 
80 // ---------------------------------------------------------------------------
86  AttachmentInfo() :
87  scene(nullptr),
88  attachToNode(nullptr) {}
89 
90  AttachmentInfo(aiScene *_scene, aiNode *_attachToNode) :
91  scene(_scene), attachToNode(_attachToNode) {}
92 
93  aiScene *scene;
94  aiNode *attachToNode;
95 };
96 
97 // ---------------------------------------------------------------------------
100  node(nullptr),
101  attachToNode(nullptr),
102  resolved(false),
103  src_idx(SIZE_MAX) {}
104 
105  NodeAttachmentInfo(aiNode *_scene, aiNode *_attachToNode, size_t idx) :
106  node(_scene), attachToNode(_attachToNode), resolved(false), src_idx(idx) {}
107 
108  aiNode *node;
109  aiNode *attachToNode;
110  bool resolved;
111  size_t src_idx;
112 };
113 
114 // ---------------------------------------------------------------------------
118 #define AI_INT_MERGE_SCENE_GEN_UNIQUE_NAMES 0x1
119 
124 #define AI_INT_MERGE_SCENE_GEN_UNIQUE_MATNAMES 0x2
125 
129 #define AI_INT_MERGE_SCENE_DUPLICATES_DEEP_CPY 0x4
130 
135 #define AI_INT_MERGE_SCENE_RESOLVE_CROSS_ATTACHMENTS 0x8
136 
142 #define AI_INT_MERGE_SCENE_GEN_UNIQUE_NAMES_IF_NECESSARY 0x10
143 
144 typedef std::pair<aiBone *, unsigned int> BoneSrcIndex;
145 
146 // ---------------------------------------------------------------------------
149 struct BoneWithHash : public std::pair<uint32_t, aiString *> {
150  std::vector<BoneSrcIndex> pSrcBones;
151 };
152 
153 // ---------------------------------------------------------------------------
156 struct SceneHelper {
157  SceneHelper() :
158  scene(nullptr),
159  idlen(0) {
160  id[0] = 0;
161  }
162 
163  explicit SceneHelper(aiScene *_scene) :
164  scene(_scene), idlen(0) {
165  id[0] = 0;
166  }
167 
168  AI_FORCE_INLINE aiScene *operator->() const {
169  return scene;
170  }
171 
172  // scene we're working on
173  aiScene *scene;
174 
175  // prefix to be added to all identifiers in the scene ...
176  char id[32];
177 
178  // and its strlen()
179  unsigned int idlen;
180 
181  // hash table to quickly check whether a name is contained in the scene
182  std::set<unsigned int> hashes;
183 };
184 
185 // ---------------------------------------------------------------------------
193 class ASSIMP_API SceneCombiner {
194  // class cannot be instanced
195  SceneCombiner() {
196  // empty
197  }
198 
199  ~SceneCombiner() {
200  // empty
201  }
202 
203 public:
204  // -------------------------------------------------------------------
214  static void MergeScenes(aiScene **dest, std::vector<aiScene *> &src,
215  unsigned int flags = 0);
216 
217  // -------------------------------------------------------------------
231  static void MergeScenes(aiScene **dest, aiScene *master,
232  std::vector<AttachmentInfo> &src,
233  unsigned int flags = 0);
234 
235  // -------------------------------------------------------------------
249  static void MergeMeshes(aiMesh **dest, unsigned int flags,
250  std::vector<aiMesh *>::const_iterator begin,
251  std::vector<aiMesh *>::const_iterator end);
252 
253  // -------------------------------------------------------------------
261  static void MergeBones(aiMesh *out, std::vector<aiMesh *>::const_iterator it,
262  std::vector<aiMesh *>::const_iterator end);
263 
264  // -------------------------------------------------------------------
275  static void MergeMaterials(aiMaterial **dest,
276  std::vector<aiMaterial *>::const_iterator begin,
277  std::vector<aiMaterial *>::const_iterator end);
278 
279  // -------------------------------------------------------------------
286  static void BuildUniqueBoneList(std::list<BoneWithHash> &asBones,
287  std::vector<aiMesh *>::const_iterator it,
288  std::vector<aiMesh *>::const_iterator end);
289 
290  // -------------------------------------------------------------------
297  static void AddNodePrefixes(aiNode *node, const char *prefix,
298  unsigned int len);
299 
300  // -------------------------------------------------------------------
306  static void OffsetNodeMeshIndices(aiNode *node, unsigned int offset);
307 
308  // -------------------------------------------------------------------
320  static void AttachToGraph(aiScene *master,
321  std::vector<NodeAttachmentInfo> &srcList);
322 
323  static void AttachToGraph(aiNode *attach,
324  std::vector<NodeAttachmentInfo> &srcList);
325 
326  // -------------------------------------------------------------------
332  static void CopyScene(aiScene **dest, const aiScene *source, bool allocate = true);
333 
334  // -------------------------------------------------------------------
344  static void CopySceneFlat(aiScene **dest, const aiScene *source);
345 
346  // -------------------------------------------------------------------
352  static void Copy(aiMesh **dest, const aiMesh *src);
353 
354  // similar to Copy():
355  static void Copy(aiAnimMesh **dest, const aiAnimMesh *src);
356  static void Copy(aiMaterial **dest, const aiMaterial *src);
357  static void Copy(aiTexture **dest, const aiTexture *src);
358  static void Copy(aiAnimation **dest, const aiAnimation *src);
359  static void Copy(aiCamera **dest, const aiCamera *src);
360  static void Copy(aiBone **dest, const aiBone *src);
361  static void Copy(aiLight **dest, const aiLight *src);
362  static void Copy(aiNodeAnim **dest, const aiNodeAnim *src);
363  static void Copy(aiMeshMorphAnim **dest, const aiMeshMorphAnim *src);
364  static void Copy(aiMetadata **dest, const aiMetadata *src);
365 
366  // recursive, of course
367  static void Copy(aiNode **dest, const aiNode *src);
368 
369 private:
370  // -------------------------------------------------------------------
371  // Same as AddNodePrefixes, but with an additional check
372  static void AddNodePrefixesChecked(aiNode *node, const char *prefix,
373  unsigned int len,
374  std::vector<SceneHelper> &input,
375  unsigned int cur);
376 
377  // -------------------------------------------------------------------
378  // Add node identifiers to a hashing set
379  static void AddNodeHashes(aiNode *node, std::set<unsigned int> &hashes);
380 
381  // -------------------------------------------------------------------
382  // Search for duplicate names
383  static bool FindNameMatch(const aiString &name,
384  std::vector<SceneHelper> &input, unsigned int cur);
385 };
386 
387 } // namespace Assimp
388 
389 #endif // !! AI_SCENE_COMBINER_H_INC
Assimp::SceneCombiner::MergeMaterials
static void MergeMaterials(aiMaterial **dest, std::vector< aiMaterial * >::const_iterator begin, std::vector< aiMaterial * >::const_iterator end)
Assimp::NodeAttachmentInfo
Definition: SceneCombiner.h:98
Assimp::SceneCombiner::MergeScenes
static void MergeScenes(aiScene **dest, std::vector< aiScene * > &src, unsigned int flags=0)
aiTexture
Definition: texture.h:135
types.h
aiNode
Definition: scene.h:85
aiLight
Definition: light.h:119
Assimp::SceneCombiner::Copy
static void Copy(aiMesh **dest, const aiMesh *src)
aiCamera
Definition: camera.h:104
Assimp::AttachmentInfo
Helper data structure for SceneCombiner.
Definition: SceneCombiner.h:85
Assimp::SceneHelper
Utility for SceneCombiner.
Definition: SceneCombiner.h:156
Assimp::SceneCombiner::MergeScenes
static void MergeScenes(aiScene **dest, aiScene *master, std::vector< AttachmentInfo > &src, unsigned int flags=0)
Assimp::SceneCombiner::MergeBones
static void MergeBones(aiMesh *out, std::vector< aiMesh * >::const_iterator it, std::vector< aiMesh * >::const_iterator end)
Assimp::SceneCombiner::OffsetNodeMeshIndices
static void OffsetNodeMeshIndices(aiNode *node, unsigned int offset)
Assimp::BoneWithHash
Helper data structure for SceneCombiner::MergeBones.
Definition: SceneCombiner.h:149
Assimp::SceneCombiner::AddNodePrefixes
static void AddNodePrefixes(aiNode *node, const char *prefix, unsigned int len)
aiMaterial
Data structure for a material.
Definition: material.h:672
Assimp::SceneCombiner::CopySceneFlat
static void CopySceneFlat(aiScene **dest, const aiScene *source)
aiMeshMorphAnim
Definition: anim.h:369
aiString
Definition: types.h:266
aiNodeAnim
Definition: anim.h:264
Assimp::SceneCombiner::MergeMeshes
static void MergeMeshes(aiMesh **dest, unsigned int flags, std::vector< aiMesh * >::const_iterator begin, std::vector< aiMesh * >::const_iterator end)
aiMetadata
Definition: metadata.h:146
Assimp::SceneCombiner::BuildUniqueBoneList
static void BuildUniqueBoneList(std::list< BoneWithHash > &asBones, std::vector< aiMesh * >::const_iterator it, std::vector< aiMesh * >::const_iterator end)
aiBone
A single bone of a mesh.
Definition: mesh.h:264
aiAnimation
Definition: anim.h:398
Assimp::SceneCombiner
Static helper class providing various utilities to merge two scenes. It is intended as internal utili...
Definition: SceneCombiner.h:193
aiAnimMesh
An AnimMesh is an attachment to an aiMesh stores per-vertex animations for a particular frame.
Definition: mesh.h:424
Assimp::SceneCombiner::AttachToGraph
static void AttachToGraph(aiScene *master, std::vector< NodeAttachmentInfo > &srcList)
Assimp
Definition: ai_assert.h:50
Assimp::SceneCombiner::CopyScene
static void CopyScene(aiScene **dest, const aiScene *source, bool allocate=true)
aiScene
Definition: scene.h:247
aiMesh
enum aiMorphingMethod
Definition: mesh.h:575