Merge branch 'master' into patch-1

pull/3543/head
Martin 2020-12-17 14:29:51 +01:00 committed by GitHub
commit 6003be382c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 72 additions and 8 deletions

View File

@ -79,7 +79,7 @@ using namespace Util;
#define MAGIC_NODE_TAG "_$AssimpFbx$" #define MAGIC_NODE_TAG "_$AssimpFbx$"
#define CONVERT_FBX_TIME(time) static_cast<double>(time) / 46186158000LL #define CONVERT_FBX_TIME(time) (static_cast<double>(time) * 1000.0 / 46186158000LL)
FBXConverter::FBXConverter(aiScene *out, const Document &doc, bool removeEmptyBones) : FBXConverter::FBXConverter(aiScene *out, const Document &doc, bool removeEmptyBones) :
defaultMaterialIndex(), defaultMaterialIndex(),
@ -2560,7 +2560,7 @@ void FBXConverter::ConvertAnimationStack(const AnimationStack &st) {
meshMorphAnim->mKeys[j].mNumValuesAndWeights = numValuesAndWeights; meshMorphAnim->mKeys[j].mNumValuesAndWeights = numValuesAndWeights;
meshMorphAnim->mKeys[j].mValues = new unsigned int[numValuesAndWeights]; meshMorphAnim->mKeys[j].mValues = new unsigned int[numValuesAndWeights];
meshMorphAnim->mKeys[j].mWeights = new double[numValuesAndWeights]; meshMorphAnim->mKeys[j].mWeights = new double[numValuesAndWeights];
meshMorphAnim->mKeys[j].mTime = CONVERT_FBX_TIME(animIt.first) * anim_fps; meshMorphAnim->mKeys[j].mTime = CONVERT_FBX_TIME(animIt.first);
for (unsigned int k = 0; k < numValuesAndWeights; k++) { for (unsigned int k = 0; k < numValuesAndWeights; k++) {
meshMorphAnim->mKeys[j].mValues[k] = keyData->values.at(k); meshMorphAnim->mKeys[j].mValues[k] = keyData->values.at(k);
meshMorphAnim->mKeys[j].mWeights[k] = keyData->weights.at(k); meshMorphAnim->mKeys[j].mWeights[k] = keyData->weights.at(k);
@ -2578,8 +2578,8 @@ void FBXConverter::ConvertAnimationStack(const AnimationStack &st) {
return; return;
} }
double start_time_fps = has_local_startstop ? (CONVERT_FBX_TIME(start_time) * anim_fps) : min_time; double start_time_fps = has_local_startstop ? CONVERT_FBX_TIME(start_time) : min_time;
double stop_time_fps = has_local_startstop ? (CONVERT_FBX_TIME(stop_time) * anim_fps) : max_time; double stop_time_fps = has_local_startstop ? CONVERT_FBX_TIME(stop_time) : max_time;
// adjust relative timing for animation // adjust relative timing for animation
for (unsigned int c = 0; c < anim->mNumChannels; c++) { for (unsigned int c = 0; c < anim->mNumChannels; c++) {
@ -3099,7 +3099,7 @@ aiNodeAnim* FBXConverter::GenerateSimpleNodeAnim(const std::string& name,
InterpolateKeys(outTranslations, keytimes, keyframeLists[TransformationComp_Translation], defTranslate, maxTime, minTime); InterpolateKeys(outTranslations, keytimes, keyframeLists[TransformationComp_Translation], defTranslate, maxTime, minTime);
} else { } else {
for (size_t i = 0; i < keyCount; ++i) { for (size_t i = 0; i < keyCount; ++i) {
outTranslations[i].mTime = CONVERT_FBX_TIME(keytimes[i]) * anim_fps; outTranslations[i].mTime = CONVERT_FBX_TIME(keytimes[i]);
outTranslations[i].mValue = defTranslate; outTranslations[i].mValue = defTranslate;
} }
} }
@ -3108,7 +3108,7 @@ aiNodeAnim* FBXConverter::GenerateSimpleNodeAnim(const std::string& name,
InterpolateKeys(outRotations, keytimes, keyframeLists[TransformationComp_Rotation], defRotation, maxTime, minTime, rotOrder); InterpolateKeys(outRotations, keytimes, keyframeLists[TransformationComp_Rotation], defRotation, maxTime, minTime, rotOrder);
} else { } else {
for (size_t i = 0; i < keyCount; ++i) { for (size_t i = 0; i < keyCount; ++i) {
outRotations[i].mTime = CONVERT_FBX_TIME(keytimes[i]) * anim_fps; outRotations[i].mTime = CONVERT_FBX_TIME(keytimes[i]);
outRotations[i].mValue = defQuat; outRotations[i].mValue = defQuat;
} }
} }
@ -3117,7 +3117,7 @@ aiNodeAnim* FBXConverter::GenerateSimpleNodeAnim(const std::string& name,
InterpolateKeys(outScales, keytimes, keyframeLists[TransformationComp_Scaling], defScale, maxTime, minTime); InterpolateKeys(outScales, keytimes, keyframeLists[TransformationComp_Scaling], defScale, maxTime, minTime);
} else { } else {
for (size_t i = 0; i < keyCount; ++i) { for (size_t i = 0; i < keyCount; ++i) {
outScales[i].mTime = CONVERT_FBX_TIME(keytimes[i]) * anim_fps; outScales[i].mTime = CONVERT_FBX_TIME(keytimes[i]);
outScales[i].mValue = defScale; outScales[i].mValue = defScale;
} }
} }
@ -3306,7 +3306,7 @@ void FBXConverter::InterpolateKeys(aiVectorKey *valOut, const KeyTimeList &keys,
} }
// magic value to convert fbx times to seconds // magic value to convert fbx times to seconds
valOut->mTime = CONVERT_FBX_TIME(time) * anim_fps; valOut->mTime = CONVERT_FBX_TIME(time);
min_time = std::min(min_time, valOut->mTime); min_time = std::min(min_time, valOut->mTime);
max_time = std::max(max_time, valOut->mTime); max_time = std::max(max_time, valOut->mTime);

