当前位置: 首页>>代码示例>>C++>>正文


C++ AnimatedModel::GetAnimationState方法代码示例

本文整理汇总了C++中AnimatedModel::GetAnimationState方法的典型用法代码示例。如果您正苦于以下问题:C++ AnimatedModel::GetAnimationState方法的具体用法?C++ AnimatedModel::GetAnimationState怎么用?C++ AnimatedModel::GetAnimationState使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AnimatedModel的用法示例。


在下文中一共展示了AnimatedModel::GetAnimationState方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: FadeOthers

bool AnimationController::FadeOthers(const String& name, float targetWeight, float fadeTime)
{
    unsigned index;
    AnimationState* state;
    FindAnimation(name, index, state);
    if (index == M_MAX_UNSIGNED || !state)
        return false;
    
    AnimatedModel* model = GetComponent<AnimatedModel>();
    unsigned char layer = state->GetLayer();
    
    bool needUpdate = false;
    for (unsigned i = 0; i < animations_.Size(); ++i)
    {
        if (i != index)
        {
            AnimationControl& control = animations_[i];
            AnimationState* otherState = model->GetAnimationState(control.hash_);
            if (otherState && otherState->GetLayer() == layer)
            {
                control.targetWeight_ = Clamp(targetWeight, 0.0f, 1.0f);
                control.fadeTime_ = fadeTime;
                needUpdate = true;
            }
        }
    }
    
    if (needUpdate)
        MarkNetworkUpdate();
    return true;
}
开发者ID:acremean,项目名称:urho3d,代码行数:31,代码来源:AnimationController.cpp

示例2: SetStartBone

bool AnimationController::SetStartBone(const String& name, const String& startBoneName)
{
    // Start bone can only be set in model mode
    AnimatedModel* model = GetComponent<AnimatedModel>();
    if (!model)
        return false;

    AnimationState* state = model->GetAnimationState(name);
    if (!state)
        return false;

    Bone* bone = model->GetSkeleton().GetBone(startBoneName);
    state->SetStartBone(bone);
    MarkNetworkUpdate();
    return true;
}
开发者ID:nonconforme,项目名称:Urho3D,代码行数:16,代码来源:AnimationController.cpp

示例3: GetAnimationState

AnimationState* AnimationController::GetAnimationState(StringHash nameHash) const
{
    // Model mode
    AnimatedModel* model = GetComponent<AnimatedModel>();
    if (model)
        return model->GetAnimationState(nameHash);

    // Node hierarchy mode
    for (Vector<SharedPtr<AnimationState> >::ConstIterator i = nodeAnimationStates_.Begin(); i != nodeAnimationStates_.End(); ++i)
    {
        Animation* animation = (*i)->GetAnimation();
        if (animation->GetNameHash() == nameHash || animation->GetAnimationNameHash() == nameHash)
            return *i;
    }

    return 0;
}
开发者ID:nonconforme,项目名称:Urho3D,代码行数:17,代码来源:AnimationController.cpp

示例4: StopLayer

void AnimationController::StopLayer(unsigned char layer, float fadeOutTime)
{
    AnimatedModel* model = GetComponent<AnimatedModel>();
    if (!model)
        return;
    
    bool needUpdate = false;
    for (Vector<AnimationControl>::Iterator i = animations_.Begin(); i != animations_.End(); ++i)
    {
        AnimationState* state = model->GetAnimationState(i->hash_);
        if (state && state->GetLayer() == layer)
        {
            i->targetWeight_ = 0.0f;
            i->fadeTime_ = fadeOutTime;
            needUpdate = true;
        }
    }
    
    if (needUpdate)
        MarkNetworkUpdate();
}
开发者ID:acremean,项目名称:urho3d,代码行数:21,代码来源:AnimationController.cpp

示例5: FindAnimation

void AnimationController::FindAnimation(const String& name, unsigned& index, AnimationState*& state) const
{
    AnimatedModel* model = GetComponent<AnimatedModel>();
    StringHash nameHash(name);
    
    // Find the AnimationState
    state = model ? model->GetAnimationState(nameHash) : 0;
    if (state)
    {
        // Either a resource name or animation name may be specified. We store resource names, so correct the hash if necessary
        nameHash = state->GetAnimation()->GetNameHash();
    }
    
    // Find the internal control structure
    index = M_MAX_UNSIGNED;
    for (unsigned i = 0; i < animations_.Size(); ++i)
    {
        if (animations_[i].hash_ == nameHash)
        {
            index = i;
            break;
        }
    }
}
开发者ID:acremean,项目名称:urho3d,代码行数:24,代码来源:AnimationController.cpp

示例6: FindAnimationState

