extra fixes

Torque sees the seqEnd in appSequence as a time in seconds whereas in Assimp this is in frames.
This is then converted to frames in generateSequences.
This commit is contained in:
marauder2k7 2024-02-10 20:01:52 +00:00
parent e2550ed525
commit 05960e4d25
4 changed files with 171 additions and 94 deletions

View file

@ -14,30 +14,75 @@
AssimpAppSequence::AssimpAppSequence(aiAnimation *a) :
seqStart(0.0f),
mAnim(a)
seqEnd(0.0f)
{
mAnim = new aiAnimation(*a);
// Deep copy channels
mAnim->mChannels = new aiNodeAnim * [a->mNumChannels];
for (U32 i = 0; i < a->mNumChannels; ++i) {
mAnim->mChannels[i] = new aiNodeAnim(*a->mChannels[i]);
}
// Deep copy meshes
mAnim->mMeshChannels = new aiMeshAnim * [a->mNumMeshChannels];
for (U32 i = 0; i < a->mNumMeshChannels; ++i) {
mAnim->mMeshChannels[i] = new aiMeshAnim(*a->mMeshChannels[i]);
}
// Deep copy name
mAnim->mName = a->mName;
mSequenceName = mAnim->mName.C_Str();
if (mSequenceName.isEmpty())
mSequenceName = "ambient";
Con::printf("\n[Assimp] Adding %s animation", mSequenceName.c_str());
fps = (mAnim->mTicksPerSecond > 0) ? mAnim->mTicksPerSecond : 30.0f;
fps = (a->mTicksPerSecond > 0) ? a->mTicksPerSecond : 30.0f;
U32 maxKeys = 0;
F32 maxEndTime = 0;
F32 minFrameTime = 100000.0f;
// Detect the frame rate (minimum time between keyframes) and max sequence time
for (U32 i = 0; i < mAnim->mNumChannels; ++i)
if (a->mDuration > 0)
{
aiNodeAnim *nodeAnim = mAnim->mChannels[i];
maxKeys = getMax(maxKeys, nodeAnim->mNumPositionKeys);
maxKeys = getMax(maxKeys, nodeAnim->mNumRotationKeys);
maxKeys = getMax(maxKeys, nodeAnim->mNumScalingKeys);
// torques seqEnd is in seconds, this then gets generated into frames in generateSequences()
seqEnd = (F32)a->mDuration / fps;
}
else
{
for (U32 i = 0; i < a->mNumChannels; ++i)
{
aiNodeAnim* nodeAnim = a->mChannels[i];
// Determine the maximum keyframe time for this animation
F32 maxKeyTime = 0.0f;
for (U32 k = 0; k < nodeAnim->mNumPositionKeys; k++) {
maxKeyTime = getMax(maxKeyTime, (F32)nodeAnim->mPositionKeys[k].mTime);
}
for (U32 k = 0; k < nodeAnim->mNumRotationKeys; k++) {
maxKeyTime = getMax(maxKeyTime, (F32)nodeAnim->mRotationKeys[k].mTime);
}
for (U32 k = 0; k < nodeAnim->mNumScalingKeys; k++) {
maxKeyTime = getMax(maxKeyTime, (F32)nodeAnim->mScalingKeys[k].mTime);
}
maxEndTime = getMax(maxEndTime, (F32)maxKeys);
seqEnd = getMax(seqEnd, maxKeyTime);
}
}
seqEnd = maxEndTime;
mTimeMultiplier = 1.0f;
//S32 timeFactor = ColladaUtils::getOptions().animTiming;
//S32 fpsRequest = (S32)a->mTicksPerSecond;
//if (timeFactor == 0)
//{ // Timing specified in frames
// fps = mClamp(fpsRequest, 5 /*TSShapeLoader::MinFrameRate*/, TSShapeLoader::MaxFrameRate);
// mTimeMultiplier = 1.0f / fps;
//}
//else
//{ // Timing specified in seconds or ms depending on format
// if (seqEnd > 1000.0f || a->mDuration > 1000.0f)
// timeFactor = 1000.0f; // If it's more than 1000 seconds, assume it's ms.
// timeFactor = mClamp(timeFactor, 1, 1000);
// mTimeMultiplier = 1.0f / timeFactor;
//}
}