Beispiel #1
0
NodeAnimPtr AnimationModule::getNearestTimeNodeFromOutputsInternal(const NodePtr& node) const
{
    std::list<NodePtr> markedNodes;
    NodeCollectionPtr collection = node->getGroup();
    NodePtr timeNode = _imp->getNearestTimeNodeFromOutputs_recursive(node, collection, markedNodes);
    return findNodeAnim(timeNode);
}
Beispiel #2
0
std::vector<NodeAnimPtr > AnimationModule::getChildrenNodes(const NodeAnimPtr& node) const
{
    std::vector<NodeAnimPtr > children;
    AnimatedItemTypeEnum nodeType = node->getItemType();
    if (nodeType == eAnimatedItemTypeGroup) {

        // If the node is a group, make all its children to be a child in the tree view
        NodeGroupPtr nodeGroup = node->getInternalNode()->isEffectNodeGroup();
        assert(nodeGroup);

        NodesList nodes = nodeGroup->getNodes();
        for (NodesList::const_iterator it = nodes.begin(); it != nodes.end(); ++it) {
            NodePtr childNode = (*it);
            NodeAnimPtr isInDopeSheet = findNodeAnim( childNode );
            if (isInDopeSheet) {
                children.push_back(isInDopeSheet);
            }
        }

    } else if ( node->isTimeNode() ) {
        // If the node is a time node, all input nodes recursively are considered to be a child
        std::list<NodePtr> markedNodes;
        _imp->getInputs_recursive(node->getInternalNode(), markedNodes, &children);
    }

    return children;
}
Beispiel #3
0
void Loader::loadAnimation(const aiNode *pNode,int index,CMC_AnimateData * animate)
{
    std::string NodeName(pNode->mName.data);
    if(!m_pScene->HasAnimations ())
    {
        m_model->m_hasAnimation = false;
        return ;
    }
    const aiAnimation* pAnimation = m_pScene->mAnimations[index];
    const aiNodeAnim * pNodeAnim = findNodeAnim(pAnimation, NodeName);
    if(pNodeAnim)//that node is a animation bone.
    {
        auto animateBone = new CMC_AnimateBone();
        animateBone->m_boneName = NodeName;
        //load position key.
        for(int i =0;i<pNodeAnim->mNumPositionKeys;i++)
        {
            auto v = pNodeAnim->mPositionKeys[i];
            CMC_TranslateKey key;
            key.time = v.mTime;
            key.trans = QVector3D (v.mValue.x,v.mValue.y,v.mValue.z);
            animateBone->addTranslate (key);
        }
        //load scale key
        for(int i =0;i<pNodeAnim->mNumScalingKeys;i++)
        {
            auto v = pNodeAnim->mScalingKeys[i];
            CMC_ScaleKey key;
            key.time = v.mTime;
            key.scale = QVector3D (v.mValue.x,v.mValue.y,v.mValue.z);
            animateBone->addScale (key);
        }
        //load rotation key
        for(int i =0;i<pNodeAnim->mNumPositionKeys;i++)
        {
            auto v = pNodeAnim->mRotationKeys[i];
            CMC_RotateKey key;
            key.time = v.mTime;
            key.rotate = QQuaternion(v.mValue.w,v.mValue.x,v.mValue.y,v.mValue.z);
            animateBone->addRotate (key);
        }

        animate->addAnimateBone (animateBone);
        animate->m_ticksPerSecond = pAnimation->mTicksPerSecond;
        animate->m_duration = pAnimation->mDuration;
    }
    for (uint i = 0 ; i < pNode->mNumChildren ; i++) {
        loadAnimation( pNode->mChildren[i],index,animate);
    }
}
Beispiel #4
0
NodeAnimPtr AnimationModule::getGroupNodeAnim(const NodeAnimPtr& node) const
{
    NodePtr internalNode = node->getInternalNode();
    if (!internalNode) {
        return NodeAnimPtr();
    }
    NodeGroupPtr parentGroup = toNodeGroup( internalNode->getGroup() );
    NodeAnimPtr parentGroupNodeAnim;

    if (parentGroup) {
        parentGroupNodeAnim = findNodeAnim( parentGroup->getNode() );
    }

    return parentGroupNodeAnim;
}
Beispiel #5
0
void Mesh::recurseNodeHeirarchy(float _animationTime, const aiNode* _node, const ngl::Mat4& _parentTransform)
{
  std::string name(_node->mName.data);

  const aiAnimation* animation = m_scene->mAnimations[0];

  ngl::Mat4 nodeTransform=AIU::aiMatrix4x4ToNGLMat4(_node->mTransformation);

  const aiNodeAnim* nodeAnim = findNodeAnim(animation, name);

  if (nodeAnim)
  {
    // Interpolate scaling and generate scaling transformation matrix
    ngl::Vec3 scale=calcInterpolatedScaling(_animationTime, nodeAnim);
    ngl::Mat4 scaleMatrix;
    scaleMatrix.scale(scale.m_x, scale.m_y, scale.m_z);
    // Interpolate rotation and generate rotation transformation matrix
    ngl::Quaternion rotation=calcInterpolatedRotation( _animationTime, nodeAnim);
    ngl::Mat4 rotationMatrix = rotation.toMat4();

    // Interpolate translation and generate translation transformation matrix
    ngl::Vec3 translation=calcInterpolatedPosition(_animationTime, nodeAnim);
    // Combine the above transformations
    nodeTransform = rotationMatrix*scaleMatrix;
    nodeTransform.m_30=translation.m_x;
    nodeTransform.m_31=translation.m_y;
    nodeTransform.m_32=translation.m_z;
    nodeTransform.transpose();

  }


  ngl::Mat4 globalTransform = _parentTransform * nodeTransform;

  if (m_boneMapping.find(name) != m_boneMapping.end())
  {
    unsigned int boneIndex = m_boneMapping[name];
    m_boneInfo[boneIndex].finalTransformation = m_globalInverseTransform * globalTransform * m_boneInfo[boneIndex].boneOffset;
  }

  for (unsigned int i = 0 ; i < _node->mNumChildren ; ++i)
  {
    recurseNodeHeirarchy(_animationTime, _node->mChildren[i], globalTransform);
  }
}
Beispiel #6
0
NodeAnimPtr
AnimationModule::getNearestReaderInternal(const NodePtr& timeNode) const
{
    std::list<NodePtr> markedNodes;
    return findNodeAnim(_imp->getNearestReaderFromInputs_recursive(timeNode, markedNodes));
}