Exemplo n.º 1
0
void Animation::UpdateFrameTfs(int frameNum)
{
    /*
    printf("There are %d Rot %d Loc %d Scal Keys\n", 
	   pAnim->mChannels[0]->mNumRotationKeys,
	   pAnim->mChannels[0]->mNumPositionKeys,
	   pAnim->mChannels[0]->mNumScalingKeys);
    */
  
  // Recursively update the transform;
  ReadNodeHeirarchy(frameNum, pRootNode, glm::mat4(1.0f));
}
Exemplo n.º 2
0
void Mesh::BoneTransform(float TimeInSeconds, vector<Matrix4f>& Transforms)
{
    Matrix4f Identity;
    Identity.InitIdentity();
    
    float TicksPerSecond = (float)(m_pScene->mAnimations[0]->mTicksPerSecond != 0 ? m_pScene->mAnimations[0]->mTicksPerSecond : 25.0f);
    float TimeInTicks = TimeInSeconds * TicksPerSecond;
    float AnimationTime = fmod(TimeInTicks, (float)m_pScene->mAnimations[0]->mDuration);

    ReadNodeHeirarchy(AnimationTime, m_pScene->mRootNode, Identity);

    Transforms.resize(m_NumBones);

    for (uint i = 0 ; i < m_NumBones ; i++) {
        Transforms[i] = m_BoneInfo[i].FinalTransformation;
    }
}
Exemplo n.º 3
0
void Mesh::ReadNodeHeirarchy(float AnimationTime, const aiNode* pNode, const Matrix4f& ParentTransform)
{    
    string NodeName(pNode->mName.data);
    
    const aiAnimation* pAnimation = m_pScene->mAnimations[0];
        
    Matrix4f NodeTransformation(pNode->mTransformation);
     
    const aiNodeAnim* pNodeAnim = FindNodeAnim(pAnimation, NodeName);
    
    if (pNodeAnim) {
        // Interpolate scaling and generate scaling transformation matrix
        aiVector3D Scaling;
        CalcInterpolatedScaling(Scaling, AnimationTime, pNodeAnim);
        Matrix4f ScalingM;
        ScalingM.InitScaleTransform(Scaling.x, Scaling.y, Scaling.z);
        
        // Interpolate rotation and generate rotation transformation matrix
        aiQuaternion RotationQ;
        CalcInterpolatedRotation(RotationQ, AnimationTime, pNodeAnim);        
        Matrix4f RotationM = Matrix4f(RotationQ.GetMatrix());

        // Interpolate translation and generate translation transformation matrix
        aiVector3D Translation;
        CalcInterpolatedPosition(Translation, AnimationTime, pNodeAnim);
        Matrix4f TranslationM;
        TranslationM.InitTranslationTransform(Translation.x, Translation.y, Translation.z);
        
        // Combine the above transformations
        NodeTransformation = TranslationM * RotationM * ScalingM;
    }
       
    Matrix4f GlobalTransformation = ParentTransform * NodeTransformation;
    
    if (m_BoneMapping.find(NodeName) != m_BoneMapping.end()) {
        uint BoneIndex = m_BoneMapping[NodeName];
        m_BoneInfo[BoneIndex].FinalTransformation = m_GlobalInverseTransform * GlobalTransformation * m_BoneInfo[BoneIndex].BoneOffset;
    }
    
    for (uint i = 0 ; i < pNode->mNumChildren ; i++) {
        ReadNodeHeirarchy(AnimationTime, pNode->mChildren[i], GlobalTransformation);
    }
}
Exemplo n.º 4
0
void Animation::
ReadNodeHeirarchy(int frameIdx, 
		  const aiNode* pNode, 
		  const glm::mat4& parTf)
{
  std::string nodeName(pNode->mName.data);
  if (mBoneIdx.find(nodeName) == mBoneIdx.end())
    return;
  
  uint32 boneIdx = mBoneIdx[nodeName];
  
  const aiNodeAnim* pAnim = mBoneAnim[boneIdx];
  aiVectorKey& sc= pAnim->mScalingKeys[frameIdx % pAnim->mNumScalingKeys];
  aiMatrix4x4 matScale;
  aiMatrix4x4::Scaling(sc.mValue, matScale);
  
  aiQuatKey& qt = pAnim->mRotationKeys[frameIdx % pAnim->mNumRotationKeys];
  aiMatrix4x4 matRotat(qt.mValue.GetMatrix());
  
  aiVectorKey& tr = pAnim->mPositionKeys[frameIdx % pAnim->mNumPositionKeys];
  aiMatrix4x4 matTrans;
  aiMatrix4x4::Translation(tr.mValue, matTrans);

  // Convert from aiMatrix4x4 to glm::mat4
  glm::mat4 nodeTf;
  CopyMat(matTrans * matRotat * matScale, nodeTf);

  glm::mat4 globalTf= parTf * nodeTf;
  
  glm::mat4 finalTf = globalTf * mBoneOffsets[boneIdx];
  mBoneFinalTf[boneIdx] = finalTf;
  
  // Print out info
  //    cout << nodeName << endl;
  //    pprintMat4x4(finalTf);
  // pprintScQtTr(sc.mValue, qt.mValue, tr.mValue);
  //    pprintMat16(nodeTf);
  
  for(uint i=0; i< pNode->mNumChildren; ++i)
    ReadNodeHeirarchy(frameIdx, pNode->mChildren[i], globalTf);
}