void AnimationState::addMixingTransform(const String &timelineName, int type , bool recursive) { if(_clip && _clip->getTimeline(timelineName)) { if(recursive) { int i = _armature->_boneList.size(); Bone* bone; Bone* currentBone; while(i --) { bone = _armature->_boneList[i]; if(bone->name == timelineName) { currentBone = bone; } if(currentBone && (currentBone == bone || currentBone->contains(bone))) { _mixingTransforms[bone->name] = type; } } } else { _mixingTransforms[timelineName] = type; } updateTimelineStates(); } else { // TODO(hejiangzhou): Shall we disable exception? throw std::invalid_argument("argument error"); } }
/** @private */ void AnimationState::fadeIn(Armature * armature, AnimationData * clip, Number fadeInTime, Number timeScale, int loop, uint layer, bool inDisplayControl, bool pauseBeforeFadeInComplete) { _armature = armature; _clip = clip; name = _clip->name; _layer = layer; _totalTime = _clip->duration; if(round(_clip->duration * _clip->frameRate) < 2 || timeScale == Infinite) { _timeScale = 1; _currentTime = _totalTime; if(_loop >= 0) { _loop = 1; } else { _loop = -1; } } else { _timeScale = timeScale; _currentTime = 0; _loop = loop; } if(pauseBeforeFadeInComplete) { _pauseBeforeFadeInCompleteState = -1; } else { _pauseBeforeFadeInCompleteState = 1; } _fadeInTime = fadeInTime * _timeScale; _loopCount = -1; _fadeState = 1; _fadeOutBeginTime = 0; _fadeOutWeight = -1; _fadeWeight = 0; _isPlaying = true; _isComplete = false; _fadeIn = true; _fadeOut = false; displayControl = inDisplayControl; weight = 1; blend = true; tweenEnabled = true; updateTimelineStates(); }
void AnimationState::fadeIn(Armature *armature, AnimationData *clip, float fadeTotalTime, float timeScale, int playTimes, bool pausePlayhead) { _armature = armature; _clip = clip; _pausePlayheadInFade = pausePlayhead; _totalTime = _clip->duration; autoTween = _clip->autoTween; name = _clip->name; setTimeScale(timeScale); setPlayTimes(playTimes); // reset _isComplete = false; _currentFrameIndex = -1; _currentPlayTimes = -1; if (round(_totalTime * 0.001f * _clip->frameRate) < 2) { _currentTime = _totalTime; } else { _currentTime = -1; } _time = 0.f; _mixingTransforms.clear(); // fade start _isFadeOut = false; _fadeWeight = 0.f; _fadeTotalWeight = 1.f; _fadeCurrentTime = 0.f; _fadeBeginTime = _fadeCurrentTime; _fadeTotalTime = fadeTotalTime * _timeScale; _fadeState = FadeState::FADE_BEFORE; // default _isPlaying = true; displayControl = true; lastFrameAutoTween = true; additiveBlending = false; weight = 1.f; fadeOutTime = fadeTotalTime; updateTimelineStates(); }
AnimationState* AnimationState::removeMixingTransform(const std::string &timelineName, bool recursive) { if (recursive) { Bone *currentBone = nullptr; // From root to leaf for (size_t i = _armature->getBones().size(); i--;) { Bone *bone = _armature->getBones()[i]; if (bone->name == timelineName) { currentBone = bone; } if (currentBone && (currentBone == bone || currentBone->contains(bone))) { auto iterator = std::find(_mixingTransforms.begin(), _mixingTransforms.end(), bone->name); if (iterator != _mixingTransforms.end()) { _mixingTransforms.erase(iterator); } } } } else { auto iterator = std::find(_mixingTransforms.begin(), _mixingTransforms.end(), timelineName); if (iterator != _mixingTransforms.end()) { _mixingTransforms.erase(iterator); } } updateTimelineStates(); return this; }
void AnimationState::removeMixingTransform(const String &timelineName , bool recursive) { if(!timelineName.empty()) { if(recursive) { int i = _armature->_boneList.size(); Bone* bone; Bone* currentBone; while(i --) { bone = _armature->_boneList[i]; if(bone->name == timelineName) { currentBone = bone; } if(currentBone && (currentBone == bone || currentBone->contains(bone))) { std::map<String , int>::iterator iter = _mixingTransforms.find(bone->name); if(iter != _mixingTransforms.end()) { _mixingTransforms.erase(iter); } } } } else { std::map<String , int>::iterator iter = _mixingTransforms.find(timelineName); if(iter != _mixingTransforms.end()) { _mixingTransforms.erase(iter); } } } updateTimelineStates(); }
AnimationState* AnimationState::addMixingTransform(const std::string &timelineName, bool recursive) { if (recursive) { Bone *currentBone = nullptr; // From root to leaf for (size_t i = _armature->getBones().size(); i--;) { Bone *bone = _armature->getBones()[i]; const std::string &boneName = bone->name; if (boneName == timelineName) { currentBone = bone; } if ( currentBone && (currentBone == bone || currentBone->contains(bone)) && _clip->getTimeline(boneName) && std::find(_mixingTransforms.cbegin(), _mixingTransforms.cend(), boneName) == _mixingTransforms.cend() ) { _mixingTransforms.push_back(boneName); } } } else if ( _clip->getTimeline(timelineName) && std::find(_mixingTransforms.cbegin(), _mixingTransforms.cend(), timelineName) == _mixingTransforms.cend() ) { _mixingTransforms.push_back(timelineName); } updateTimelineStates(); return this; }
AnimationState* AnimationState::removeAllMixingTransform() { _mixingTransforms.clear(); updateTimelineStates(); return this; }