Пример #1
0
    void DiMotion::ApplySkeletonAnimation( DiSkeletonInstance* skel, DiClipControllerSet* clipset )
    {
        if (!GetNumAnimations())
        {
            return;
        }

        skel->Reset();

        float weightFactor = 1.0f;
        if (skel->GetBlendMode() == ANIMBLEND_AVERAGE)
        {
            float totalWeights = 0.0f;
            ConstEnabledClipsIt stateIt = 
                clipset->GetEnabledClipsIterator();
            while (stateIt.HasMoreElements())
            {
                const DiClipController* animState = stateIt.GetNext();
                totalWeights += animState->GetWeight();
            }

            if (totalWeights > 1.0f)
            {
                weightFactor = 1.0f / totalWeights;
            }
        }

        ConstEnabledClipsIt stateIt = 
            clipset->GetEnabledClipsIterator();
        while (stateIt.HasMoreElements())
        {
            const DiClipController* animState = stateIt.GetNext();

            DiAnimation* anima = GetAnimation(animState->GetAnimationName());

            if( anima )
            {
                DiTimeIndex timeIndex = anima->GetTimeIndex(animState->GetTimePosition());

                if(animState->HasBoneBlendMask())
                {
                    anima->ApplySkeleton(skel, timeIndex, 
                        animState->GetWeight() * weightFactor,
                        animState->GetBoneBlendMask(), 1.0f);
                }
                else
                {
                    anima->ApplySkeleton(skel, timeIndex, 
                        animState->GetWeight() * weightFactor, 1.0f);
                }
            }
        }
    }
Пример #2
0
 /// \brief
 ///   Creates a new animation and returns a reference to it (same as implicitly adding a new animation)
 ///
 /// \param name
 ///   Name of new animation
 ///
 /// \return
 ///   Reference to newly created animation
 inline VGAnimation<KeyPolicy>&        CreateAnimation(const VString& name="")       { AddAnimation(VGAnimation<KeyPolicy>(name)); return GetAnimation(GetNumAnimations()-1); }//@@@test
Пример #3
0
// MSGRECEIVE
// receive trigger messages
bool plAGMasterMod::MsgReceive(plMessage* msg)
{
    plSDLNotificationMsg* nMsg = plSDLNotificationMsg::ConvertNoRef(msg);
    if (nMsg)
    {
        // Force a single eval
        plgDispatch::Dispatch()->RegisterForExactType(plEvalMsg::Index(), GetKey());
        return true;
    }

    plAnimCmdMsg* cmdMsg = plAnimCmdMsg::ConvertNoRef(msg);
    if (cmdMsg)
    {
        plString targetName = cmdMsg->GetAnimName();

        if (targetName.IsNull())
            targetName = ENTIRE_ANIMATION_NAME;

        plAGAnimInstance *inst = FindAnimInstance(targetName);
        if (inst != nil)
        {
            if (cmdMsg->CmdChangesAnimTime())
            {
                for (int i = 0; i < GetNumAnimations(); i++)
                {
                    plAGAnimInstance *currInst = GetAnimInstance(i);
                    if (currInst != inst && currInst->GetAnimation()->SharesPinsWith(inst->GetAnimation()))
                        currInst->SetBlend(0);
                }
                inst->SetBlend(1);
            }

            inst->HandleCmd(cmdMsg);
        }

        return true;
    }

    plAGCmdMsg* agMsg = plAGCmdMsg::ConvertNoRef(msg);
    if (agMsg)
    {
        if (agMsg->Cmd(plAGCmdMsg::kSetAnimTime))
        {
            for (int i = 0; i < fAnimInstances.size(); i++)
            {
                plAGAnimInstance *inst = fAnimInstances[i];
                inst->SetCurrentTime(agMsg->fAnimTime, true);
            }

            return true;
        }

        plAGAnimInstance *inst = FindAnimInstance(agMsg->GetAnimName());
        if (inst != nil)
        {
            if (agMsg->Cmd(plAGCmdMsg::kSetBlend))
                inst->Fade(agMsg->fBlend, agMsg->fBlendRate, plAGAnimInstance::kFadeBlend);
            if (agMsg->Cmd(plAGCmdMsg::kSetAmp))
                inst->Fade(agMsg->fAmp, agMsg->fAmpRate, plAGAnimInstance::kFadeAmp);
        }
        return true;
    }

    plAGInstanceCallbackMsg *agicMsg = plAGInstanceCallbackMsg::ConvertNoRef(msg);
    if (agicMsg)
    {
        if (agicMsg->fEvent == kStart)
        {
            IRegForEval(true);
        }
        else if (agicMsg->fEvent == kStop)
        {
            if (!HasRunningAnims())
                IRegForEval(false);
        }
        else // Just force a single eval
        {
            plgDispatch::Dispatch()->RegisterForExactType(plEvalMsg::Index(), GetKey());
        }
        return true;
    }

    plAGDetachCallbackMsg *detachMsg = plAGDetachCallbackMsg::ConvertNoRef(msg);
    if (detachMsg)
    {
        DetachAnimation(detachMsg->GetAnimName());
    }

    plGenRefMsg *genRefMsg = plGenRefMsg::ConvertNoRef(msg);
    if (genRefMsg)
    {
        plAGAnim *anim = plAGAnim::ConvertNoRef(genRefMsg->GetRef());
        if (anim)
        {
            if (genRefMsg->GetContext() & (plRefMsg::kOnCreate|plRefMsg::kOnRequest))
            {
                if (genRefMsg->fType == kPrivateAnim)
                    fPrivateAnims.push_back(anim);
            }
            else
            {
                if (genRefMsg->fType == kPrivateAnim)
                {
                    plAnimVector::iterator i = fPrivateAnims.begin();
                    for ( ; i != fPrivateAnims.end(); i++)
                    {
                        plAGAnim *currAnim = *i;

                        if(currAnim == anim)
                        {
                            i = fPrivateAnims.erase(i);
                            break;
                        }
                    }
                }
            }

            return true;
        }

        plAGModifier *agmod = plAGModifier::ConvertNoRef(genRefMsg->GetRef());
        if (agmod)
        {
            if (genRefMsg->GetContext() & (plRefMsg::kOnCreate|plRefMsg::kOnRequest))
                fChannelMods[agmod->GetChannelName()] = agmod;
            else
                fChannelMods.erase(agmod->GetChannelName());

            return true;
        }

        plMsgForwarder *msgfwd = plMsgForwarder::ConvertNoRef(genRefMsg->GetRef());
        if (msgfwd)
        {
            if (genRefMsg->GetContext() & (plRefMsg::kOnCreate|plRefMsg::kOnRequest))
                fMsgForwarder = msgfwd;
            else
                fMsgForwarder = nil;

            return true;
        }
    }

    plRefMsg* refMsg = plRefMsg::ConvertNoRef(msg);
    if (refMsg)
    {
        if( refMsg->GetContext() & (plRefMsg::kOnCreate|plRefMsg::kOnRequest|plRefMsg::kOnReplace) )
            AddTarget(plSceneObject::ConvertNoRef(refMsg->GetRef()));
        else
            RemoveTarget(plSceneObject::ConvertNoRef(refMsg->GetRef()));

        return true;
    }

    return plModifier::MsgReceive(msg);
}