Community
// Evaluate the node at the given time
KTime kTime;
kTime.SetSecondDouble(Time);
FbxAMatrix Transform = m_pFBXNode->EvaluateLocalTransform(kTime);
FbxVector4 Translation = Transform.GetT();
FbxQuaternion QuatRotation = Transform.GetQ();
FbxVector4 Scale = Transform.GetS();
// Make the values relative to time of 0
kTime.SetSecondDouble(0);
FbxAMatrix Frame0Transform = m_pFBXNode->EvaluateLocalTransform(kTime);
FbxVector4 Frame0Translation = Frame0Transform.GetT();
FbxQuaternion Frame0QuatRotation = Frame0Transform.GetQ();
FbxVector4 Frame0Scale = Frame0Transform.GetS();
FbxAMatrix InverseFrame0Transform = Frame0Transform.Inverse();
FbxAMatrix RelativeTransform = InverseFrame0Transform * Transform;
Translation = RelativeTransform.GetT();
QuatRotation = RelativeTransform.GetQ();
Scale = Transform.GetS() - Frame0Scale;
// Transform the translation by the inverse of the rotation
// This might be the correct thing to do, or it might not
/*
FbxMatrix inverseRotationMatrix;
inverseRotationMatrix.SetTQS(FbxVector4(0, 0, 0, 1), QuatRotation, FbxVector4(1, 1, 1, 1));
//inverseRotationMatrix = inverseRotationMatrix.Inverse();
Translation = inverseRotationMatrix.MultNormalize(Translation);
*/
Keyframe = (float)Translation;
Keyframe = (float)Translation;
Keyframe = (float)Translation;
Keyframe = (float)QuatRotation;
Keyframe = (float)QuatRotation;
Keyframe = (float)QuatRotation;
Keyframe = (float)QuatRotation;
Keyframe = (float)Scale;
Keyframe = (float)Scale;
Keyframe = (float)Scale;
// Get the base transformation
// This is from the node's original position / rotation
m_Position = m_pModelNode->GetPosition();
m_Rotation = m_pModelNode->GetRotation();
m_Scale = m_pModelNode->GetScale();
// Blend in any timelines
// Timelines store the relative local transformation
for(std::map<int, TimelineInstancePtr>::iterator currentTimeline = m_TimelineInstances.begin(); currentTimeline != m_TimelineInstances.end(); ++currentTimeline)
{
// Update the timeline
TimelineInstancePtr instance = currentTimeline->second;
instance->Update(DeltaTime);
// Get the weight of the timeline
// Weights are 0 - 1, and are used to make the animation additive
float32 timelineWeight = m_TimelineInstanceWeights;
//Retrieve the keyframe values
m_Position += timelineWeight * Vector3(instance->GetCurrentValues(), instance->GetCurrentValues(), instance->GetCurrentValues());
m_Scale += timelineWeight * Vector3(instance->GetCurrentValues(), instance->GetCurrentValues(), instance->GetCurrentValues());
// Blend the quaternion rotation
Quaternion unitQuaternion(0, 0, 0, 1);
Quaternion newRotation = Quaternion::Slerp(unitQuaternion, Quaternion(instance->GetCurrentValues(), instance->GetCurrentValues(), instance->GetCurrentValues(), instance->GetCurrentValues()), timelineWeight);
m_Rotation = m_Rotation * newRotation;
}
// Construct the total matrix
m_TransformMatrix = ParentTransform * (Matrix4x4::Translation(m_Position)) * m_Rotation.ToMatrix4x4() * Matrix4x4::Scaling(m_Scale);
translation = relativeTransform.GetT();
translation = 1.0f;
quatRotation = relativeTransform.GetQ();
// Transform the translation by the inverse of the rotation
FbxMatrix rotationMatrix;
rotationMatrix.SetTQS(FbxVector4(0, 0, 0, 1), quatRotation, FbxVector4(1, 1, 1, 1));
translation = rotationMatrix.MultNormalize(translation);
// Evaluate the node at the given time
KTime kTime;
kTime.SetSecondDouble(Time);
FbxAMatrix Transform = m_pFBXNode->EvaluateLocalTransform(kTime);
FbxVector4 Translation = Transform.GetT();
FbxQuaternion QuatRotation = Transform.GetQ();
FbxVector4 Scale = Transform.GetS();
// Make the values relative to time of 0
kTime.SetSecondDouble(0);
FbxAMatrix Frame0Transform = m_pFBXNode->EvaluateLocalTransform(kTime);
FbxVector4 Frame0Translation = Frame0Transform.GetT();
FbxQuaternion Frame0QuatRotation = Frame0Transform.GetQ();
FbxVector4 Frame0Scale = Frame0Transform.GetS();
Scale = Scale - Frame0Scale;
Translation = Translation - Frame0Translation;
Transform.SetT(FbxVector4(0, 0, 0, 1));
Frame0Transform.SetT(FbxVector4(0, 0, 0, 1));
FbxAMatrix InverseFrame0Transform = Frame0Transform.Inverse();
FbxAMatrix RelativeTransform = InverseFrame0Transform * Transform;
QuatRotation = RelativeTransform.GetQ();
Can't find what you're looking for? Ask the community or share your knowledge.