Use unique_ptr to release old vertices data.
parent
7a4d8ec412
commit
b2bfe6d253
|
@ -157,52 +157,46 @@ void updateXMeshVertices(XMesh *pMesh, std::vector<int> &uniqueVertices) {
|
||||||
|
|
||||||
// Position, if present (check made for aiAnimMesh)
|
// Position, if present (check made for aiAnimMesh)
|
||||||
if (pMesh->mVertices) {
|
if (pMesh->mVertices) {
|
||||||
aiVector3D *oldVertices = pMesh->mVertices;
|
std::unique_ptr<aiVector3D[]> oldVertices(pMesh->mVertices);
|
||||||
pMesh->mVertices = new aiVector3D[pMesh->mNumVertices];
|
pMesh->mVertices = new aiVector3D[pMesh->mNumVertices];
|
||||||
for (unsigned int a = 0; a < pMesh->mNumVertices; a++)
|
for (unsigned int a = 0; a < pMesh->mNumVertices; a++)
|
||||||
pMesh->mVertices[a] = oldVertices[uniqueVertices[a]];
|
pMesh->mVertices[a] = oldVertices[uniqueVertices[a]];
|
||||||
delete [] oldVertices;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Normals, if present
|
// Normals, if present
|
||||||
if (pMesh->mNormals) {
|
if (pMesh->mNormals) {
|
||||||
aiVector3D *oldNormals = pMesh->mNormals;
|
std::unique_ptr<aiVector3D[]> oldNormals(pMesh->mNormals);
|
||||||
pMesh->mNormals = new aiVector3D[pMesh->mNumVertices];
|
pMesh->mNormals = new aiVector3D[pMesh->mNumVertices];
|
||||||
for (unsigned int a = 0; a < pMesh->mNumVertices; a++)
|
for (unsigned int a = 0; a < pMesh->mNumVertices; a++)
|
||||||
pMesh->mNormals[a] = oldNormals[uniqueVertices[a]];
|
pMesh->mNormals[a] = oldNormals[uniqueVertices[a]];
|
||||||
delete oldNormals;
|
|
||||||
}
|
}
|
||||||
// Tangents, if present
|
// Tangents, if present
|
||||||
if (pMesh->mTangents) {
|
if (pMesh->mTangents) {
|
||||||
aiVector3D *oldTangents = pMesh->mTangents;
|
std::unique_ptr<aiVector3D[]> oldTangents(pMesh->mTangents);
|
||||||
pMesh->mTangents = new aiVector3D[pMesh->mNumVertices];
|
pMesh->mTangents = new aiVector3D[pMesh->mNumVertices];
|
||||||
for (unsigned int a = 0; a < pMesh->mNumVertices; a++)
|
for (unsigned int a = 0; a < pMesh->mNumVertices; a++)
|
||||||
pMesh->mTangents[a] = oldTangents[uniqueVertices[a]];
|
pMesh->mTangents[a] = oldTangents[uniqueVertices[a]];
|
||||||
delete oldTangents;
|
|
||||||
}
|
}
|
||||||
// Bitangents as well
|
// Bitangents as well
|
||||||
if (pMesh->mBitangents) {
|
if (pMesh->mBitangents) {
|
||||||
aiVector3D *oldBitangents = pMesh->mBitangents;
|
std::unique_ptr<aiVector3D[]> oldBitangents(pMesh->mBitangents);
|
||||||
pMesh->mBitangents = new aiVector3D[pMesh->mNumVertices];
|
pMesh->mBitangents = new aiVector3D[pMesh->mNumVertices];
|
||||||
for (unsigned int a = 0; a < pMesh->mNumVertices; a++)
|
for (unsigned int a = 0; a < pMesh->mNumVertices; a++)
|
||||||
pMesh->mBitangents[a] = oldBitangents[uniqueVertices[a]];
|
pMesh->mBitangents[a] = oldBitangents[uniqueVertices[a]];
|
||||||
delete oldBitangents;
|
|
||||||
}
|
}
|
||||||
// Vertex colors
|
// Vertex colors
|
||||||
for (unsigned int a = 0; pMesh->HasVertexColors(a); a++) {
|
for (unsigned int a = 0; pMesh->HasVertexColors(a); a++) {
|
||||||
aiColor4D *oldColors = pMesh->mColors[a];
|
std::unique_ptr<aiColor4D[]> oldColors(pMesh->mColors[a]);
|
||||||
pMesh->mColors[a] = new aiColor4D[pMesh->mNumVertices];
|
pMesh->mColors[a] = new aiColor4D[pMesh->mNumVertices];
|
||||||
for (unsigned int b = 0; b < pMesh->mNumVertices; b++)
|
for (unsigned int b = 0; b < pMesh->mNumVertices; b++)
|
||||||
pMesh->mColors[a][b] = oldColors[uniqueVertices[b]];
|
pMesh->mColors[a][b] = oldColors[uniqueVertices[b]];
|
||||||
delete [] oldColors;
|
|
||||||
}
|
}
|
||||||
// Texture coords
|
// Texture coords
|
||||||
for (unsigned int a = 0; pMesh->HasTextureCoords(a); a++) {
|
for (unsigned int a = 0; pMesh->HasTextureCoords(a); a++) {
|
||||||
aiVector3D *oldTextureCoords = pMesh->mTextureCoords[a];
|
std::unique_ptr<aiVector3D[]> oldTextureCoords(pMesh->mTextureCoords[a]);
|
||||||
pMesh->mTextureCoords[a] = new aiVector3D[pMesh->mNumVertices];
|
pMesh->mTextureCoords[a] = new aiVector3D[pMesh->mNumVertices];
|
||||||
for (unsigned int b = 0; b < pMesh->mNumVertices; b++)
|
for (unsigned int b = 0; b < pMesh->mNumVertices; b++)
|
||||||
pMesh->mTextureCoords[a][b] = oldTextureCoords[uniqueVertices[b]];
|
pMesh->mTextureCoords[a][b] = oldTextureCoords[uniqueVertices[b]];
|
||||||
delete [] oldTextureCoords;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue