further assimp fixes

AppMesh position was being scaled twice since the node is now being scaled
Try and resolve fps from file instead of default 30
maxKeyTime should be outside the loop
This commit is contained in:
marauder2k7 2025-11-25 08:32:34 +00:00
parent a5ed09fa57
commit f817d7d903
4 changed files with 26 additions and 13 deletions

View file

@ -226,7 +226,6 @@ void AssimpAppMesh::lockMesh(F32 t, const MatrixF& objOffset)
bonePos /= scaleMult;
}
bonePos *= ColladaUtils::getOptions().unit * ColladaUtils::getOptions().formatScaleFactor;
boneTransform.setPosition(bonePos);
initialTransforms.push_back(boneTransform);

View file

@ -178,12 +178,16 @@ Point3F AssimpAppNode::interpolateVectorKey(const aiVectorKey* keys, U32 numKeys
{
if (frameTime < keys[i].mTime)
{
Assimp::Interpolator<aiVectorKey> interp;
const aiVectorKey& next = keys[i];
const aiVectorKey& prev = keys[i - 1];
const F32 factor = (frameTime - keys[i - 1].mTime) / (keys[i].mTime - keys[i - 1].mTime);
Point3F start(keys[i - 1].mValue.x, keys[i - 1].mValue.y, keys[i - 1].mValue.z);
Point3F end(keys[i].mValue.x, keys[i].mValue.y, keys[i].mValue.z);
Point3F result;
result.interpolate(start, end, factor);
return result;
aiVector3D out;
interp(out, prev, next, factor);
return Point3F(out.x, out.y, out.z);
}
}
@ -196,6 +200,16 @@ QuatF AssimpAppNode::interpolateQuaternionKey(const aiQuatKey* keys, U32 numKeys
if (numKeys == 1) // Single keyframe: use it directly
return QuatF(keys[0].mValue.x, keys[0].mValue.y, keys[0].mValue.z, keys[0].mValue.w);
// Clamp frameTime to the bounds of the keyframes
if (frameTime <= keys[0].mTime) {
// Before the first keyframe, return the first key
return QuatF(keys[0].mValue.x, keys[0].mValue.y, keys[0].mValue.z, keys[0].mValue.w);
}
if (frameTime >= keys[numKeys - 1].mTime) {
// After the last keyframe, return the last key
return QuatF(keys[numKeys - 1].mValue.x, keys[numKeys - 1].mValue.y, keys[numKeys - 1].mValue.z, keys[numKeys - 1].mValue.w);
}
for (U32 i = 1; i < numKeys; ++i)
{
if (frameTime < keys[i].mTime)

View file

@ -15,7 +15,7 @@
AssimpAppSequence::AssimpAppSequence(aiAnimation* a)
: seqStart(0.0f), seqEnd(0.0f), mTimeMultiplier(1.0f)
{
fps = 30.0f;
fps = ColladaUtils::getOptions().animFPS;
// Deep copy animation structure
mAnim = new aiAnimation(*a);
mAnim->mChannels = new aiNodeAnim * [a->mNumChannels];

View file

@ -279,7 +279,6 @@ void AssimpShapeLoader::enumerateScene()
detectDetails();
aiNode* root = mScene->mRootNode;
for (S32 iNode = 0; iNode < root->mNumChildren; iNode++)
{
aiNode* child = root->mChildren[iNode];
@ -352,6 +351,10 @@ void AssimpShapeLoader::configureImportUnits() {
{
opts.unit = (F32)unit;
}
F32 fps;
getMetaFloat("CustomFrameRate", fps);
opts.animFPS = fps;
}
}
@ -388,21 +391,18 @@ void AssimpShapeLoader::processAnimations()
Vector<aiNodeAnim*> ambientChannels;
F32 duration = 0.0f;
F32 ticks = 0.0f;
F32 maxKeyTime = 0.0f;
if (mScene->mNumAnimations > 0)
{
for (U32 i = 0; i < mScene->mNumAnimations; ++i)
{
aiAnimation* anim = mScene->mAnimations[i];
ticks = anim->mTicksPerSecond;
duration = 0.0f;
for (U32 j = 0; j < anim->mNumChannels; j++)
{
aiNodeAnim* nodeAnim = anim->mChannels[j];
// 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);
}
@ -422,7 +422,7 @@ void AssimpShapeLoader::processAnimations()
ambientSeq->mNumChannels = ambientChannels.size();
ambientSeq->mChannels = ambientChannels.address();
ambientSeq->mDuration = duration;
ambientSeq->mTicksPerSecond = ticks;
ambientSeq->mTicksPerSecond = ColladaUtils::getOptions().animFPS;
AssimpAppSequence* defaultAssimpSeq = new AssimpAppSequence(ambientSeq);
appSequences.push_back(defaultAssimpSeq);