예제 #1
0
//----------------------------------------------------------------------------------------------------------------------

        internal void ResetPlayableFrames()
        {
            DestroyPlayableFrames();

            //Recalculate the number of frames and create the marker's ground truth data
            int numFrames = TimelineUtility.CalculateNumFrames(m_clipOwner);

            m_playableFrames = new List <SISPlayableFrame>(numFrames);
            UpdatePlayableFramesSize(numFrames);
        }
//----------------------------------------------------------------------------------------------------------------------

        //Resize PlayableFrames and used the previous values
        internal void RefreshPlayableFrames()
        {
            TimelineClip clipOwner = GetOwner();


            //Clip doesn't have parent. Might be because the clip is being moved
            if (null == clipOwner.GetParentTrack())
            {
                return;
            }

            int numIdealNumPlayableFrames = TimelineUtility.CalculateNumFrames(clipOwner);

            //Change the size of m_playableFrames and reinitialize if necessary
            int prevNumPlayableFrames = m_playableFrames.Count;

            if (numIdealNumPlayableFrames != prevNumPlayableFrames)
            {
                //Change the size of m_playableFrames and reinitialize if necessary
                List <bool> prevUsedFrames = new List <bool>(prevNumPlayableFrames);
                foreach (SISPlayableFrame frame in m_playableFrames)
                {
                    prevUsedFrames.Add(null == frame || frame.IsUsed()); //if frame ==null, just regard as used.
                }

                UpdatePlayableFramesSize(numIdealNumPlayableFrames);

                //Reinitialize
                if (prevNumPlayableFrames > 0)
                {
                    for (int i = 0; i < numIdealNumPlayableFrames; ++i)
                    {
                        int prevIndex = (int)(((float)(i) / numIdealNumPlayableFrames) * prevNumPlayableFrames);
                        m_playableFrames[i].SetUsed(prevUsedFrames[prevIndex]);
                    }
                }
            }

            //Refresh all markers
            double timePerFrame      = TimelineUtility.CalculateTimePerFrame(clipOwner);
            int    numPlayableFrames = m_playableFrames.Count;

            for (int i = 0; i < numPlayableFrames; ++i)
            {
                m_playableFrames[i].SetIndexAndLocalTime(i, i * timePerFrame);
                m_playableFrames[i].Refresh(m_frameMarkersVisibility);
            }
        }
예제 #3
0
//----------------------------------------------------------------------------------------------------------------------

        //Calculate the used image index for the passed localTime
        internal int LocalTimeToImageIndex(TimelineClip clip, double localTime)
        {
            SISClipData clipData = GetBoundClipData();

            if (null == clipData)
            {
                return(0);
            }


            {
                //drop disabled frames
                double scaledTimePerFrame = TimelineUtility.CalculateTimePerFrame(clip) * clip.timeScale;

                //Try to check if this frame is "dropped", so that we should use the image in the prev frame
                int playableFrameIndex = Mathf.RoundToInt((float)(localTime - clip.clipIn) / (float)scaledTimePerFrame);
                if (playableFrameIndex < 0)
                {
                    return(0);
                }

                SISPlayableFrame playableFrame = clipData.GetPlayableFrame(playableFrameIndex);
                while (playableFrameIndex > 0 && !playableFrame.IsUsed())
                {
                    --playableFrameIndex;
                    playableFrame = clipData.GetPlayableFrame(playableFrameIndex);
                    localTime     = playableFrameIndex * scaledTimePerFrame;
                }
            }

            AnimationCurve curve             = clipData.GetAnimationCurve();
            double         imageSequenceTime = curve.Evaluate((float)localTime);

            int count = m_imageFiles.Count;

            //Can't round up, because if the time for the next frame hasn't been reached, then we should stick
            int index = Mathf.FloorToInt(count * (float)imageSequenceTime);

            index = Mathf.Clamp(index, 0, count - 1);
            return(index);
        }
//----------------------------------------------------------------------------------------------------------------------

        private void UpdatePlayableFramesSize(int reqPlayableFramesSize)
        {
            TimelineClip clipOwner = GetOwner();

            Assert.IsNotNull(clipOwner);

            double timePerFrame = TimelineUtility.CalculateTimePerFrame(clipOwner);

            //Resize m_playableFrames
            if (m_playableFrames.Count < reqPlayableFramesSize)
            {
                int numNewPlayableFrames = (reqPlayableFramesSize - m_playableFrames.Count);
                List <SISPlayableFrame> newPlayableFrames = new List <SISPlayableFrame>(numNewPlayableFrames);
                for (int i = m_playableFrames.Count; i < reqPlayableFramesSize; ++i)
                {
                    newPlayableFrames.Add(CreatePlayableFrame(this, i, timePerFrame));
                }
                m_playableFrames.AddRange(newPlayableFrames);
            }

            if (m_playableFrames.Count > reqPlayableFramesSize)
            {
                int numLastPlayableFrames = m_playableFrames.Count;
                for (int i = reqPlayableFramesSize; i < numLastPlayableFrames; ++i)
                {
                    SISPlayableFrame curFrame = m_playableFrames[i];
                    curFrame?.Destroy();
                }
                m_playableFrames.RemoveRange(reqPlayableFramesSize, numLastPlayableFrames - reqPlayableFramesSize);
            }

            Assert.IsTrue(m_playableFrames.Count == reqPlayableFramesSize);

            for (int i = 0; i < reqPlayableFramesSize; ++i)
            {
                SISPlayableFrame curPlayableFrame = m_playableFrames[i];
                Assert.IsNotNull(curPlayableFrame);
                m_playableFrames[i].SetIndexAndLocalTime(i, timePerFrame * i);
            }
        }