View File

@ -243,6 +243,45 @@ void SortByPTypeProcess::Execute(aiScene *pScene) {
} }
} }
if (mesh->mNumAnimMeshes > 0 && mesh->mAnimMeshes) {
out->mNumAnimMeshes = mesh->mNumAnimMeshes;
out->mAnimMeshes = new aiAnimMesh *[out->mNumAnimMeshes];
}
for (unsigned int j = 0; j < mesh->mNumAnimMeshes; ++j) {
aiAnimMesh *animMesh = mesh->mAnimMeshes[j];
aiAnimMesh *outAnimMesh = out->mAnimMeshes[j] = new aiAnimMesh;
outAnimMesh->mNumVertices = out->mNumVertices;
if (animMesh->mVertices)
outAnimMesh->mVertices = new aiVector3D[out->mNumVertices];
else
outAnimMesh->mVertices = nullptr;
if (animMesh->mNormals)
outAnimMesh->mNormals = new aiVector3D[out->mNumVertices];
else
outAnimMesh->mNormals = nullptr;
if (animMesh->mTangents)
outAnimMesh->mTangents = new aiVector3D[out->mNumVertices];
else
outAnimMesh->mTangents = nullptr;
if (animMesh->mBitangents)
outAnimMesh->mBitangents = new aiVector3D[out->mNumVertices];
else
outAnimMesh->mBitangents = nullptr;
for (int jj = 0; jj < AI_MAX_NUMBER_OF_COLOR_SETS; ++jj) {
if (animMesh->mColors[jj])
outAnimMesh->mColors[jj] = new aiColor4D[out->mNumVertices];
else
outAnimMesh->mColors[jj] = nullptr;
}
for (int jj = 0; jj < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++jj) {
if (animMesh->mTextureCoords[jj])
outAnimMesh->mTextureCoords[jj] = new aiVector3D[out->mNumVertices];
else
outAnimMesh->mTextureCoords[jj] = nullptr;
}
}
typedef std::vector<aiVertexWeight> TempBoneInfo; typedef std::vector<aiVertexWeight> TempBoneInfo;
std::vector<TempBoneInfo> tempBones(mesh->mNumBones); std::vector<TempBoneInfo> tempBones(mesh->mNumBones);
@ -252,6 +291,7 @@ void SortByPTypeProcess::Execute(aiScene *pScene) {
} }
unsigned int outIdx = 0; unsigned int outIdx = 0;
unsigned int amIdx = 0; // AnimMesh index
for (unsigned int m = 0; m < mesh->mNumFaces; ++m) { for (unsigned int m = 0; m < mesh->mNumFaces; ++m) {
aiFace &in = mesh->mFaces[m]; aiFace &in = mesh->mFaces[m];
if ((real == 3 && in.mNumIndices <= 3) || (real != 3 && in.mNumIndices != real + 1)) { if ((real == 3 && in.mNumIndices <= 3) || (real != 3 && in.mNumIndices != real + 1)) {
@ -293,6 +333,30 @@ void SortByPTypeProcess::Execute(aiScene *pScene) {
*cols[pp]++ = mesh->mColors[pp][idx]; *cols[pp]++ = mesh->mColors[pp][idx];
} }
unsigned int pp = 0;
for (; pp < mesh->mNumAnimMeshes; ++pp) {
aiAnimMesh *animMesh = mesh->mAnimMeshes[pp];
aiAnimMesh *outAnimMesh = out->mAnimMeshes[pp];
if (animMesh->mVertices)
outAnimMesh->mVertices[amIdx] = animMesh->mVertices[idx];
if (animMesh->mNormals)
outAnimMesh->mNormals[amIdx] = animMesh->mNormals[idx];
if (animMesh->mTangents)
outAnimMesh->mTangents[amIdx] = animMesh->mTangents[idx];
if (animMesh->mBitangents)
outAnimMesh->mBitangents[amIdx] = animMesh->mBitangents[idx];
for (int jj = 0; jj < AI_MAX_NUMBER_OF_COLOR_SETS; ++jj) {
if (animMesh->mColors[jj])
outAnimMesh->mColors[jj][amIdx] = animMesh->mColors[jj][idx];
}
for (int jj = 0; jj < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++jj) {
if (animMesh->mTextureCoords[jj])
outAnimMesh->mTextureCoords[jj][amIdx] = animMesh->mTextureCoords[jj][idx];
}
}
if (pp == mesh->mNumAnimMeshes)
amIdx++;
in.mIndices[q] = outIdx++; in.mIndices[q] = outIdx++;
} }