internal void _SetSequence(Sequence seq, float toPos) { Shape shape = _shapeInstance.GetShape(); Assert.Fatal(shape != null && toPos >= 0.0f && toPos <= 1.0f, "Thread.SetSequence - Invalid shape handle, sequence number, or position."); _shapeInstance.ClearTransition(this); _sequence = seq; _priority = _sequence.Priority; _pos = toPos; _makePath = _sequence.MakePath(); // 1.0f doesn't exist on cyclic sequences if (_pos > 0.9999f && _sequence.IsCyclic()) _pos = 0.9999f; // select keyframes _SelectKeyframes(_pos, _sequence, out _keyNum1, out _keyNum2, out _keyPos); }
void _SelectKeyframes(float pos, Sequence seq, out int k1, out int k2, out float kpos) { Shape shape = _shapeInstance.GetShape(); int numKF = seq.KeyframeCount; float kf; if (seq.IsCyclic()) { // cyclic _sequence: // _pos=0 and _pos=1 are equivalent, so we don't have a keyframe at _pos=1 // last keyframe corresponds to _pos=n/(n-1) up to (not including) _pos=1 // (where n == num keyframes) Assert.Fatal(pos >= 0.0f && pos < 1.0f, "Thread.SelectKeyframes - Invalid thread position."); kf = pos * (float)(numKF); // Set _keyPos kpos = kf - (int)kf; // make sure compiler doing what we want... Assert.Fatal(kpos >= 0.0f && kpos < 1.0f, "Thread.SelectKeyframes - Invalid thread position."); int kfIdx1 = (int)kf; // following assert could happen if pos1<1 && pos1==1...paradoxically... Assert.Fatal(kfIdx1 <= seq.KeyframeCount, "Thread.SelectKeyframes - Invalid keyframe."); int kfIdx2 = (kfIdx1 == seq.KeyframeCount - 1) ? 0 : kfIdx1 + 1; k1 = kfIdx1; k2 = kfIdx2; } else { // one-shot _sequence: // _pos=0 and _pos=1 are now different, so we have a keyframe at _pos=1 // last keyframe corresponds to _pos=1 // rest of the keyframes are equally spaced (so 1/(n-1) _pos units long) // (where n == num keyframes) Assert.Fatal(pos >= 0.0f && pos <= 1.0f, "Thread.SelectKeyframes - Invalid thread position."); if (pos == 1.0f) { kpos = 0.0f; k1 = seq.KeyframeCount - 1; k2 = seq.KeyframeCount - 1; } else { kf = pos * (float)(numKF - 1); // Set _keyPos kpos = kf - (int)kf; int kfIdx1 = (int)kf; // following assert could happen if pos1<1 && pos1==1...paradoxically... Assert.Fatal(kfIdx1 < seq.KeyframeCount, "TSThread.SelectKeyFrames - Invalid keyframe."); int kfIdx2 = kfIdx1 + 1; k1 = kfIdx1; k2 = kfIdx2; } } }
/// <summary> /// Sets a new sequence on the thread by transitioning to it. /// </summary> /// <param name="seq">The sequence to transition to.</param> /// <param name="toPos">The position of the new sequence to start at.</param> /// <param name="duration">The length of the transition.</param> /// <param name="continuePlay">Whether or not to continue playing the thread.</param> public void TransitionToSequence(Sequence seq, float toPos, float duration, bool continuePlay) { Assert.Fatal(duration > 0.0f, "Thread.TransitionToSequence - Must pass a positive non zero duration."); Shape shape = _shapeInstance.GetShape(); // make sure these nodes are smoothly interpolated to new positions... // basically, any node we controlled just prior to transition, or at any stage // of the transition is interpolated. If we _start to transtion from A to B, // but before reaching B we transtion to C, we Interpolate all nodes controlled // by A, B, or C to their new position. if (_transitionData._inTransition) { _transitionData._oldRotationNodes.Overlap(_sequence.DoesRotationMatter); _transitionData._oldTranslationNodes.Overlap(_sequence.DoesTranslationMatter); _transitionData._oldScaleNodes.Overlap(_sequence.DoesScaleMatter); } else { _transitionData._oldRotationNodes.Copy(ref _sequence.DoesRotationMatter); _transitionData._oldTranslationNodes.Copy(ref _sequence.DoesTranslationMatter); _transitionData._oldScaleNodes.Copy(ref _sequence.DoesScaleMatter); } // Set time characteristics of transition _transitionData._oldSequence = _sequence; _transitionData._oldPos = _pos; _transitionData._duration = duration; _transitionData._pos = 0.0f; _transitionData._direction = _timeScale > 0.0f ? 1.0f : -1.0f; _transitionData._targetScale = continuePlay ? 1.0f : 0.0f; // in transition... _transitionData._inTransition = true; // Set target _sequence data _sequence = seq; _priority = _sequence.Priority; _pos = toPos; _makePath = _sequence.MakePath(); // 1.0f doesn't exist on cyclic sequences if (_pos > 0.9999f && _sequence.IsCyclic()) _pos = 0.9999f; // select keyframes _SelectKeyframes(_pos, _sequence, out _keyNum1, out _keyNum2, out _keyPos); }