mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-03-24 22:59:24 +00:00
Adds animated node transforms for animation importing.
Fixes sequence timing variables.
This commit is contained in:
parent
bd486bab66
commit
17a2e416ed
4 changed files with 187 additions and 17 deletions
|
|
@ -10,29 +10,72 @@
|
|||
#include "console/persistenceManager.h"
|
||||
#include "ts/assimp/assimpAppMaterial.h"
|
||||
#include "ts/assimp/assimpAppSequence.h"
|
||||
#include "ts/assimp/assimpAppNode.h"
|
||||
|
||||
AssimpAppSequence::AssimpAppSequence(aiAnimation *a) :
|
||||
seqStart(0.0f),
|
||||
mAnim(a)
|
||||
{
|
||||
fps = mAnim->mTicksPerSecond;
|
||||
// From: http://sir-kimmi.de/assimp/lib_html/data.html#anims
|
||||
// An aiAnimation has a duration. The duration as well as all time stamps are given in ticks.
|
||||
// To get the correct timing, all time stamp thus have to be divided by aiAnimation::mTicksPerSecond.
|
||||
// Beware, though, that certain combinations of file format and exporter don't always store this
|
||||
// information in the exported file. In this case, mTicksPerSecond is set to 0 to indicate the lack of knowledge.
|
||||
fps = (mAnim->mTicksPerSecond > 0) ? mAnim->mTicksPerSecond : 30.0f;
|
||||
|
||||
F32 maxEndTime = 0;
|
||||
F32 minFrameTime = 1000.0f;
|
||||
// Detect the frame rate (minimum time between keyframes) and max sequence time
|
||||
for (U32 i = 0; i < mAnim->mNumChannels; ++i)
|
||||
{
|
||||
aiNodeAnim *nodeAnim = mAnim->mChannels[i];
|
||||
if (nodeAnim->mNumPositionKeys)
|
||||
maxEndTime = getMax(maxEndTime, (F32) nodeAnim->mPositionKeys[nodeAnim->mNumPositionKeys-1].mTime);
|
||||
if (nodeAnim->mNumRotationKeys)
|
||||
maxEndTime = getMax(maxEndTime, (F32) nodeAnim->mRotationKeys[nodeAnim->mNumRotationKeys-1].mTime);
|
||||
if (nodeAnim->mNumScalingKeys)
|
||||
maxEndTime = getMax(maxEndTime, (F32) nodeAnim->mScalingKeys[nodeAnim->mNumScalingKeys-1].mTime);
|
||||
|
||||
for (U32 key = 1; key < nodeAnim->mNumPositionKeys; ++key)
|
||||
{
|
||||
F32 deltaT = nodeAnim->mPositionKeys[key].mTime - nodeAnim->mPositionKeys[key-1].mTime;
|
||||
minFrameTime = getMin(minFrameTime, deltaT);
|
||||
}
|
||||
for (U32 key = 1; key < nodeAnim->mNumRotationKeys; ++key)
|
||||
{
|
||||
F32 deltaT = nodeAnim->mRotationKeys[key].mTime - nodeAnim->mRotationKeys[key-1].mTime;
|
||||
minFrameTime = getMin(minFrameTime, deltaT);
|
||||
}
|
||||
for (U32 key = 1; key < nodeAnim->mNumScalingKeys; ++key)
|
||||
{
|
||||
F32 deltaT = nodeAnim->mScalingKeys[key].mTime - nodeAnim->mScalingKeys[key-1].mTime;
|
||||
minFrameTime = getMin(minFrameTime, deltaT);
|
||||
}
|
||||
}
|
||||
|
||||
fps = (minFrameTime > 0.0f) ? 1.0f / minFrameTime : fps;
|
||||
fps = mClamp(fps, TSShapeLoader::MinFrameRate, TSShapeLoader::MaxFrameRate);
|
||||
seqEnd = maxEndTime;
|
||||
}
|
||||
|
||||
AssimpAppSequence::~AssimpAppSequence()
|
||||
{
|
||||
}
|
||||
|
||||
F32 AssimpAppSequence::getStart() const
|
||||
{
|
||||
return 0.0f;
|
||||
}
|
||||
F32 AssimpAppSequence::getEnd() const
|
||||
{
|
||||
return (F32)mAnim->mDuration / fps;
|
||||
void AssimpAppSequence::setActive(bool active)
|
||||
{
|
||||
if (active)
|
||||
AssimpAppNode::sActiveSequence = mAnim;
|
||||
else
|
||||
{
|
||||
if (AssimpAppNode::sActiveSequence == mAnim)
|
||||
AssimpAppNode::sActiveSequence = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
U32 AssimpAppSequence::getFlags() const
|
||||
{
|
||||
return TSShape::Blend;
|
||||
return TSShape::Blend;
|
||||
}
|
||||
F32 AssimpAppSequence::getPriority() const
|
||||
{
|
||||
|
|
@ -41,5 +84,4 @@ F32 AssimpAppSequence::getPriority() const
|
|||
F32 AssimpAppSequence::getBlendRefTime() const
|
||||
{
|
||||
return -1.0f;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue