Fix for 3489 | Preserve morph targets when splitting by bone count

pull/3512/head
Oleg Bogdanov 2020-11-28 10:01:50 -08:00
parent 9ae112309f
commit 4d4a3c42f6
1 changed files with 39 additions and 0 deletions

View File

@ -408,6 +408,45 @@ void SplitByBoneCountProcess::SplitMesh( const aiMesh* pMesh, std::vector<aiMesh
}
}
// ... and copy all the morph targets for all the vertices which made it into the new submesh
if (pMesh->mNumAnimMeshes > 0) {
newMesh->mNumAnimMeshes = pMesh->mNumAnimMeshes;
newMesh->mAnimMeshes = new aiAnimMesh*[newMesh->mNumAnimMeshes];
for (unsigned int morphIdx = 0; morphIdx < newMesh->mNumAnimMeshes; ++morphIdx) {
aiAnimMesh* origTarget = pMesh->mAnimMeshes[morphIdx];
aiAnimMesh* newTarget = new aiAnimMesh;
newTarget->mName = origTarget->mName;
newTarget->mWeight = origTarget->mWeight;
newTarget->mNumVertices = numSubMeshVertices;
newTarget->mVertices = new aiVector3D[numSubMeshVertices];
newMesh->mAnimMeshes[morphIdx] = newTarget;
if (origTarget->HasNormals()) {
newTarget->mNormals = new aiVector3D[numSubMeshVertices];
}
if (origTarget->HasTangentsAndBitangents()) {
newTarget->mTangents = new aiVector3D[numSubMeshVertices];
newTarget->mBitangents = new aiVector3D[numSubMeshVertices];
}
for( unsigned int vi = 0; vi < numSubMeshVertices; ++vi) {
// find the source vertex for it in the source mesh
unsigned int previousIndex = previousVertexIndices[vi];
newTarget->mVertices[vi] = origTarget->mVertices[previousIndex];
if (newTarget->HasNormals()) {
newTarget->mNormals[vi] = origTarget->mNormals[previousIndex];
}
if (newTarget->HasTangentsAndBitangents()) {
newTarget->mTangents[vi] = origTarget->mTangents[previousIndex];
newTarget->mBitangents[vi] = origTarget->mBitangents[previousIndex];
}
}
}
}
// I have the strange feeling that this will break apart at some point in time...
}
}