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

@ -122,100 +122,115 @@ MatrixF AssimpAppNode::getTransform(F32 time)
void AssimpAppNode::getAnimatedTransform(MatrixF& mat, F32 t, aiAnimation* animSeq)
{
// Find the channel for this node
for (U32 i = 0; i < animSeq->mNumChannels; ++i)
for (U32 k = 0; k < animSeq->mNumChannels; ++k)
{
if (strcmp(mName, animSeq->mChannels[i]->mNodeName.C_Str()) == 0)
if (dStrcmp(mName, animSeq->mChannels[k]->mNodeName.C_Str()) == 0)
{
aiNodeAnim *nodeAnim = animSeq->mChannels[i];
aiNodeAnim *nodeAnim = animSeq->mChannels[k];
Point3F trans(Point3F::Zero);
Point3F scale(Point3F::One);
QuatF rot;
rot.identity();
// T is in seconds, convert to frames.
F32 frame = t * animSeq->mTicksPerSecond;
// Transform
if (nodeAnim->mNumPositionKeys == 1)
trans.set(nodeAnim->mPositionKeys[0].mValue.x, nodeAnim->mPositionKeys[0].mValue.y, nodeAnim->mPositionKeys[0].mValue.z);
// interpolate scaling.
if (nodeAnim->mNumScalingKeys > 1) {
U32 scaleIndex = 0;
for (U32 i = 0; i < nodeAnim->mNumScalingKeys-1; i++)
{
if (frame < nodeAnim->mScalingKeys[i + 1].mTime) {
scaleIndex = i;
break;
}
}
const Point3F& scalingStart = Point3F( nodeAnim->mScalingKeys[scaleIndex].mValue.x,
nodeAnim->mScalingKeys[scaleIndex].mValue.y,
nodeAnim->mScalingKeys[scaleIndex].mValue.z);
const Point3F& scalingEnd = Point3F(nodeAnim->mScalingKeys[scaleIndex + 1].mValue.x,
nodeAnim->mScalingKeys[scaleIndex + 1].mValue.y,
nodeAnim->mScalingKeys[scaleIndex + 1].mValue.z);
F32 deltaTime = nodeAnim->mScalingKeys[scaleIndex + 1].mTime - nodeAnim->mScalingKeys[scaleIndex].mTime;
F32 factor = (frame - nodeAnim->mScalingKeys[scaleIndex].mTime) / deltaTime;
scale = scalingStart + factor * (scalingEnd - scalingStart);
}
else
{
Point3F curPos, lastPos;
F32 lastT = 0.0;
for (U32 key = 0; key < nodeAnim->mNumPositionKeys; ++key)
{
F32 curT = sTimeMultiplier * (F32)nodeAnim->mPositionKeys[key].mTime;
curPos.set(nodeAnim->mPositionKeys[key].mValue.x, nodeAnim->mPositionKeys[key].mValue.y, nodeAnim->mPositionKeys[key].mValue.z);
if ((curT > t) && (key > 0))
{
F32 factor = (t - lastT) / (curT - lastT);
trans.interpolate(lastPos, curPos, factor);
break;
}
else if ((curT >= t) || (key == nodeAnim->mNumPositionKeys - 1))
{
trans = curPos;
break;
}
lastT = curT;
lastPos = curPos;
}
scale.set( nodeAnim->mScalingKeys[0].mValue.x,
nodeAnim->mScalingKeys[0].mValue.y,
nodeAnim->mScalingKeys[0].mValue.z);
}
// Rotation
if (nodeAnim->mNumRotationKeys == 1)
rot.set(nodeAnim->mRotationKeys[0].mValue.x, nodeAnim->mRotationKeys[0].mValue.y,
nodeAnim->mRotationKeys[0].mValue.z, nodeAnim->mRotationKeys[0].mValue.w);
// interpolate rotation.
if (nodeAnim->mNumRotationKeys > 1) {
U32 rotationIndex = 0;
for (U32 i = 0; i < nodeAnim->mNumRotationKeys - 1; i++)
{
if (frame < nodeAnim->mRotationKeys[i + 1].mTime) {
rotationIndex = i;
break;
}
}
const QuatF& rotStart = QuatF(nodeAnim->mRotationKeys[rotationIndex].mValue.x,
nodeAnim->mRotationKeys[rotationIndex].mValue.y,
nodeAnim->mRotationKeys[rotationIndex].mValue.z,
nodeAnim->mRotationKeys[rotationIndex].mValue.w);
const QuatF& rotEnd = QuatF(nodeAnim->mRotationKeys[rotationIndex + 1].mValue.x,
nodeAnim->mRotationKeys[rotationIndex + 1].mValue.y,
nodeAnim->mRotationKeys[rotationIndex + 1].mValue.z,
nodeAnim->mRotationKeys[rotationIndex + 1].mValue.w);
F32 deltaTime = nodeAnim->mRotationKeys[rotationIndex + 1].mTime - nodeAnim->mRotationKeys[rotationIndex].mTime;
F32 factor = (frame - nodeAnim->mRotationKeys[rotationIndex].mTime) / deltaTime;
rot.interpolate(rotStart, rotEnd, factor);
}
else
{
QuatF curRot, lastRot;
F32 lastT = 0.0;
for (U32 key = 0; key < nodeAnim->mNumRotationKeys; ++key)
{
F32 curT = sTimeMultiplier * (F32)nodeAnim->mRotationKeys[key].mTime;
curRot.set(nodeAnim->mRotationKeys[key].mValue.x, nodeAnim->mRotationKeys[key].mValue.y,
nodeAnim->mRotationKeys[key].mValue.z, nodeAnim->mRotationKeys[key].mValue.w);
if ((curT > t) && (key > 0))
{
F32 factor = (t - lastT) / (curT - lastT);
rot.interpolate(lastRot, curRot, factor);
break;
}
else if ((curT >= t) || (key == nodeAnim->mNumRotationKeys - 1))
{
rot = curRot;
break;
}
lastT = curT;
lastRot = curRot;
}
rot.set( nodeAnim->mRotationKeys[0].mValue.x,
nodeAnim->mRotationKeys[0].mValue.y,
nodeAnim->mRotationKeys[0].mValue.z,
nodeAnim->mRotationKeys[0].mValue.w);
}
// Scale
if (nodeAnim->mNumScalingKeys == 1)
scale.set(nodeAnim->mScalingKeys[0].mValue.x, nodeAnim->mScalingKeys[0].mValue.y, nodeAnim->mScalingKeys[0].mValue.z);
// interpolate position.
if (nodeAnim->mNumPositionKeys > 1) {
U32 posIndex = 0;
for (U32 i = 0; i < nodeAnim->mNumPositionKeys - 1; i++)
{
if (frame < nodeAnim->mPositionKeys[i + 1].mTime) {
posIndex = i;
break;
}
}
const Point3F& posStart = Point3F( nodeAnim->mPositionKeys[posIndex].mValue.x,
nodeAnim->mPositionKeys[posIndex].mValue.y,
nodeAnim->mPositionKeys[posIndex].mValue.z);
const Point3F& posEnd = Point3F(nodeAnim->mPositionKeys[posIndex + 1].mValue.x,
nodeAnim->mPositionKeys[posIndex + 1].mValue.y,
nodeAnim->mPositionKeys[posIndex + 1].mValue.z);
F32 deltaTime = nodeAnim->mPositionKeys[posIndex + 1].mTime - nodeAnim->mPositionKeys[posIndex].mTime;
F32 factor = (frame - nodeAnim->mPositionKeys[posIndex].mTime) / deltaTime;
trans = posStart + factor * (posEnd - posStart);
}
else
{
Point3F curScale, lastScale;
F32 lastT = 0.0;
for (U32 key = 0; key < nodeAnim->mNumScalingKeys; ++key)
{
F32 curT = sTimeMultiplier * (F32)nodeAnim->mScalingKeys[key].mTime;
curScale.set(nodeAnim->mScalingKeys[key].mValue.x, nodeAnim->mScalingKeys[key].mValue.y, nodeAnim->mScalingKeys[key].mValue.z);
if ((curT > t) && (key > 0))
{
F32 factor = (t - lastT) / (curT - lastT);
scale.interpolate(lastScale, curScale, factor);
break;
}
else if ((curT >= t) || (key == nodeAnim->mNumScalingKeys - 1))
{
scale = curScale;
break;
}
lastT = curT;
lastScale = curScale;
}
trans.set( nodeAnim->mPositionKeys[0].mValue.x,
nodeAnim->mPositionKeys[0].mValue.y,
nodeAnim->mPositionKeys[0].mValue.z);
}
rot.setMatrix(&mat);