summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/assimp/code/SceneCombiner.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdparty/assimp/code/SceneCombiner.cpp')
-rw-r--r--src/3rdparty/assimp/code/SceneCombiner.cpp245
1 files changed, 135 insertions, 110 deletions
diff --git a/src/3rdparty/assimp/code/SceneCombiner.cpp b/src/3rdparty/assimp/code/SceneCombiner.cpp
index b39adbf78..4b77bb2db 100644
--- a/src/3rdparty/assimp/code/SceneCombiner.cpp
+++ b/src/3rdparty/assimp/code/SceneCombiner.cpp
@@ -2,7 +2,8 @@
Open Asset Import Library (assimp)
----------------------------------------------------------------------
-Copyright (c) 2006-2016, assimp team
+Copyright (c) 2006-2017, assimp team
+
All rights reserved.
Redistribution and use of this software in source and binary forms,
@@ -43,28 +44,30 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// possible as new fields are added to assimp structures.
// ----------------------------------------------------------------------------
-/** @file Implements Assimp::SceneCombiner. This is a smart utility
- * class that combines multiple scenes, meshes, ... into one. Currently
- * these utilities are used by the IRR and LWS loaders and the
- * OptimizeGraph step.
- */
+/**
+ * @file Implements Assimp::SceneCombiner. This is a smart utility
+ * class that combines multiple scenes, meshes, ... into one. Currently
+ * these utilities are used by the IRR and LWS loaders and the
+ * OptimizeGraph step.
+ */
// ----------------------------------------------------------------------------
-#include "SceneCombiner.h"
+#include <assimp/SceneCombiner.h>
#include "StringUtils.h"
#include "fast_atof.h"
#include "Hash.h"
#include "time.h"
#include <assimp/DefaultLogger.hpp>
#include <assimp/scene.h>
+#include <assimp/mesh.h>
#include <stdio.h>
#include "ScenePrivate.h"
-namespace Assimp {
+namespace Assimp {
// ------------------------------------------------------------------------------------------------
// Add a prefix to a string
-inline void PrefixString(aiString& string,const char* prefix, unsigned int len)
-{
+inline
+void PrefixString(aiString& string,const char* prefix, unsigned int len) {
// If the string is already prefixed, we won't prefix it a second time
if (string.length >= 1 && string.data[0] == '$')
return;
@@ -85,12 +88,11 @@ inline void PrefixString(aiString& string,const char* prefix, unsigned int len)
// ------------------------------------------------------------------------------------------------
// Add node identifiers to a hashing set
-void SceneCombiner::AddNodeHashes(aiNode* node, std::set<unsigned int>& hashes)
-{
+void SceneCombiner::AddNodeHashes(aiNode* node, std::set<unsigned int>& hashes) {
// Add node name to hashing set if it is non-empty - empty nodes are allowed
// and they can't have any anims assigned so its absolutely safe to duplicate them.
if (node->mName.length) {
- hashes.insert( SuperFastHash(node->mName.data,node->mName.length) );
+ hashes.insert( SuperFastHash(node->mName.data, static_cast<uint32_t>(node->mName.length)) );
}
// Process all children recursively
@@ -100,25 +102,23 @@ void SceneCombiner::AddNodeHashes(aiNode* node, std::set<unsigned int>& hashes)
// ------------------------------------------------------------------------------------------------
// Add a name prefix to all nodes in a hierarchy
-void SceneCombiner::AddNodePrefixes(aiNode* node, const char* prefix, unsigned int len)
-{
+void SceneCombiner::AddNodePrefixes(aiNode* node, const char* prefix, unsigned int len) {
ai_assert(NULL != prefix);
PrefixString(node->mName,prefix,len);
// Process all children recursively
- for (unsigned int i = 0; i < node->mNumChildren;++i)
- AddNodePrefixes(node->mChildren[i],prefix,len);
+ for ( unsigned int i = 0; i < node->mNumChildren; ++i ) {
+ AddNodePrefixes( node->mChildren[ i ], prefix, len );
+ }
}
// ------------------------------------------------------------------------------------------------
// Search for matching names
-bool SceneCombiner::FindNameMatch(const aiString& name, std::vector<SceneHelper>& input, unsigned int cur)
-{
- const unsigned int hash = SuperFastHash(name.data, name.length);
+bool SceneCombiner::FindNameMatch(const aiString& name, std::vector<SceneHelper>& input, unsigned int cur) {
+ const unsigned int hash = SuperFastHash(name.data, static_cast<uint32_t>(name.length));
// Check whether we find a positive match in one of the given sets
for (unsigned int i = 0; i < input.size(); ++i) {
-
if (cur != i && input[i].hashes.find(hash) != input[i].hashes.end()) {
return true;
}
@@ -129,14 +129,12 @@ bool SceneCombiner::FindNameMatch(const aiString& name, std::vector<SceneHelper>
// ------------------------------------------------------------------------------------------------
// Add a name prefix to all nodes in a hierarchy if a hash match is found
void SceneCombiner::AddNodePrefixesChecked(aiNode* node, const char* prefix, unsigned int len,
- std::vector<SceneHelper>& input, unsigned int cur)
-{
+ std::vector<SceneHelper>& input, unsigned int cur) {
ai_assert(NULL != prefix);
- const unsigned int hash = SuperFastHash(node->mName.data,node->mName.length);
+ const unsigned int hash = SuperFastHash(node->mName.data, static_cast<uint32_t>(node->mName.length));
// Check whether we find a positive match in one of the given sets
for (unsigned int i = 0; i < input.size(); ++i) {
-
if (cur != i && input[i].hashes.find(hash) != input[i].hashes.end()) {
PrefixString(node->mName,prefix,len);
break;
@@ -150,27 +148,25 @@ void SceneCombiner::AddNodePrefixesChecked(aiNode* node, const char* prefix, uns
// ------------------------------------------------------------------------------------------------
// Add an offset to all mesh indices in a node graph
-void SceneCombiner::OffsetNodeMeshIndices (aiNode* node, unsigned int offset)
-{
+void SceneCombiner::OffsetNodeMeshIndices (aiNode* node, unsigned int offset) {
for (unsigned int i = 0; i < node->mNumMeshes;++i)
node->mMeshes[i] += offset;
- for (unsigned int i = 0; i < node->mNumChildren;++i)
- OffsetNodeMeshIndices(node->mChildren[i],offset);
+ for ( unsigned int i = 0; i < node->mNumChildren; ++i ) {
+ OffsetNodeMeshIndices( node->mChildren[ i ], offset );
+ }
}
// ------------------------------------------------------------------------------------------------
// Merges two scenes. Currently only used by the LWS loader.
-void SceneCombiner::MergeScenes(aiScene** _dest,std::vector<aiScene*>& src,
- unsigned int flags)
-{
- ai_assert(NULL != _dest);
+void SceneCombiner::MergeScenes(aiScene** _dest,std::vector<aiScene*>& src, unsigned int flags) {
+ if ( nullptr == _dest ) {
+ return;
+ }
// if _dest points to NULL allocate a new scene. Otherwise clear the old and reuse it
- if (src.empty())
- {
- if (*_dest)
- {
+ if (src.empty()) {
+ if (*_dest) {
(*_dest)->~aiScene();
SceneCombiner::CopySceneFlat(_dest,src[0]);
}
@@ -195,11 +191,11 @@ void SceneCombiner::MergeScenes(aiScene** _dest,std::vector<aiScene*>& src,
}
// ------------------------------------------------------------------------------------------------
-void SceneCombiner::AttachToGraph (aiNode* attach, std::vector<NodeAttachmentInfo>& srcList)
-{
+void SceneCombiner::AttachToGraph (aiNode* attach, std::vector<NodeAttachmentInfo>& srcList) {
unsigned int cnt;
- for (cnt = 0; cnt < attach->mNumChildren;++cnt)
- AttachToGraph(attach->mChildren[cnt],srcList);
+ for ( cnt = 0; cnt < attach->mNumChildren; ++cnt ) {
+ AttachToGraph( attach->mChildren[ cnt ], srcList );
+ }
cnt = 0;
for (std::vector<NodeAttachmentInfo>::iterator it = srcList.begin();
@@ -235,19 +231,16 @@ void SceneCombiner::AttachToGraph (aiNode* attach, std::vector<NodeAttachmentInf
}
// ------------------------------------------------------------------------------------------------
-void SceneCombiner::AttachToGraph ( aiScene* master,
- std::vector<NodeAttachmentInfo>& src)
-{
+void SceneCombiner::AttachToGraph ( aiScene* master, std::vector<NodeAttachmentInfo>& src) {
ai_assert(NULL != master);
AttachToGraph(master->mRootNode,src);
}
// ------------------------------------------------------------------------------------------------
-void SceneCombiner::MergeScenes(aiScene** _dest, aiScene* master,
- std::vector<AttachmentInfo>& srcList,
- unsigned int flags)
-{
- ai_assert(NULL != _dest);
+void SceneCombiner::MergeScenes(aiScene** _dest, aiScene* master, std::vector<AttachmentInfo>& srcList, unsigned int flags) {
+ if ( nullptr == _dest ) {
+ return;
+ }
// if _dest points to NULL allocate a new scene. Otherwise clear the old and reuse it
if (srcList.empty()) {
@@ -323,7 +316,7 @@ void SceneCombiner::MergeScenes(aiScene** _dest, aiScene* master,
for (unsigned int a = 0; a < src[i]->mNumAnimations;++a) {
aiAnimation* anim = src[i]->mAnimations[a];
- src[i].hashes.insert(SuperFastHash(anim->mName.data,anim->mName.length));
+ src[i].hashes.insert(SuperFastHash(anim->mName.data,static_cast<uint32_t>(anim->mName.length)));
}
}
}
@@ -485,7 +478,7 @@ void SceneCombiner::MergeScenes(aiScene** _dest, aiScene* master,
aiAnimation** ppAnims = dest->mAnimations = (dest->mNumAnimations
? new aiAnimation*[dest->mNumAnimations] : NULL);
- for ( int n = src.size()-1; n >= 0 ;--n ) /* !!! important !!! */
+ for ( int n = static_cast<int>(src.size()-1); n >= 0 ;--n ) /* !!! important !!! */
{
SceneHelper* cur = &src[n];
aiNode* node;
@@ -704,7 +697,9 @@ void SceneCombiner::BuildUniqueBoneList(std::list<BoneWithHash>& asBones,
void SceneCombiner::MergeBones(aiMesh* out,std::vector<aiMesh*>::const_iterator it,
std::vector<aiMesh*>::const_iterator end)
{
- ai_assert(NULL != out && !out->mNumBones);
+ if ( nullptr == out || out->mNumBones == 0 ) {
+ return;
+ }
// find we need to build an unique list of all bones.
// we work with hashes to make the comparisons MUCH faster,
@@ -740,7 +735,7 @@ void SceneCombiner::MergeBones(aiMesh* out,std::vector<aiMesh*>::const_iterator
aiVertexWeight* avw = pc->mWeights = new aiVertexWeight[pc->mNumWeights];
// And copy the final weights - adjust the vertex IDs by the
- // face index offset of the coresponding mesh.
+ // face index offset of the corresponding mesh.
for (std::vector< BoneSrcIndex >::const_iterator wmit = (*it).pSrcBones.begin(); wmit != wend; ++wmit) {
aiBone* pip = (*wmit).first;
for (unsigned int mp = 0; mp < pip->mNumWeights;++mp,++avw) {
@@ -754,11 +749,13 @@ void SceneCombiner::MergeBones(aiMesh* out,std::vector<aiMesh*>::const_iterator
// ------------------------------------------------------------------------------------------------
// Merge a list of meshes
-void SceneCombiner::MergeMeshes(aiMesh** _out,unsigned int /*flags*/,
+void SceneCombiner::MergeMeshes(aiMesh** _out, unsigned int /*flags*/,
std::vector<aiMesh*>::const_iterator begin,
std::vector<aiMesh*>::const_iterator end)
{
- ai_assert(NULL != _out);
+ if ( nullptr == _out ) {
+ return;
+ }
if (begin == end) {
*_out = NULL; // no meshes ...
@@ -769,8 +766,14 @@ void SceneCombiner::MergeMeshes(aiMesh** _out,unsigned int /*flags*/,
aiMesh* out = *_out = new aiMesh();
out->mMaterialIndex = (*begin)->mMaterialIndex;
+ std::string name;
// Find out how much output storage we'll need
- for (std::vector<aiMesh*>::const_iterator it = begin; it != end;++it) {
+ for (std::vector<aiMesh*>::const_iterator it = begin; it != end; ++it) {
+ const char *meshName( (*it)->mName.C_Str() );
+ name += std::string( meshName );
+ if ( it != end - 1 ) {
+ name += ".";
+ }
out->mNumVertices += (*it)->mNumVertices;
out->mNumFaces += (*it)->mNumFaces;
out->mNumBones += (*it)->mNumBones;
@@ -778,6 +781,7 @@ void SceneCombiner::MergeMeshes(aiMesh** _out,unsigned int /*flags*/,
// combine primitive type flags
out->mPrimitiveTypes |= (*it)->mPrimitiveTypes;
}
+ out->mName.Set( name.c_str() );
if (out->mNumVertices) {
aiVector3D* pv2;
@@ -786,7 +790,7 @@ void SceneCombiner::MergeMeshes(aiMesh** _out,unsigned int /*flags*/,
if ((**begin).HasPositions()) {
pv2 = out->mVertices = new aiVector3D[out->mNumVertices];
- for (std::vector<aiMesh*>::const_iterator it = begin; it != end;++it) {
+ for (std::vector<aiMesh*>::const_iterator it = begin; it != end; ++it) {
if ((*it)->mVertices) {
::memcpy(pv2,(*it)->mVertices,(*it)->mNumVertices*sizeof(aiVector3D));
}
@@ -806,7 +810,7 @@ void SceneCombiner::MergeMeshes(aiMesh** _out,unsigned int /*flags*/,
pv2 += (*it)->mNumVertices;
}
}
- // copy tangents and bitangents
+ // copy tangents and bi-tangents
if ((**begin).HasTangentsAndBitangents()) {
pv2 = out->mTangents = new aiVector3D[out->mNumVertices];
@@ -892,7 +896,9 @@ void SceneCombiner::MergeMaterials(aiMaterial** dest,
std::vector<aiMaterial*>::const_iterator begin,
std::vector<aiMaterial*>::const_iterator end)
{
- ai_assert(NULL != dest);
+ if ( nullptr == dest ) {
+ return;
+ }
if (begin == end) {
*dest = NULL; // no materials ...
@@ -942,24 +948,25 @@ void SceneCombiner::MergeMaterials(aiMaterial** dest,
// ------------------------------------------------------------------------------------------------
template <typename Type>
-inline void CopyPtrArray (Type**& dest, const Type* const * src, unsigned int num)
-{
- if (!num)
- {
+inline
+void CopyPtrArray (Type**& dest, const Type* const * src, ai_uint num) {
+ if (!num) {
dest = NULL;
return;
}
dest = new Type*[num];
- for (unsigned int i = 0; i < num;++i) {
+ for (ai_uint i = 0; i < num;++i) {
SceneCombiner::Copy(&dest[i],src[i]);
}
}
// ------------------------------------------------------------------------------------------------
template <typename Type>
-inline void GetArrayCopy (Type*& dest, unsigned int num )
-{
- if (!dest)return;
+inline
+void GetArrayCopy(Type*& dest, ai_uint num ) {
+ if ( !dest ) {
+ return;
+ }
Type* old = dest;
dest = new Type[num];
@@ -967,22 +974,27 @@ inline void GetArrayCopy (Type*& dest, unsigned int num )
}
// ------------------------------------------------------------------------------------------------
-void SceneCombiner::CopySceneFlat(aiScene** _dest,const aiScene* src)
-{
+void SceneCombiner::CopySceneFlat(aiScene** _dest,const aiScene* src) {
+ if ( nullptr == _dest || nullptr == src ) {
+ return;
+ }
+
// reuse the old scene or allocate a new?
if (*_dest) {
(*_dest)->~aiScene();
new (*_dest) aiScene();
+ } else {
+ *_dest = new aiScene();
}
- else *_dest = new aiScene();
::memcpy(*_dest,src,sizeof(aiScene));
}
// ------------------------------------------------------------------------------------------------
-void SceneCombiner::CopyScene(aiScene** _dest,const aiScene* src,bool allocate)
-{
- ai_assert(NULL != _dest && NULL != src);
+void SceneCombiner::CopyScene(aiScene** _dest,const aiScene* src,bool allocate) {
+ if ( nullptr == _dest || nullptr == src ) {
+ return;
+ }
if (allocate) {
*_dest = new aiScene();
@@ -1033,9 +1045,10 @@ void SceneCombiner::CopyScene(aiScene** _dest,const aiScene* src,bool allocate)
}
// ------------------------------------------------------------------------------------------------
-void SceneCombiner::Copy (aiMesh** _dest, const aiMesh* src)
-{
- ai_assert(NULL != _dest && NULL != src);
+void SceneCombiner::Copy( aiMesh** _dest, const aiMesh* src ) {
+ if ( nullptr == _dest || nullptr == src ) {
+ return;
+ }
aiMesh* dest = *_dest = new aiMesh();
@@ -1061,17 +1074,17 @@ void SceneCombiner::Copy (aiMesh** _dest, const aiMesh* src)
// make a deep copy of all faces
GetArrayCopy(dest->mFaces,dest->mNumFaces);
- for (unsigned int i = 0; i < dest->mNumFaces;++i)
- {
+ for (unsigned int i = 0; i < dest->mNumFaces;++i) {
aiFace& f = dest->mFaces[i];
GetArrayCopy(f.mIndices,f.mNumIndices);
}
}
// ------------------------------------------------------------------------------------------------
-void SceneCombiner::Copy (aiMaterial** _dest, const aiMaterial* src)
-{
- ai_assert(NULL != _dest && NULL != src);
+void SceneCombiner::Copy (aiMaterial** _dest, const aiMaterial* src) {
+ if ( nullptr == _dest || nullptr == src ) {
+ return;
+ }
aiMaterial* dest = (aiMaterial*) ( *_dest = new aiMaterial() );
@@ -1099,9 +1112,10 @@ void SceneCombiner::Copy (aiMaterial** _dest, const aiMaterial* src)
}
// ------------------------------------------------------------------------------------------------
-void SceneCombiner::Copy (aiTexture** _dest, const aiTexture* src)
-{
- ai_assert(NULL != _dest && NULL != src);
+void SceneCombiner::Copy(aiTexture** _dest, const aiTexture* src) {
+ if ( nullptr == _dest || nullptr == src ) {
+ return;
+ }
aiTexture* dest = *_dest = new aiTexture();
@@ -1128,11 +1142,11 @@ void SceneCombiner::Copy (aiTexture** _dest, const aiTexture* src)
}
// ------------------------------------------------------------------------------------------------
-void SceneCombiner::Copy( aiAnimation** _dest, const aiAnimation* src )
-{
- ai_assert( NULL != _dest );
- ai_assert( NULL != src );
-
+void SceneCombiner::Copy( aiAnimation** _dest, const aiAnimation* src ) {
+ if ( nullptr == _dest || nullptr == src ) {
+ return;
+ }
+
aiAnimation* dest = *_dest = new aiAnimation();
// get a flat copy
@@ -1143,9 +1157,10 @@ void SceneCombiner::Copy( aiAnimation** _dest, const aiAnimation* src )
}
// ------------------------------------------------------------------------------------------------
-void SceneCombiner::Copy (aiNodeAnim** _dest, const aiNodeAnim* src)
-{
- ai_assert(NULL != _dest && NULL != src);
+void SceneCombiner::Copy(aiNodeAnim** _dest, const aiNodeAnim* src) {
+ if ( nullptr == _dest || nullptr == src ) {
+ return;
+ }
aiNodeAnim* dest = *_dest = new aiNodeAnim();
@@ -1159,9 +1174,10 @@ void SceneCombiner::Copy (aiNodeAnim** _dest, const aiNodeAnim* src)
}
// ------------------------------------------------------------------------------------------------
-void SceneCombiner::Copy (aiCamera** _dest,const aiCamera* src)
-{
- ai_assert(NULL != _dest && NULL != src);
+void SceneCombiner::Copy( aiCamera** _dest,const aiCamera* src) {
+ if ( nullptr == _dest || nullptr == src ) {
+ return;
+ }
aiCamera* dest = *_dest = new aiCamera();
@@ -1170,9 +1186,10 @@ void SceneCombiner::Copy (aiCamera** _dest,const aiCamera* src)
}
// ------------------------------------------------------------------------------------------------
-void SceneCombiner::Copy (aiLight** _dest, const aiLight* src)
-{
- ai_assert(NULL != _dest && NULL != src);
+void SceneCombiner::Copy(aiLight** _dest, const aiLight* src) {
+ if ( nullptr == _dest || nullptr == src ) {
+ return;
+ }
aiLight* dest = *_dest = new aiLight();
@@ -1181,9 +1198,10 @@ void SceneCombiner::Copy (aiLight** _dest, const aiLight* src)
}
// ------------------------------------------------------------------------------------------------
-void SceneCombiner::Copy (aiBone** _dest, const aiBone* src)
-{
- ai_assert(NULL != _dest && NULL != src);
+void SceneCombiner::Copy(aiBone** _dest, const aiBone* src) {
+ if ( nullptr == _dest || nullptr == src ) {
+ return;
+ }
aiBone* dest = *_dest = new aiBone();
@@ -1219,13 +1237,16 @@ void SceneCombiner::Copy (aiNode** _dest, const aiNode* src)
}
// ------------------------------------------------------------------------------------------------
-void SceneCombiner::Copy (aiMetadata** _dest, const aiMetadata* src)
-{
- ai_assert(NULL != _dest && NULL != src);
+void SceneCombiner::Copy(aiMetadata** _dest, const aiMetadata* src) {
+ if ( nullptr == _dest || nullptr == src ) {
+ return;
+ }
- aiMetadata* dest = *_dest = new aiMetadata();
- dest->mNumProperties = src->mNumProperties;
- dest->mKeys = new aiString[src->mNumProperties];
+ if ( 0 == src->mNumProperties ) {
+ return;
+ }
+
+ aiMetadata* dest = *_dest = aiMetadata::Alloc( src->mNumProperties );
std::copy(src->mKeys, src->mKeys + src->mNumProperties, dest->mKeys);
dest->mValues = new aiMetadataEntry[src->mNumProperties];
@@ -1237,8 +1258,8 @@ void SceneCombiner::Copy (aiMetadata** _dest, const aiMetadata* src)
case AI_BOOL:
out.mData = new bool(*static_cast<bool*>(in.mData));
break;
- case AI_INT:
- out.mData = new int(*static_cast<int*>(in.mData));
+ case AI_INT32:
+ out.mData = new int32_t(*static_cast<int32_t*>(in.mData));
break;
case AI_UINT64:
out.mData = new uint64_t(*static_cast<uint64_t*>(in.mData));
@@ -1246,6 +1267,9 @@ void SceneCombiner::Copy (aiMetadata** _dest, const aiMetadata* src)
case AI_FLOAT:
out.mData = new float(*static_cast<float*>(in.mData));
break;
+ case AI_DOUBLE:
+ out.mData = new double(*static_cast<double*>(in.mData));
+ break;
case AI_AISTRING:
out.mData = new aiString(*static_cast<aiString*>(in.mData));
break;
@@ -1258,4 +1282,5 @@ void SceneCombiner::Copy (aiMetadata** _dest, const aiMetadata* src)
}
}
-}
+} // Namespace Assimp
+