Esempio n. 1
0
//==========================
// 再生するモーションの設定
//==========================
void cMotionPlayer::setup( cPMDModel *pPMDModel, cVMDMotion *pMotion, bool bLoop )
{
	clear();


	m_pPMDModel = pPMDModel;
	m_pVMDMotion = pMotion;

	//---------------------------------------------------------
	// 操作対象ボーンのポインタを設定する
	MotionDataList	*pMotionDataList = m_pVMDMotion->getMotionDataList();
	m_ppBoneList = new cPMDBone *[m_pVMDMotion->getNumMotionNodes()];
	cPMDBone		**ppBone = m_ppBoneList;
	while( pMotionDataList )
	{
		(*ppBone) = getBoneByName( pMotionDataList->szBoneName, pPMDModel->m_pBoneArray, pPMDModel->m_unNumBones );

		pMotionDataList = pMotionDataList->pNext;
		ppBone++;
	}

	//---------------------------------------------------------
	// 操作対象表情のポインタを設定する
	FaceDataList	*pFaceDataList = m_pVMDMotion->getFaceDataList();
	m_ppFaceList = new cPMDFace *[m_pVMDMotion->getNumFaceNodes()];
	cPMDFace		**ppFace = m_ppFaceList;
	while( pFaceDataList )
	{
		(*ppFace) = getFaceByName( pFaceDataList->szFaceName, pPMDModel->m_pFaceArray, pPMDModel->m_unNumFaces );

		pFaceDataList = pFaceDataList->pNext;
		ppFace++;
	}

	// 変数初期値設定
	m_fOldFrame = m_fFrame = 0.0f;
	m_bLoop = bLoop;
}
Esempio n. 2
0
//! called before the action start. It will also set the target.
void Animate3D::startWithTarget(Node *target)
{
    bool needReMap = (_target != target);
    ActionInterval::startWithTarget(target);
    
    if (needReMap)
    {
        _boneCurves.clear();
        _nodeCurves.clear();
        
        bool hasCurve = false;
        Sprite3D* sprite = dynamic_cast<Sprite3D*>(target);
        
        if(sprite)
        {
            if (_animation)
            {
                const std::unordered_map<std::string, Animation3D::Curve*>& boneCurves = _animation->getBoneCurves();
                for (const auto& iter: boneCurves)
                {
                    const std::string& boneName = iter.first;
                    auto skin = sprite->getSkeleton();
                    if(skin)
                    {
                        auto bone = skin->getBoneByName(boneName);
                        if (bone)
                        {
                            auto curve = _animation->getBoneCurveByName(boneName);
                            _boneCurves[bone] = curve;
                            hasCurve = true;
                        }
                        else
                        {
                            Node* node = nullptr;
                            if (target->getName() == boneName)
                                node = target;
                            else
                                node = findChildByNameRecursively(target, boneName);
                            
                            if (node)
                            {
                                auto curve = _animation->getBoneCurveByName(boneName);
                                if (curve)
                                {
                                    _nodeCurves[node] = curve;
                                    hasCurve = true;
                                }
                            }
                        }
                    }
                }
            }
        }
        else
        {
            const std::unordered_map<std::string, Animation3D::Curve*>& boneCurves = _animation->getBoneCurves();
            for (const auto& iter: boneCurves)
            {
                const std::string& boneName = iter.first;
                Node* node = nullptr;
                if (target->getName() == boneName)
                    node = target;
                else
                    node = findChildByNameRecursively(target, boneName);
                
                if (node)
                {
                    auto curve = _animation->getBoneCurveByName(boneName);
                    if (curve)
                    {
                        _nodeCurves[node] = curve;
                        hasCurve = true;
                    }
                }
                
            }
        }
        
        if (!hasCurve)
        {
            CCLOG("warning: no animation found for the skeleton");
        }
    }
    
    auto runningAction = s_runningAnimates.find(target);
    if (runningAction != s_runningAnimates.end())
    {
        //make the running action fade out
        auto action = (*runningAction).second;
        if (action != this)
        {
            if (_transTime < 0.001f)
            {
                s_runningAnimates[target] = this;
                _state = Animate3D::Animate3DState::Running;
                _weight = 1.0f;
            }
            else
            {
                s_fadeOutAnimates[target] = action;
                action->_state = Animate3D::Animate3DState::FadeOut;
                action->_accTransTime = 0.0f;
                action->_weight = 1.0f;
                action->_lastTime = 0.f;
                s_runningAnimates.erase(target);
                s_fadeInAnimates[target] = this;
                _accTransTime = 0.0f;
                _state = Animate3D::Animate3DState::FadeIn;
                _weight = 0.f;
                _lastTime = 0.f;
            }
        }
    }
    else
    {
        auto it = s_fadeInAnimates.find(target);
        if (it != s_fadeInAnimates.end())
        {
            s_fadeInAnimates.erase(it);
        }
        s_runningAnimates[target] = this;
        _state = Animate3D::Animate3DState::Running;
        _weight = 1.0f;
    }
}