Fixed build warnings on MSVC14 x64 in the Collada loader.

pull/1083/head
Jared Mulconry 2016-11-19 03:16:06 +11:00
parent 3b63e4af54
commit 128c27e89c
1 changed files with 35 additions and 25 deletions

View File

@ -58,6 +58,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "time.h" #include "time.h"
#include "math.h" #include "math.h"
#include <algorithm>
#include <cstdint>
#include <numeric> #include <numeric>
#include "Defines.h" #include "Defines.h"
@ -240,7 +242,7 @@ aiNode* ColladaLoader::BuildHierarchy( const ColladaParser& pParser, const Colla
ResolveNodeInstances(pParser,pNode,instances); ResolveNodeInstances(pParser,pNode,instances);
// add children. first the *real* ones // add children. first the *real* ones
node->mNumChildren = pNode->mChildren.size()+instances.size(); node->mNumChildren = static_cast<unsigned int>(pNode->mChildren.size()+instances.size());
node->mChildren = new aiNode*[node->mNumChildren]; node->mChildren = new aiNode*[node->mNumChildren];
for( size_t a = 0; a < pNode->mChildren.size(); a++) for( size_t a = 0; a < pNode->mChildren.size(); a++)
@ -506,7 +508,7 @@ void ColladaLoader::BuildMeshesForNode( const ColladaParser& pParser, const Coll
std::map<std::string, size_t>::const_iterator matIt = mMaterialIndexByName.find( meshMaterial); std::map<std::string, size_t>::const_iterator matIt = mMaterialIndexByName.find( meshMaterial);
unsigned int matIdx; unsigned int matIdx;
if( matIt != mMaterialIndexByName.end()) if( matIt != mMaterialIndexByName.end())
matIdx = matIt->second; matIdx = static_cast<unsigned int>(matIt->second);
else else
matIdx = 0; matIdx = 0;
@ -553,11 +555,19 @@ void ColladaLoader::BuildMeshesForNode( const ColladaParser& pParser, const Coll
} }
// now place all mesh references we gathered in the target node // now place all mesh references we gathered in the target node
pTarget->mNumMeshes = newMeshRefs.size(); pTarget->mNumMeshes = static_cast<unsigned int>(newMeshRefs.size());
if( newMeshRefs.size()) if( newMeshRefs.size())
{ {
struct UIntTypeConverter
{
unsigned int operator()(const size_t& v) const
{
return static_cast<unsigned int>(v);
}
};
pTarget->mMeshes = new unsigned int[pTarget->mNumMeshes]; pTarget->mMeshes = new unsigned int[pTarget->mNumMeshes];
std::copy( newMeshRefs.begin(), newMeshRefs.end(), pTarget->mMeshes); std::transform( newMeshRefs.begin(), newMeshRefs.end(), pTarget->mMeshes, UIntTypeConverter());
} }
} }
@ -572,10 +582,10 @@ aiMesh* ColladaLoader::CreateMesh( const ColladaParser& pParser, const Collada::
// count the vertices addressed by its faces // count the vertices addressed by its faces
const size_t numVertices = std::accumulate( pSrcMesh->mFaceSize.begin() + pStartFace, const size_t numVertices = std::accumulate( pSrcMesh->mFaceSize.begin() + pStartFace,
pSrcMesh->mFaceSize.begin() + pStartFace + pSubMesh.mNumFaces, 0); pSrcMesh->mFaceSize.begin() + pStartFace + pSubMesh.mNumFaces, size_t(0));
// copy positions // copy positions
dstMesh->mNumVertices = numVertices; dstMesh->mNumVertices = static_cast<unsigned int>(numVertices);
dstMesh->mVertices = new aiVector3D[numVertices]; dstMesh->mVertices = new aiVector3D[numVertices];
std::copy( pSrcMesh->mPositions.begin() + pStartVertex, pSrcMesh->mPositions.begin() + std::copy( pSrcMesh->mPositions.begin() + pStartVertex, pSrcMesh->mPositions.begin() +
pStartVertex + numVertices, dstMesh->mVertices); pStartVertex + numVertices, dstMesh->mVertices);
@ -634,16 +644,16 @@ aiMesh* ColladaLoader::CreateMesh( const ColladaParser& pParser, const Collada::
// create faces. Due to the fact that each face uses unique vertices, we can simply count up on each vertex // create faces. Due to the fact that each face uses unique vertices, we can simply count up on each vertex
size_t vertex = 0; size_t vertex = 0;
dstMesh->mNumFaces = pSubMesh.mNumFaces; dstMesh->mNumFaces = static_cast<unsigned int>(pSubMesh.mNumFaces);
dstMesh->mFaces = new aiFace[dstMesh->mNumFaces]; dstMesh->mFaces = new aiFace[dstMesh->mNumFaces];
for( size_t a = 0; a < dstMesh->mNumFaces; ++a) for( size_t a = 0; a < dstMesh->mNumFaces; ++a)
{ {
size_t s = pSrcMesh->mFaceSize[ pStartFace + a]; size_t s = pSrcMesh->mFaceSize[ pStartFace + a];
aiFace& face = dstMesh->mFaces[a]; aiFace& face = dstMesh->mFaces[a];
face.mNumIndices = s; face.mNumIndices = static_cast<unsigned int>(s);
face.mIndices = new unsigned int[s]; face.mIndices = new unsigned int[s];
for( size_t b = 0; b < s; ++b) for( size_t b = 0; b < s; ++b)
face.mIndices[b] = vertex++; face.mIndices[b] = static_cast<unsigned int>(vertex++);
} }
// create bones if given // create bones if given
@ -710,7 +720,7 @@ aiMesh* ColladaLoader::CreateMesh( const ColladaParser& pParser, const Collada::
if( weight > 0.0f) if( weight > 0.0f)
{ {
aiVertexWeight w; aiVertexWeight w;
w.mVertexId = a - pStartVertex; w.mVertexId = static_cast<unsigned int>(a - pStartVertex);
w.mWeight = weight; w.mWeight = weight;
dstBones[jointIndex].push_back( w); dstBones[jointIndex].push_back( w);
} }
@ -724,7 +734,7 @@ aiMesh* ColladaLoader::CreateMesh( const ColladaParser& pParser, const Collada::
numRemainingBones++; numRemainingBones++;
// create bone array and copy bone weights one by one // create bone array and copy bone weights one by one
dstMesh->mNumBones = numRemainingBones; dstMesh->mNumBones = static_cast<unsigned int>(numRemainingBones);
dstMesh->mBones = new aiBone*[numRemainingBones]; dstMesh->mBones = new aiBone*[numRemainingBones];
size_t boneCount = 0; size_t boneCount = 0;
for( size_t a = 0; a < numBones; ++a) for( size_t a = 0; a < numBones; ++a)
@ -748,7 +758,7 @@ aiMesh* ColladaLoader::CreateMesh( const ColladaParser& pParser, const Collada::
bone->mOffsetMatrix.c2 = ReadFloat( jointMatrixAcc, jointMatrices, a, 9); bone->mOffsetMatrix.c2 = ReadFloat( jointMatrixAcc, jointMatrices, a, 9);
bone->mOffsetMatrix.c3 = ReadFloat( jointMatrixAcc, jointMatrices, a, 10); bone->mOffsetMatrix.c3 = ReadFloat( jointMatrixAcc, jointMatrices, a, 10);
bone->mOffsetMatrix.c4 = ReadFloat( jointMatrixAcc, jointMatrices, a, 11); bone->mOffsetMatrix.c4 = ReadFloat( jointMatrixAcc, jointMatrices, a, 11);
bone->mNumWeights = dstBones[a].size(); bone->mNumWeights = static_cast<unsigned int>(dstBones[a].size());
bone->mWeights = new aiVertexWeight[bone->mNumWeights]; bone->mWeights = new aiVertexWeight[bone->mNumWeights];
std::copy( dstBones[a].begin(), dstBones[a].end(), bone->mWeights); std::copy( dstBones[a].begin(), dstBones[a].end(), bone->mWeights);
@ -798,7 +808,7 @@ aiMesh* ColladaLoader::CreateMesh( const ColladaParser& pParser, const Collada::
// Stores all meshes in the given scene // Stores all meshes in the given scene
void ColladaLoader::StoreSceneMeshes( aiScene* pScene) void ColladaLoader::StoreSceneMeshes( aiScene* pScene)
{ {
pScene->mNumMeshes = mMeshes.size(); pScene->mNumMeshes = static_cast<unsigned int>(mMeshes.size());
if( mMeshes.size() > 0) if( mMeshes.size() > 0)
{ {
pScene->mMeshes = new aiMesh*[mMeshes.size()]; pScene->mMeshes = new aiMesh*[mMeshes.size()];
@ -811,7 +821,7 @@ void ColladaLoader::StoreSceneMeshes( aiScene* pScene)
// Stores all cameras in the given scene // Stores all cameras in the given scene
void ColladaLoader::StoreSceneCameras( aiScene* pScene) void ColladaLoader::StoreSceneCameras( aiScene* pScene)
{ {
pScene->mNumCameras = mCameras.size(); pScene->mNumCameras = static_cast<unsigned int>(mCameras.size());
if( mCameras.size() > 0) if( mCameras.size() > 0)
{ {
pScene->mCameras = new aiCamera*[mCameras.size()]; pScene->mCameras = new aiCamera*[mCameras.size()];
@ -824,7 +834,7 @@ void ColladaLoader::StoreSceneCameras( aiScene* pScene)
// Stores all lights in the given scene // Stores all lights in the given scene
void ColladaLoader::StoreSceneLights( aiScene* pScene) void ColladaLoader::StoreSceneLights( aiScene* pScene)
{ {
pScene->mNumLights = mLights.size(); pScene->mNumLights = static_cast<unsigned int>(mLights.size());
if( mLights.size() > 0) if( mLights.size() > 0)
{ {
pScene->mLights = new aiLight*[mLights.size()]; pScene->mLights = new aiLight*[mLights.size()];
@ -837,7 +847,7 @@ void ColladaLoader::StoreSceneLights( aiScene* pScene)
// Stores all textures in the given scene // Stores all textures in the given scene
void ColladaLoader::StoreSceneTextures( aiScene* pScene) void ColladaLoader::StoreSceneTextures( aiScene* pScene)
{ {
pScene->mNumTextures = mTextures.size(); pScene->mNumTextures = static_cast<unsigned int>(mTextures.size());
if( mTextures.size() > 0) if( mTextures.size() > 0)
{ {
pScene->mTextures = new aiTexture*[mTextures.size()]; pScene->mTextures = new aiTexture*[mTextures.size()];
@ -850,7 +860,7 @@ void ColladaLoader::StoreSceneTextures( aiScene* pScene)
// Stores all materials in the given scene // Stores all materials in the given scene
void ColladaLoader::StoreSceneMaterials( aiScene* pScene) void ColladaLoader::StoreSceneMaterials( aiScene* pScene)
{ {
pScene->mNumMaterials = newMats.size(); pScene->mNumMaterials = static_cast<unsigned int>(newMats.size());
if (newMats.size() > 0) { if (newMats.size() > 0) {
pScene->mMaterials = new aiMaterial*[newMats.size()]; pScene->mMaterials = new aiMaterial*[newMats.size()];
@ -891,7 +901,7 @@ void ColladaLoader::StoreAnimations( aiScene* pScene, const ColladaParser& pPars
combinedAnim->mName = aiString( std::string( "combinedAnim_") + char( '0' + a)); combinedAnim->mName = aiString( std::string( "combinedAnim_") + char( '0' + a));
combinedAnim->mDuration = templateAnim->mDuration; combinedAnim->mDuration = templateAnim->mDuration;
combinedAnim->mTicksPerSecond = templateAnim->mTicksPerSecond; combinedAnim->mTicksPerSecond = templateAnim->mTicksPerSecond;
combinedAnim->mNumChannels = collectedAnimIndices.size() + 1; combinedAnim->mNumChannels = static_cast<unsigned int>(collectedAnimIndices.size() + 1);
combinedAnim->mChannels = new aiNodeAnim*[combinedAnim->mNumChannels]; combinedAnim->mChannels = new aiNodeAnim*[combinedAnim->mNumChannels];
// add the template anim as first channel by moving its aiNodeAnim to the combined animation // add the template anim as first channel by moving its aiNodeAnim to the combined animation
combinedAnim->mChannels[0] = templateAnim->mChannels[0]; combinedAnim->mChannels[0] = templateAnim->mChannels[0];
@ -923,7 +933,7 @@ void ColladaLoader::StoreAnimations( aiScene* pScene, const ColladaParser& pPars
// now store all anims in the scene // now store all anims in the scene
if( !mAnims.empty()) if( !mAnims.empty())
{ {
pScene->mNumAnimations = mAnims.size(); pScene->mNumAnimations = static_cast<unsigned int>(mAnims.size());
pScene->mAnimations = new aiAnimation*[mAnims.size()]; pScene->mAnimations = new aiAnimation*[mAnims.size()];
std::copy( mAnims.begin(), mAnims.end(), pScene->mAnimations); std::copy( mAnims.begin(), mAnims.end(), pScene->mAnimations);
} }
@ -1207,9 +1217,9 @@ void ColladaLoader::CreateAnimation( aiScene* pScene, const ColladaParser& pPars
{ {
aiNodeAnim* dstAnim = new aiNodeAnim; aiNodeAnim* dstAnim = new aiNodeAnim;
dstAnim->mNodeName = nodeName; dstAnim->mNodeName = nodeName;
dstAnim->mNumPositionKeys = resultTrafos.size(); dstAnim->mNumPositionKeys = static_cast<unsigned int>(resultTrafos.size());
dstAnim->mNumRotationKeys= resultTrafos.size(); dstAnim->mNumRotationKeys= static_cast<unsigned int>(resultTrafos.size());
dstAnim->mNumScalingKeys = resultTrafos.size(); dstAnim->mNumScalingKeys = static_cast<unsigned int>(resultTrafos.size());
dstAnim->mPositionKeys = new aiVectorKey[resultTrafos.size()]; dstAnim->mPositionKeys = new aiVectorKey[resultTrafos.size()];
dstAnim->mRotationKeys = new aiQuatKey[resultTrafos.size()]; dstAnim->mRotationKeys = new aiQuatKey[resultTrafos.size()];
dstAnim->mScalingKeys = new aiVectorKey[resultTrafos.size()]; dstAnim->mScalingKeys = new aiVectorKey[resultTrafos.size()];
@ -1237,7 +1247,7 @@ void ColladaLoader::CreateAnimation( aiScene* pScene, const ColladaParser& pPars
{ {
aiAnimation* anim = new aiAnimation; aiAnimation* anim = new aiAnimation;
anim->mName.Set( pName); anim->mName.Set( pName);
anim->mNumChannels = anims.size(); anim->mNumChannels = static_cast<unsigned int>(anims.size());
anim->mChannels = new aiNodeAnim*[anims.size()]; anim->mChannels = new aiNodeAnim*[anims.size()];
std::copy( anims.begin(), anims.end(), anim->mChannels); std::copy( anims.begin(), anims.end(), anim->mChannels);
anim->mDuration = 0.0f; anim->mDuration = 0.0f;
@ -1520,13 +1530,13 @@ aiString ColladaLoader::FindFilenameForEffectTexture( const ColladaParser& pPars
// and copy texture data // and copy texture data
tex->mHeight = 0; tex->mHeight = 0;
tex->mWidth = imIt->second.mImageData.size(); tex->mWidth = static_cast<unsigned int>(imIt->second.mImageData.size());
tex->pcData = (aiTexel*)new char[tex->mWidth]; tex->pcData = (aiTexel*)new char[tex->mWidth];
memcpy(tex->pcData,&imIt->second.mImageData[0],tex->mWidth); memcpy(tex->pcData,&imIt->second.mImageData[0],tex->mWidth);
// setup texture reference string // setup texture reference string
result.data[0] = '*'; result.data[0] = '*';
result.length = 1 + ASSIMP_itoa10(result.data+1,MAXLEN-1,mTextures.size()); result.length = 1 + ASSIMP_itoa10(result.data+1,static_cast<unsigned int>(MAXLEN-1),static_cast<int32_t>(mTextures.size()));
// and add this texture to the list // and add this texture to the list
mTextures.push_back(tex); mTextures.push_back(tex);