AnimationState* AnimationController::FindAnimationState(const String& name) const
{
    AnimatedModel* model = GetComponent<AnimatedModel>();
    return model ? model->GetAnimationState(StringHash(name)) : 0;
}
开发者ID:acremean,项目名称:urho3d,代码行数:5,代码来源:AnimationController.cpp

示例7: Update

void AnimationController::Update(float timeStep)
{
    AnimatedModel* model = GetComponent<AnimatedModel>();
    if (!model)
        return;
    
    // Loop through animations
    for (Vector<AnimationControl>::Iterator i = animations_.Begin(); i != animations_.End();)
    {
        bool remove = false;
        AnimationState* state = model->GetAnimationState(i->hash_);
        if (!state)
            remove = true;
        else
        {
            // Advance the animation
            if (i->speed_ != 0.0f)
                state->AddTime(i->speed_ * timeStep);
            
            float targetWeight = i->targetWeight_;
            float fadeTime = i->fadeTime_;
            
            // If non-looped animation at the end, activate autofade as applicable
            if (!state->IsLooped() && state->GetTime() >= state->GetLength() && i->autoFadeTime_ > 0.0f)
            {
                targetWeight = 0.0f;
                fadeTime = i->autoFadeTime_;
            }
            
            // Process weight fade
            float currentWeight = state->GetWeight();
            if (currentWeight != targetWeight)
            {
                if (fadeTime > 0.0f)
                {
                    float weightDelta = 1.0f / fadeTime * timeStep;
                    if (currentWeight < targetWeight)
                        currentWeight = Min(currentWeight + weightDelta, targetWeight);
                    else if (currentWeight > targetWeight)
                        currentWeight = Max(currentWeight - weightDelta, targetWeight);
                    state->SetWeight(currentWeight);
                }
                else
                    state->SetWeight(targetWeight);
            }
            
            // Remove if weight zero and target weight zero
            if (state->GetWeight() == 0.0f && (targetWeight == 0.0f || fadeTime == 0.0f))
                remove = true;
        }
        
        // Decrement the command time-to-live values
        if (i->setTimeTtl_ > 0.0f)
            i->setTimeTtl_ = Max(i->setTimeTtl_ - timeStep, 0.0f);
        if (i->setWeightTtl_ > 0.0f)
            i->setWeightTtl_ = Max(i->setWeightTtl_ - timeStep, 0.0f);
        
        if (remove)
        {
            if (state)
                model->RemoveAnimationState(state);
            i = animations_.Erase(i);
            MarkNetworkUpdate();
        }
        else
            ++i;
    }
}
开发者ID:acremean,项目名称:urho3d,代码行数:68,代码来源:AnimationController.cpp

示例8:

const PODVector<unsigned char>& AnimationController::GetNetAnimationsAttr() const
{
    attrBuffer_.Clear();
    
    AnimatedModel* model = GetComponent<AnimatedModel>();
    if (!model)
    {
        attrBuffer_.WriteVLE(0);
        return attrBuffer_.GetBuffer();
    }
    
    unsigned validAnimations = 0;
    for (Vector<AnimationControl>::ConstIterator i = animations_.Begin(); i != animations_.End(); ++i)
    {
        if (model->GetAnimationState(i->hash_))
            ++validAnimations;
    }
    
    attrBuffer_.WriteVLE(validAnimations);
    for (Vector<AnimationControl>::ConstIterator i = animations_.Begin(); i != animations_.End(); ++i)
    {
        AnimationState* state = model->GetAnimationState(i->hash_);
        if (!state)
            continue;
        
        unsigned char ctrl = 0;
        Bone* startBone = state->GetStartBone();
        if (state->IsLooped())
            ctrl |= CTRL_LOOPED;
        if (startBone && startBone != model->GetSkeleton().GetRootBone())
            ctrl |= CTRL_STARTBONE;
        if (i->autoFadeTime_ > 0.0f)
            ctrl |= CTRL_AUTOFADE;
        if (i->setTimeTtl_ > 0.0f)
            ctrl |= CTRL_SETTIME;
        if (i->setWeightTtl_ > 0.0f)
            ctrl |= CTRL_SETWEIGHT;
        
        attrBuffer_.WriteStringHash(i->hash_);
        attrBuffer_.WriteUByte(ctrl);
        attrBuffer_.WriteUByte(state->GetLayer());
        attrBuffer_.WriteShort((short)Clamp(i->speed_ * 2048.0f, -32767.0f, 32767.0f));
        attrBuffer_.WriteUByte((unsigned char)(i->targetWeight_ * 255.0f));
        attrBuffer_.WriteUByte((unsigned char)Clamp(i->fadeTime_ * 64.0f, 0.0f, 255.0f));
        if (ctrl & CTRL_STARTBONE)
            attrBuffer_.WriteStringHash(startBone->nameHash_);
        if (ctrl & CTRL_AUTOFADE)
            attrBuffer_.WriteUByte((unsigned char)Clamp(i->autoFadeTime_ * 64.0f, 0.0f, 255.0f));
        if (ctrl & CTRL_SETTIME)
        {
            attrBuffer_.WriteUByte(i->setTimeRev_);
            attrBuffer_.WriteUShort(i->setTime_);
        }
        if (ctrl & CTRL_SETWEIGHT)
        {
            attrBuffer_.WriteUByte(i->setWeightRev_);
            attrBuffer_.WriteUByte(i->setWeight_);
        }
    }
    
    return attrBuffer_.GetBuffer();
}
开发者ID:acremean,项目名称:urho3d,代码行数:62,代码来源:AnimationController.cpp

