Esempio n. 1
0
void Mesh::ReadNodeHeirarchyCont(float AnimationTime, 
				 const aiNode* pNode, 
				 const glm::mat4& ParentTf,
				 unsigned int anim_index)
{
  std::string NodeName(pNode->mName.data);
  glm::mat4 NodeTf;
  CopyaiMat(pNode->mTransformation, NodeTf);

  // NOTE: the skeleton must use the same naming convention used by the .bvh files
  if(_b2i_map.find(NodeName) == _b2i_map.end())
    {
      printf("Node: %15s\n", NodeName.c_str());
      return;  // bone does not exist
    }
  //  const aiNodeAnim* pNodeAnim=FindNodeAnim(_pSceneMesh->mAnimations[anim_index],NodeName);
  const aiNodeAnim* pNodeAnim = _channels[anim_index][NodeName];

  if(pNodeAnim)
    {
      // Interpolate scaling and generate scaling transformation matrix
      aiVector3D sc;
      CalcInterpolatedScaling(sc, AnimationTime, pNodeAnim);
      glm::mat4 ScMat=glm::scale(glm::mat4(1.0f),
				 glm::vec3(sc.x, sc.y, sc.z));

      //     printf("Node name: %s: Sc: %f %f %f\n", NodeName.c_str(), sc.x, sc.y, sc.z);

      aiQuaternion quat;
      CalcInterpolatedRotation(quat, AnimationTime, pNodeAnim);
      glm::mat4 RotMat;
      CopyaiMat(aiMatrix4x4(quat.GetMatrix()), RotMat);
      
      aiVector3D tran;
      CalcInterpolatedPosition(tran, AnimationTime, pNodeAnim);
      glm::mat4 TranMat = glm::translate(glm::mat4(1.0f),
					 glm::vec3(tran.x, tran.y, tran.z));

      NodeTf = TranMat*RotMat*ScMat;
    }
  
  glm::mat4 GlobalTf = ParentTf * NodeTf;
  unsigned int BoneIdx = _b2i_map[NodeName];
  _boneTfs[BoneIdx].FinalTf= _globalInvTf * GlobalTf * _boneTfs[BoneIdx].Offset;

  for(unsigned int i=0; i< pNode->mNumChildren; i++)
    {
      ReadNodeHeirarchyCont(AnimationTime, pNode->mChildren[i], GlobalTf, anim_index);
    }
}
Esempio n. 2
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);
    }
}