Merge branch 'master' into skylion007/modernize-use-emplace

pull/4700/head
Aaron Gokaslan 2022-08-23 15:14:48 -04:00 committed by GitHub
commit 25add7baa2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 44 deletions

View File

@ -147,10 +147,8 @@ void SMDImporter::InternReadFile( const std::string& pFile, aiScene* scene, IOSy
if (!asBones.empty()) { if (!asBones.empty()) {
// Check whether all bones have been initialized // Check whether all bones have been initialized
for (std::vector<SMD::Bone>::const_iterator for (const auto &asBone : asBones) {
i = asBones.begin(); if (!asBone.mName.length()) {
i != asBones.end();++i) {
if (!(*i).mName.length()) {
ASSIMP_LOG_WARN("SMD: Not all bones have been initialized"); ASSIMP_LOG_WARN("SMD: Not all bones have been initialized");
break; break;
} }
@ -210,14 +208,10 @@ void SMDImporter::LogWarning(const char* msg) {
void SMDImporter::FixTimeValues() { void SMDImporter::FixTimeValues() {
double dDelta = (double)iSmallestFrame; double dDelta = (double)iSmallestFrame;
double dMax = 0.0f; double dMax = 0.0f;
for (std::vector<SMD::Bone>::iterator for (auto &asBone : asBones) {
iBone = asBones.begin(); for (auto &asKey : asBone.sAnim.asKeys) {
iBone != asBones.end();++iBone) { asKey.dTime -= dDelta;
for (std::vector<SMD::Bone::Animation::MatrixKey>::iterator dMax = std::max(dMax, asKey.dTime);
iKey = (*iBone).sAnim.asKeys.begin();
iKey != (*iBone).sAnim.asKeys.end();++iKey) {
(*iKey).dTime -= dDelta;
dMax = std::max(dMax, (*iKey).dTime);
} }
} }
dLengthOfAnim = dMax; dLengthOfAnim = dMax;
@ -237,7 +231,7 @@ void SMDImporter::CreateOutputMeshes() {
pScene->mMeshes = new aiMesh*[pScene->mNumMeshes]; pScene->mMeshes = new aiMesh*[pScene->mNumMeshes];
typedef std::vector<unsigned int> FaceList; typedef std::vector<unsigned int> FaceList;
FaceList* aaiFaces = new FaceList[pScene->mNumMeshes]; std::unique_ptr<FaceList[]> aaiFaces(new FaceList[pScene->mNumMeshes]);
// approximate the space that will be required // approximate the space that will be required
unsigned int iNum = (unsigned int)asTriangles.size() / pScene->mNumMeshes; unsigned int iNum = (unsigned int)asTriangles.size() / pScene->mNumMeshes;
@ -248,17 +242,14 @@ void SMDImporter::CreateOutputMeshes() {
// collect all faces // collect all faces
iNum = 0; iNum = 0;
for (std::vector<SMD::Face>::const_iterator for (const auto &asTriangle : asTriangles) {
iFace = asTriangles.begin(); if (asTriangle.iTexture >= aszTextures.size()) {
iFace != asTriangles.end();++iFace,++iNum) {
if (UINT_MAX == (*iFace).iTexture) {
aaiFaces[(*iFace).iTexture].push_back( 0 );
} else if ((*iFace).iTexture >= aszTextures.size()) {
ASSIMP_LOG_INFO("[SMD/VTA] Material index overflow in face"); ASSIMP_LOG_INFO("[SMD/VTA] Material index overflow in face");
aaiFaces[(*iFace).iTexture].push_back((unsigned int)aszTextures.size()-1); aaiFaces[asTriangle.iTexture].push_back((unsigned int)aszTextures.size()-1);
} else { } else {
aaiFaces[(*iFace).iTexture].push_back(iNum); aaiFaces[asTriangle.iTexture].push_back(iNum);
} }
++iNum;
} }
// now create the output meshes // now create the output meshes
@ -275,7 +266,7 @@ void SMDImporter::CreateOutputMeshes() {
typedef std::pair<unsigned int,float> TempWeightListEntry; typedef std::pair<unsigned int,float> TempWeightListEntry;
typedef std::vector< TempWeightListEntry > TempBoneWeightList; typedef std::vector< TempWeightListEntry > TempBoneWeightList;
TempBoneWeightList* aaiBones = new TempBoneWeightList[asBones.size()](); std::unique_ptr<TempBoneWeightList[]> aaiBones(new TempBoneWeightList[asBones.size()]());
// try to reserve enough memory without wasting too much // try to reserve enough memory without wasting too much
for (unsigned int iBone = 0; iBone < asBones.size();++iBone) { for (unsigned int iBone = 0; iBone < asBones.size();++iBone) {
@ -351,8 +342,7 @@ void SMDImporter::CreateOutputMeshes() {
if (fSum) { if (fSum) {
fSum = 1 / fSum; fSum = 1 / fSum;
for (unsigned int iBone = 0;iBone < face.avVertices[iVert].aiBoneLinks.size();++iBone) { for (auto &pairval : face.avVertices[iVert].aiBoneLinks) {
TempWeightListEntry& pairval = face.avVertices[iVert].aiBoneLinks[iBone];
if (pairval.first >= asBones.size()) { if (pairval.first >= asBones.size()) {
continue; continue;
} }
@ -398,9 +388,7 @@ void SMDImporter::CreateOutputMeshes() {
++iNum; ++iNum;
} }
} }
delete[] aaiBones;
} }
delete[] aaiFaces;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -411,8 +399,7 @@ void SMDImporter::AddBoneChildren(aiNode* pcNode, uint32_t iParent) {
ai_assert( nullptr == pcNode->mChildren); ai_assert( nullptr == pcNode->mChildren);
// first count ... // first count ...
for (unsigned int i = 0; i < asBones.size();++i) { for (auto &bone : asBones) {
SMD::Bone& bone = asBones[i];
if (bone.iParent == iParent) { if (bone.iParent == iParent) {
++pcNode->mNumChildren; ++pcNode->mNumChildren;
} }
@ -516,27 +503,25 @@ void SMDImporter::CreateOutputAnimation(int index, const std::string &name) {
// now build valid keys // now build valid keys
unsigned int a = 0; unsigned int a = 0;
for (std::vector<SMD::Bone>::const_iterator i = asBones.begin(); i != asBones.end(); ++i) { for (const auto &asBone : asBones) {
aiNodeAnim* p = pp[a] = new aiNodeAnim(); aiNodeAnim* p = pp[a] = new aiNodeAnim();
// copy the name of the bone // copy the name of the bone
p->mNodeName.Set(i->mName); p->mNodeName.Set(asBone.mName);
p->mNumRotationKeys = (unsigned int)(*i).sAnim.asKeys.size(); p->mNumRotationKeys = (unsigned int)asBone.sAnim.asKeys.size();
if (p->mNumRotationKeys){ if (p->mNumRotationKeys){
p->mNumPositionKeys = p->mNumRotationKeys; p->mNumPositionKeys = p->mNumRotationKeys;
aiVectorKey* pVecKeys = p->mPositionKeys = new aiVectorKey[p->mNumRotationKeys]; aiVectorKey* pVecKeys = p->mPositionKeys = new aiVectorKey[p->mNumRotationKeys];
aiQuatKey* pRotKeys = p->mRotationKeys = new aiQuatKey[p->mNumRotationKeys]; aiQuatKey* pRotKeys = p->mRotationKeys = new aiQuatKey[p->mNumRotationKeys];
for (std::vector<SMD::Bone::Animation::MatrixKey>::const_iterator for (const auto &asKey : asBone.sAnim.asKeys) {
qq = (*i).sAnim.asKeys.begin(); pRotKeys->mTime = pVecKeys->mTime = asKey.dTime;
qq != (*i).sAnim.asKeys.end(); ++qq) {
pRotKeys->mTime = pVecKeys->mTime = (*qq).dTime;
// compute the rotation quaternion from the euler angles // compute the rotation quaternion from the euler angles
// aiQuaternion: The order of the parameters is yzx? // aiQuaternion: The order of the parameters is yzx?
pRotKeys->mValue = aiQuaternion((*qq).vRot.y, (*qq).vRot.z, (*qq).vRot.x); pRotKeys->mValue = aiQuaternion(asKey.vRot.y, asKey.vRot.z, asKey.vRot.x);
pVecKeys->mValue = (*qq).vPos; pVecKeys->mValue = asKey.vPos;
++pVecKeys; ++pRotKeys; ++pVecKeys; ++pRotKeys;
} }
@ -982,8 +967,8 @@ void SMDImporter::ParseTriangle(const char* szCurrent, const char** szCurrentOut
SkipSpacesAndLineEnd(szCurrent,&szCurrent); SkipSpacesAndLineEnd(szCurrent,&szCurrent);
// load three vertices // load three vertices
for (unsigned int iVert = 0; iVert < 3;++iVert) { for (auto &avVertex : face.avVertices) {
ParseVertex(szCurrent,&szCurrent, face.avVertices[iVert]); ParseVertex(szCurrent,&szCurrent, avVertex);
} }
*szCurrentOut = szCurrent; *szCurrentOut = szCurrent;
} }
@ -1080,13 +1065,11 @@ void SMDImporter::ParseVertex(const char* szCurrent,
} }
vertex.aiBoneLinks.resize(iSize,std::pair<unsigned int, float>(0,0.0f)); vertex.aiBoneLinks.resize(iSize,std::pair<unsigned int, float>(0,0.0f));
for (std::vector<std::pair<unsigned int, float> >::iterator for (auto &aiBoneLink : vertex.aiBoneLinks) {
i = vertex.aiBoneLinks.begin(); if(!ParseUnsignedInt(szCurrent,&szCurrent,aiBoneLink.first)) {
i != vertex.aiBoneLinks.end();++i) {
if(!ParseUnsignedInt(szCurrent,&szCurrent,(*i).first)) {
SMDI_PARSE_RETURN; SMDI_PARSE_RETURN;
} }
if(!ParseFloat(szCurrent,&szCurrent,(*i).second)) { if(!ParseFloat(szCurrent,&szCurrent,aiBoneLink.second)) {
SMDI_PARSE_RETURN; SMDI_PARSE_RETURN;
} }
} }