示例9: SetNetAnimationsAttr

void AnimationController::SetNetAnimationsAttr(const PODVector<unsigned char>& value)
{
    // To apply animations, the model must exist first (practically, have been added before AnimationController)
    AnimatedModel* model = GetComponent<AnimatedModel>();
    if (!model)
        return;
    
    MemoryBuffer buf(value);
    
    // Check which animations we need to remove
    HashSet<StringHash> processedAnimations;
    
    unsigned numAnimations = buf.ReadVLE();
    while (numAnimations--)
    {
        StringHash animHash = buf.ReadStringHash();
        processedAnimations.Insert(animHash);
        
        // Check if the animation state exists. If not, add new
        AnimationState* state = model->GetAnimationState(animHash);
        if (!state)
        {
            Animation* newAnimation = GetSubsystem<ResourceCache>()->GetResource<Animation>(animHash);
            state = model->AddAnimationState(newAnimation);
            if (!state)
            {
                LOGERROR("Animation update applying aborted due to unknown animation");
                return;
            }
        }
        // Check if the internal control structure exists. If not, add new
        unsigned index;
        for (index = 0; index < animations_.Size(); ++index)
        {
            if (animations_[index].hash_ == animHash)
                break;
        }
        if (index == animations_.Size())
        {
            AnimationControl newControl;
            newControl.hash_ = animHash;
            animations_.Push(newControl);
        }
        
        unsigned char ctrl = buf.ReadUByte();
        state->SetLayer(buf.ReadUByte());
        state->SetLooped((ctrl & CTRL_LOOPED) != 0);
        animations_[index].speed_ = (float)buf.ReadShort() / 2048.0f; // 11 bits of decimal precision, max. 16x playback speed
        animations_[index].targetWeight_ = (float)buf.ReadUByte() / 255.0f; // 8 bits of decimal precision
        animations_[index].fadeTime_ = (float)buf.ReadUByte() / 64.0f; // 6 bits of decimal precision, max. 4 seconds fade
        if (ctrl & CTRL_STARTBONE)
            state->SetStartBone(model->GetSkeleton().GetBone(buf.ReadStringHash()));
        else
            state->SetStartBone(0);
        if (ctrl & CTRL_AUTOFADE)
            animations_[index].autoFadeTime_ = (float)buf.ReadUByte() / 64.0f; // 6 bits of decimal precision, max. 4 seconds fade
        else
            animations_[index].autoFadeTime_ = 0.0f;
        if (ctrl & CTRL_SETTIME)
        {
            unsigned char setTimeRev = buf.ReadUByte();
            unsigned short setTime = buf.ReadUShort();
            // Apply set time command only if revision differs
            if (setTimeRev != animations_[index].setTimeRev_)
            {
                state->SetTime(((float)setTime / 65535.0f) * state->GetLength());
                animations_[index].setTimeRev_ = setTimeRev;
            }
        }
        if (ctrl & CTRL_SETWEIGHT)
        {
            unsigned char setWeightRev = buf.ReadUByte();
            unsigned char setWeight = buf.ReadUByte();
            // Apply set weight command only if revision differs
            if (setWeightRev != animations_[index].setWeightRev_)
            {
                state->SetWeight((float)setWeight / 255.0f);
                animations_[index].setWeightRev_ = setWeightRev;
            }
        }
    }
    
    // Set any extra animations to fade out
    for (Vector<AnimationControl>::Iterator i = animations_.Begin(); i != animations_.End(); ++i)
    {
        if (!processedAnimations.Contains(i->hash_))
        {
            i->targetWeight_ = 0.0f;
            i->fadeTime_ = EXTRA_ANIM_FADEOUT_TIME;
        }
    }
}
开发者ID:acremean,项目名称:urho3d,代码行数:92,代码来源:AnimationController.cpp


注:本文中的AnimatedModel::GetAnimationState方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。