Merge pull request #875 from assimp/acgmay16

MSVC11 fixes
pull/879/head
Alexander Gessler 2016-05-05 16:04:10 +02:00
commit 174a598759
4 changed files with 50 additions and 55 deletions

View File

@ -77,7 +77,7 @@ static int ioprintf( IOStream * io, const char *format, ... ) {
::memset( sz, '\0', Size ); ::memset( sz, '\0', Size );
va_list va; va_list va;
va_start( va, format ); va_start( va, format );
int nSize = std::vsnprintf( sz, Size-1, format, va ); int nSize = vsnprintf( sz, Size-1, format, va );
ai_assert( nSize < Size ); ai_assert( nSize < Size );
va_end( va ); va_end( va );

View File

@ -596,11 +596,6 @@ namespace STEP {
LazyObject(DB& db, uint64_t id, uint64_t line, const char* type,const char* args); LazyObject(DB& db, uint64_t id, uint64_t line, const char* type,const char* args);
~LazyObject(); ~LazyObject();
LazyObject( LazyObject const& ) = delete;
LazyObject operator=( LazyObject const& ) = delete;
LazyObject( LazyObject && ) = delete;
LazyObject operator=( LazyObject && ) = delete;
public: public:
Object& operator * () { Object& operator * () {

View File

@ -90,7 +90,7 @@ void SplitByBoneCountProcess::Execute( aiScene* pScene)
// early out // early out
bool isNecessary = false; bool isNecessary = false;
for( size_t a = 0; a < pScene->mNumMeshes; ++a) for( unsigned int a = 0; a < pScene->mNumMeshes; ++a)
if( pScene->mMeshes[a]->mNumBones > mMaxBoneCount ) if( pScene->mMeshes[a]->mNumBones > mMaxBoneCount )
isNecessary = true; isNecessary = true;
@ -107,7 +107,7 @@ void SplitByBoneCountProcess::Execute( aiScene* pScene)
// build a new array of meshes for the scene // build a new array of meshes for the scene
std::vector<aiMesh*> meshes; std::vector<aiMesh*> meshes;
for( size_t a = 0; a < pScene->mNumMeshes; ++a) for( unsigned int a = 0; a < pScene->mNumMeshes; ++a)
{ {
aiMesh* srcMesh = pScene->mMeshes[a]; aiMesh* srcMesh = pScene->mMeshes[a];
@ -118,9 +118,9 @@ void SplitByBoneCountProcess::Execute( aiScene* pScene)
if( !newMeshes.empty() ) if( !newMeshes.empty() )
{ {
// store new meshes and indices of the new meshes // store new meshes and indices of the new meshes
for( size_t b = 0; b < newMeshes.size(); ++b) for( unsigned int b = 0; b < newMeshes.size(); ++b)
{ {
mSubMeshIndices[a].push_back( meshes.size()); mSubMeshIndices[a].push_back( static_cast<unsigned int>(meshes.size()));
meshes.push_back( newMeshes[b]); meshes.push_back( newMeshes[b]);
} }
@ -130,13 +130,13 @@ void SplitByBoneCountProcess::Execute( aiScene* pScene)
else else
{ {
// Mesh is kept unchanged - store it's new place in the mesh array // Mesh is kept unchanged - store it's new place in the mesh array
mSubMeshIndices[a].push_back( meshes.size()); mSubMeshIndices[a].push_back( static_cast<unsigned int>(meshes.size()));
meshes.push_back( srcMesh); meshes.push_back( srcMesh);
} }
} }
// rebuild the scene's mesh array // rebuild the scene's mesh array
pScene->mNumMeshes = meshes.size(); pScene->mNumMeshes = static_cast<unsigned int>(meshes.size());
delete [] pScene->mMeshes; delete [] pScene->mMeshes;
pScene->mMeshes = new aiMesh*[pScene->mNumMeshes]; pScene->mMeshes = new aiMesh*[pScene->mNumMeshes];
std::copy( meshes.begin(), meshes.end(), pScene->mMeshes); std::copy( meshes.begin(), meshes.end(), pScene->mMeshes);
@ -157,33 +157,33 @@ void SplitByBoneCountProcess::SplitMesh( const aiMesh* pMesh, std::vector<aiMesh
// necessary optimisation: build a list of all affecting bones for each vertex // necessary optimisation: build a list of all affecting bones for each vertex
// TODO: (thom) maybe add a custom allocator here to avoid allocating tens of thousands of small arrays // TODO: (thom) maybe add a custom allocator here to avoid allocating tens of thousands of small arrays
typedef std::pair<size_t, float> BoneWeight; typedef std::pair<unsigned int, float> BoneWeight;
std::vector< std::vector<BoneWeight> > vertexBones( pMesh->mNumVertices); std::vector< std::vector<BoneWeight> > vertexBones( pMesh->mNumVertices);
for( size_t a = 0; a < pMesh->mNumBones; ++a) for( unsigned int a = 0; a < pMesh->mNumBones; ++a)
{ {
const aiBone* bone = pMesh->mBones[a]; const aiBone* bone = pMesh->mBones[a];
for( size_t b = 0; b < bone->mNumWeights; ++b) for( unsigned int b = 0; b < bone->mNumWeights; ++b)
vertexBones[ bone->mWeights[b].mVertexId ].push_back( BoneWeight( a, bone->mWeights[b].mWeight)); vertexBones[ bone->mWeights[b].mVertexId ].push_back( BoneWeight( a, bone->mWeights[b].mWeight));
} }
size_t numFacesHandled = 0; unsigned int numFacesHandled = 0;
std::vector<bool> isFaceHandled( pMesh->mNumFaces, false); std::vector<bool> isFaceHandled( pMesh->mNumFaces, false);
while( numFacesHandled < pMesh->mNumFaces ) while( numFacesHandled < pMesh->mNumFaces )
{ {
// which bones are used in the current submesh // which bones are used in the current submesh
size_t numBones = 0; unsigned int numBones = 0;
std::vector<bool> isBoneUsed( pMesh->mNumBones, false); std::vector<bool> isBoneUsed( pMesh->mNumBones, false);
// indices of the faces which are going to go into this submesh // indices of the faces which are going to go into this submesh
std::vector<size_t> subMeshFaces; std::vector<unsigned int> subMeshFaces;
subMeshFaces.reserve( pMesh->mNumFaces); subMeshFaces.reserve( pMesh->mNumFaces);
// accumulated vertex count of all the faces in this submesh // accumulated vertex count of all the faces in this submesh
size_t numSubMeshVertices = 0; unsigned int numSubMeshVertices = 0;
// a small local array of new bones for the current face. State of all used bones for that face // a small local array of new bones for the current face. State of all used bones for that face
// can only be updated AFTER the face is completely analysed. Thanks to imre for the fix. // can only be updated AFTER the face is completely analysed. Thanks to imre for the fix.
std::vector<size_t> newBonesAtCurrentFace; std::vector<unsigned int> newBonesAtCurrentFace;
// add faces to the new submesh as long as all bones affecting the faces' vertices fit in the limit // add faces to the new submesh as long as all bones affecting the faces' vertices fit in the limit
for( size_t a = 0; a < pMesh->mNumFaces; ++a) for( unsigned int a = 0; a < pMesh->mNumFaces; ++a)
{ {
// skip if the face is already stored in a submesh // skip if the face is already stored in a submesh
if( isFaceHandled[a] ) if( isFaceHandled[a] )
@ -191,12 +191,12 @@ void SplitByBoneCountProcess::SplitMesh( const aiMesh* pMesh, std::vector<aiMesh
const aiFace& face = pMesh->mFaces[a]; const aiFace& face = pMesh->mFaces[a];
// check every vertex if its bones would still fit into the current submesh // check every vertex if its bones would still fit into the current submesh
for( size_t b = 0; b < face.mNumIndices; ++b ) for( unsigned int b = 0; b < face.mNumIndices; ++b )
{ {
const std::vector<BoneWeight>& vb = vertexBones[face.mIndices[b]]; const std::vector<BoneWeight>& vb = vertexBones[face.mIndices[b]];
for( size_t c = 0; c < vb.size(); ++c) for( unsigned int c = 0; c < vb.size(); ++c)
{ {
size_t boneIndex = vb[c].first; unsigned int boneIndex = vb[c].first;
// if the bone is already used in this submesh, it's ok // if the bone is already used in this submesh, it's ok
if( isBoneUsed[boneIndex] ) if( isBoneUsed[boneIndex] )
continue; continue;
@ -214,7 +214,7 @@ void SplitByBoneCountProcess::SplitMesh( const aiMesh* pMesh, std::vector<aiMesh
// mark all new bones as necessary // mark all new bones as necessary
while( !newBonesAtCurrentFace.empty() ) while( !newBonesAtCurrentFace.empty() )
{ {
size_t newIndex = newBonesAtCurrentFace.back(); unsigned int newIndex = newBonesAtCurrentFace.back();
newBonesAtCurrentFace.pop_back(); // this also avoids the deallocation which comes with a clear() newBonesAtCurrentFace.pop_back(); // this also avoids the deallocation which comes with a clear()
if( isBoneUsed[newIndex] ) if( isBoneUsed[newIndex] )
continue; continue;
@ -242,7 +242,7 @@ void SplitByBoneCountProcess::SplitMesh( const aiMesh* pMesh, std::vector<aiMesh
// create all the arrays for this mesh if the old mesh contained them // create all the arrays for this mesh if the old mesh contained them
newMesh->mNumVertices = numSubMeshVertices; newMesh->mNumVertices = numSubMeshVertices;
newMesh->mNumFaces = subMeshFaces.size(); newMesh->mNumFaces = static_cast<unsigned int>(subMeshFaces.size());
newMesh->mVertices = new aiVector3D[newMesh->mNumVertices]; newMesh->mVertices = new aiVector3D[newMesh->mNumVertices];
if( pMesh->HasNormals() ) if( pMesh->HasNormals() )
newMesh->mNormals = new aiVector3D[newMesh->mNumVertices]; newMesh->mNormals = new aiVector3D[newMesh->mNumVertices];
@ -251,13 +251,13 @@ void SplitByBoneCountProcess::SplitMesh( const aiMesh* pMesh, std::vector<aiMesh
newMesh->mTangents = new aiVector3D[newMesh->mNumVertices]; newMesh->mTangents = new aiVector3D[newMesh->mNumVertices];
newMesh->mBitangents = new aiVector3D[newMesh->mNumVertices]; newMesh->mBitangents = new aiVector3D[newMesh->mNumVertices];
} }
for( size_t a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++a ) for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++a )
{ {
if( pMesh->HasTextureCoords( a) ) if( pMesh->HasTextureCoords( a) )
newMesh->mTextureCoords[a] = new aiVector3D[newMesh->mNumVertices]; newMesh->mTextureCoords[a] = new aiVector3D[newMesh->mNumVertices];
newMesh->mNumUVComponents[a] = pMesh->mNumUVComponents[a]; newMesh->mNumUVComponents[a] = pMesh->mNumUVComponents[a];
} }
for( size_t a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; ++a ) for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; ++a )
{ {
if( pMesh->HasVertexColors( a) ) if( pMesh->HasVertexColors( a) )
newMesh->mColors[a] = new aiColor4D[newMesh->mNumVertices]; newMesh->mColors[a] = new aiColor4D[newMesh->mNumVertices];
@ -265,9 +265,9 @@ void SplitByBoneCountProcess::SplitMesh( const aiMesh* pMesh, std::vector<aiMesh
// and copy over the data, generating faces with linear indices along the way // and copy over the data, generating faces with linear indices along the way
newMesh->mFaces = new aiFace[subMeshFaces.size()]; newMesh->mFaces = new aiFace[subMeshFaces.size()];
size_t nvi = 0; // next vertex index unsigned int nvi = 0; // next vertex index
std::vector<size_t> previousVertexIndices( numSubMeshVertices, std::numeric_limits<size_t>::max()); // per new vertex: its index in the source mesh std::vector<unsigned int> previousVertexIndices( numSubMeshVertices, std::numeric_limits<unsigned int>::max()); // per new vertex: its index in the source mesh
for( size_t a = 0; a < subMeshFaces.size(); ++a ) for( unsigned int a = 0; a < subMeshFaces.size(); ++a )
{ {
const aiFace& srcFace = pMesh->mFaces[subMeshFaces[a]]; const aiFace& srcFace = pMesh->mFaces[subMeshFaces[a]];
aiFace& dstFace = newMesh->mFaces[a]; aiFace& dstFace = newMesh->mFaces[a];
@ -275,9 +275,9 @@ void SplitByBoneCountProcess::SplitMesh( const aiMesh* pMesh, std::vector<aiMesh
dstFace.mIndices = new unsigned int[dstFace.mNumIndices]; dstFace.mIndices = new unsigned int[dstFace.mNumIndices];
// accumulate linearly all the vertices of the source face // accumulate linearly all the vertices of the source face
for( size_t b = 0; b < dstFace.mNumIndices; ++b ) for( unsigned int b = 0; b < dstFace.mNumIndices; ++b )
{ {
size_t srcIndex = srcFace.mIndices[b]; unsigned int srcIndex = srcFace.mIndices[b];
dstFace.mIndices[b] = nvi; dstFace.mIndices[b] = nvi;
previousVertexIndices[nvi] = srcIndex; previousVertexIndices[nvi] = srcIndex;
@ -289,12 +289,12 @@ void SplitByBoneCountProcess::SplitMesh( const aiMesh* pMesh, std::vector<aiMesh
newMesh->mTangents[nvi] = pMesh->mTangents[srcIndex]; newMesh->mTangents[nvi] = pMesh->mTangents[srcIndex];
newMesh->mBitangents[nvi] = pMesh->mBitangents[srcIndex]; newMesh->mBitangents[nvi] = pMesh->mBitangents[srcIndex];
} }
for( size_t c = 0; c < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++c ) for( unsigned int c = 0; c < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++c )
{ {
if( pMesh->HasTextureCoords( c) ) if( pMesh->HasTextureCoords( c) )
newMesh->mTextureCoords[c][nvi] = pMesh->mTextureCoords[c][srcIndex]; newMesh->mTextureCoords[c][nvi] = pMesh->mTextureCoords[c][srcIndex];
} }
for( size_t c = 0; c < AI_MAX_NUMBER_OF_COLOR_SETS; ++c ) for( unsigned int c = 0; c < AI_MAX_NUMBER_OF_COLOR_SETS; ++c )
{ {
if( pMesh->HasVertexColors( c) ) if( pMesh->HasVertexColors( c) )
newMesh->mColors[c][nvi] = pMesh->mColors[c][srcIndex]; newMesh->mColors[c][nvi] = pMesh->mColors[c][srcIndex];
@ -310,8 +310,8 @@ void SplitByBoneCountProcess::SplitMesh( const aiMesh* pMesh, std::vector<aiMesh
newMesh->mNumBones = 0; newMesh->mNumBones = 0;
newMesh->mBones = new aiBone*[numBones]; newMesh->mBones = new aiBone*[numBones];
std::vector<size_t> mappedBoneIndex( pMesh->mNumBones, std::numeric_limits<size_t>::max()); std::vector<unsigned int> mappedBoneIndex( pMesh->mNumBones, std::numeric_limits<unsigned int>::max());
for( size_t a = 0; a < pMesh->mNumBones; ++a ) for( unsigned int a = 0; a < pMesh->mNumBones; ++a )
{ {
if( !isBoneUsed[a] ) if( !isBoneUsed[a] )
continue; continue;
@ -329,21 +329,21 @@ void SplitByBoneCountProcess::SplitMesh( const aiMesh* pMesh, std::vector<aiMesh
ai_assert( newMesh->mNumBones == numBones ); ai_assert( newMesh->mNumBones == numBones );
// iterate over all new vertices and count which bones affected its old vertex in the source mesh // iterate over all new vertices and count which bones affected its old vertex in the source mesh
for( size_t a = 0; a < numSubMeshVertices; ++a ) for( unsigned int a = 0; a < numSubMeshVertices; ++a )
{ {
size_t oldIndex = previousVertexIndices[a]; unsigned int oldIndex = previousVertexIndices[a];
const std::vector<BoneWeight>& bonesOnThisVertex = vertexBones[oldIndex]; const std::vector<BoneWeight>& bonesOnThisVertex = vertexBones[oldIndex];
for( size_t b = 0; b < bonesOnThisVertex.size(); ++b ) for( unsigned int b = 0; b < bonesOnThisVertex.size(); ++b )
{ {
size_t newBoneIndex = mappedBoneIndex[ bonesOnThisVertex[b].first ]; unsigned int newBoneIndex = mappedBoneIndex[ bonesOnThisVertex[b].first ];
if( newBoneIndex != std::numeric_limits<size_t>::max() ) if( newBoneIndex != std::numeric_limits<unsigned int>::max() )
newMesh->mBones[newBoneIndex]->mNumWeights++; newMesh->mBones[newBoneIndex]->mNumWeights++;
} }
} }
// allocate all bone weight arrays accordingly // allocate all bone weight arrays accordingly
for( size_t a = 0; a < newMesh->mNumBones; ++a ) for( unsigned int a = 0; a < newMesh->mNumBones; ++a )
{ {
aiBone* bone = newMesh->mBones[a]; aiBone* bone = newMesh->mBones[a];
ai_assert( bone->mNumWeights > 0 ); ai_assert( bone->mNumWeights > 0 );
@ -352,18 +352,18 @@ void SplitByBoneCountProcess::SplitMesh( const aiMesh* pMesh, std::vector<aiMesh
} }
// now copy all the bone vertex weights for all the vertices which made it into the new submesh // now copy all the bone vertex weights for all the vertices which made it into the new submesh
for( size_t a = 0; a < numSubMeshVertices; ++a) for( unsigned int a = 0; a < numSubMeshVertices; ++a)
{ {
// find the source vertex for it in the source mesh // find the source vertex for it in the source mesh
size_t previousIndex = previousVertexIndices[a]; unsigned int previousIndex = previousVertexIndices[a];
// these bones were affecting it // these bones were affecting it
const std::vector<BoneWeight>& bonesOnThisVertex = vertexBones[previousIndex]; const std::vector<BoneWeight>& bonesOnThisVertex = vertexBones[previousIndex];
// all of the bones affecting it should be present in the new submesh, or else // all of the bones affecting it should be present in the new submesh, or else
// the face it comprises shouldn't be present // the face it comprises shouldn't be present
for( size_t b = 0; b < bonesOnThisVertex.size(); ++b) for( unsigned int b = 0; b < bonesOnThisVertex.size(); ++b)
{ {
size_t newBoneIndex = mappedBoneIndex[ bonesOnThisVertex[b].first ]; unsigned int newBoneIndex = mappedBoneIndex[ bonesOnThisVertex[b].first ];
ai_assert( newBoneIndex != std::numeric_limits<size_t>::max() ); ai_assert( newBoneIndex != std::numeric_limits<unsigned int>::max() );
aiVertexWeight* dstWeight = newMesh->mBones[newBoneIndex]->mWeights + newMesh->mBones[newBoneIndex]->mNumWeights; aiVertexWeight* dstWeight = newMesh->mBones[newBoneIndex]->mWeights + newMesh->mBones[newBoneIndex]->mNumWeights;
newMesh->mBones[newBoneIndex]->mNumWeights++; newMesh->mBones[newBoneIndex]->mNumWeights++;
@ -383,22 +383,22 @@ void SplitByBoneCountProcess::UpdateNode( aiNode* pNode) const
// rebuild the node's mesh index list // rebuild the node's mesh index list
if( pNode->mNumMeshes > 0 ) if( pNode->mNumMeshes > 0 )
{ {
std::vector<size_t> newMeshList; std::vector<unsigned int> newMeshList;
for( size_t a = 0; a < pNode->mNumMeshes; ++a) for( unsigned int a = 0; a < pNode->mNumMeshes; ++a)
{ {
size_t srcIndex = pNode->mMeshes[a]; unsigned int srcIndex = pNode->mMeshes[a];
const std::vector<size_t>& replaceMeshes = mSubMeshIndices[srcIndex]; const std::vector<unsigned int>& replaceMeshes = mSubMeshIndices[srcIndex];
newMeshList.insert( newMeshList.end(), replaceMeshes.begin(), replaceMeshes.end()); newMeshList.insert( newMeshList.end(), replaceMeshes.begin(), replaceMeshes.end());
} }
delete pNode->mMeshes; delete pNode->mMeshes;
pNode->mNumMeshes = newMeshList.size(); pNode->mNumMeshes = static_cast<unsigned int>(newMeshList.size());
pNode->mMeshes = new unsigned int[pNode->mNumMeshes]; pNode->mMeshes = new unsigned int[pNode->mNumMeshes];
std::copy( newMeshList.begin(), newMeshList.end(), pNode->mMeshes); std::copy( newMeshList.begin(), newMeshList.end(), pNode->mMeshes);
} }
// do that also recursively for all children // do that also recursively for all children
for( size_t a = 0; a < pNode->mNumChildren; ++a ) for( unsigned int a = 0; a < pNode->mNumChildren; ++a )
{ {
UpdateNode( pNode->mChildren[a]); UpdateNode( pNode->mChildren[a]);
} }

View File

@ -101,7 +101,7 @@ public:
size_t mMaxBoneCount; size_t mMaxBoneCount;
/// Per mesh index: Array of indices of the new submeshes. /// Per mesh index: Array of indices of the new submeshes.
std::vector< std::vector<size_t> > mSubMeshIndices; std::vector< std::vector<unsigned int> > mSubMeshIndices;
}; };
} // end of namespace Assimp } // end of namespace Assimp