Exemple #1
0
 /// <summary>
 /// Stop playback.
 /// </summary>
 public void Stop()
 {
     if (m_entity == null)
     {
         return;
     }
     m_playMode  = Anima.Playback.HALT;
     m_playMode2 = Anima.Playback.HALT;
 }
Exemple #2
0
 /// <summary>
 /// Pause playback.
 /// </summary>
 public void Pause()
 {
     if (m_entity == null)
     {
         return;
     }
     if (m_playMode == Anima.Playback.HALT)
     {
         return;
     }
     m_playMode2 = m_playMode;
     m_playMode  = Anima.Playback.HALT;
 }
Exemple #3
0
        private void ProcAutoAnimation()
        {
            if (!m_enabled)
            {
                return;
            }

            if (m_seq == null)
            {
                m_playMode  = Anima.Playback.HALT;
                m_playMode2 = Anima.Playback.HALT;
                return;
            }

            // Get keyframe and apply transformation
            AnimaSeqBase.Keyframe sframe;
            m_lastCursorPos = (int)m_cursorPos;
            if (!m_seq.GetKeyframeData(m_lastCursorPos, out sframe))
            {
                m_playMode  = Anima.Playback.HALT;
                m_playMode2 = Anima.Playback.HALT;
                return;
            }

            // Smooth animation
            if (m_smoothAnim)
            {
                AnimaSeqBase.Keyframe sframe2;
                if (!m_seq.GetKeyframeData(m_lastCursorPos + 1, out sframe2))
                {
                    m_playMode  = Anima.Playback.HALT;
                    m_playMode2 = Anima.Playback.HALT;
                    return;
                }
                float lerpValue = m_cursorPos - (float)m_lastCursorPos;
                sframe.position = Vector3.Lerp(sframe.position, sframe2.position, lerpValue);
                sframe.rotation = Quaternion.Lerp(sframe.rotation, sframe2.rotation, lerpValue);
                sframe.scale    = Vector3.Lerp(sframe.scale, sframe2.scale, lerpValue);
            }

            // Apply trasformation
            m_position = sframe.position;
            m_rotation = sframe.rotation;
            m_scale    = sframe.scale;
            if (m_onTransform != null)
            {
                m_onTransform(this);
            }
            m_entity.PositionComp.LocalMatrix = Matrix.CreateFromTransformScale(m_rotation, m_position, m_scale);
        }
Exemple #4
0
 /// <summary>
 /// Resume playback.
 /// </summary>
 public void Resume()
 {
     if (m_entity == null)
     {
         return;
     }
     if (m_playMode != Anima.Playback.HALT)
     {
         return;
     }
     m_playMode = m_playMode2;
     if (m_playMode != Anima.Playback.HALT)
     {
         ProcAutoAnimation();
     }
 }
Exemple #5
0
 /// <summary>
 /// Start playback.
 /// </summary>
 /// <param name="playMode">any of playback mode, enum of Anima.Playback.</param>
 /// <param name="cursorPos">starting cursor position (in keyframes).</param>
 /// <remarks>cursor position will be clamped to animation range.</remarks>
 public void Play(Anima.Playback playMode, float cursorPos = 0f)
 {
     if (m_entity == null || m_seq == null)
     {
         return;
     }
     m_playMode  = playMode;
     m_playMode2 = playMode;
     if (cursorPos < m_seq.FrameStart)
     {
         cursorPos = m_seq.FrameStart;
     }
     else if (cursorPos > m_seq.FrameEnd)
     {
         cursorPos = m_seq.FrameEnd;
     }
     m_cursorPos = cursorPos;
     ProcAutoAnimation();
 }
Exemple #6
0
 /// <summary>
 /// Start playback with normalized cursor.
 /// </summary>
 /// <param name="playMode">any of playback mode, enum of Anima.Playback.</param>
 /// <param name="cursorPos">starting cursor position (normalized between 0 to 1).</param>
 /// <remarks>cursor position will be clamped to animation range.</remarks>
 public void PlayNormal(Anima.Playback playMode, float cursorPos = 0f)
 {
     if (m_entity == null || m_seq == null)
     {
         return;
     }
     m_playMode  = playMode;
     m_playMode2 = playMode;
     if (cursorPos < 0f)
     {
         cursorPos = 0f;
     }
     else if (cursorPos > 1f)
     {
         cursorPos = 1f;
     }
     m_cursorPos = cursorPos * m_seq.FramePeriod + m_seq.FrameStart;
     ProcAutoAnimation();
 }
Exemple #7
0
 /// <summary>
 /// Anima main class constructor.
 /// </summary>
 public AnimaPart(Anima anima, AnimaPart parent, MyEntity entity)
 {
     m_anima            = anima;
     m_entity           = entity;
     m_parent           = parent;
     m_smoothAnim       = false;
     m_enabled          = true;
     m_visible          = true;
     m_onTransform      = null;
     m_onComplete       = null;
     m_seq              = null;
     m_playMode         = Anima.Playback.HALT;
     m_playMode2        = Anima.Playback.HALT;
     m_cursorPos        = 0f;
     m_speed            = 1f;
     m_lastCursorPos    = 0;
     m_disableRootColor = false;
     m_position         = Vector3.Zero;
     m_rotation         = Quaternion.Identity;
     m_scale            = Vector3.One;
 }
Exemple #8
0
        /// <summary>
        /// Process the animation.
        /// </summary>
        /// <param name="elapsedTime">period elapsed since last call (in seconds).</param>
        /// <returns>true on success</returns>
        public void Update(double elapsedTime)
        {
            if (m_entity == null)
            {
                return;
            }

            float elapsed = (float)elapsedTime;

            if (elapsed == 0f || !m_enabled)
            {
                return;
            }

            // Apply root color
            if (!m_disableRootColor)
            {
                m_entity.Render.ColorMaskHsv = m_anima.Entity.Render.ColorMaskHsv;
            }

            // Apply animation
            if (m_playMode != Anima.Playback.HALT)
            {
                if (m_seq == null)
                {
                    m_playMode  = Anima.Playback.HALT;
                    m_playMode2 = Anima.Playback.HALT;
                    return;
                }

                // Timelapse
                bool callLoop = false;
                m_cursorPos += elapsed * m_seq.FrameRate * m_speed;
                if (m_cursorPos < m_seq.FrameStart || m_cursorPos >= (m_seq.FrameEnd + 1f))
                {
                    if (m_playMode == Anima.Playback.ONCE)
                    {
                        m_playMode  = Anima.Playback.HALT;
                        m_playMode2 = Anima.Playback.HALT;
                    }
                    else if (m_playMode == Anima.Playback.PINGPONG)
                    {
                        m_speed = -m_speed;
                    }
                    float newPos = (m_cursorPos - m_seq.FrameStart) % m_seq.FramePeriod;
                    if (newPos < 0f)
                    {
                        newPos = m_seq.FramePeriod + newPos;
                    }
                    m_cursorPos = newPos + m_seq.FrameStart;
                    callLoop    = true;
                }

                // Call callback
                if (callLoop && m_onComplete != null)
                {
                    m_onComplete(this);
                }

                // Get keyframe and apply transformation if needed
                if (m_smoothAnim || ((int)m_cursorPos != m_lastCursorPos))
                {
                    ProcAutoAnimation();
                }
            }
        }
Exemple #9
0
        private void ProcAutoAnimation()
        {
            if (!m_enabled) return;

            if (m_seq == null)
            {
                m_playMode = Anima.Playback.HALT;
                m_playMode2 = Anima.Playback.HALT;
                return;
            }

            // Get keyframe and apply transformation
            AnimaSeqBase.Keyframe sframe;
            m_lastCursorPos = (int)m_cursorPos;
            if (!m_seq.GetKeyframeData(m_lastCursorPos, out sframe))
            {
                m_playMode = Anima.Playback.HALT;
                m_playMode2 = Anima.Playback.HALT;
                return;
            }

            // Smooth animation
            if (m_smoothAnim)
            {
                AnimaSeqBase.Keyframe sframe2;
                if (!m_seq.GetKeyframeData(m_lastCursorPos + 1, out sframe2))
                {
                    m_playMode = Anima.Playback.HALT;
                    m_playMode2 = Anima.Playback.HALT;
                    return;
                }
                float lerpValue = m_cursorPos - (float)m_lastCursorPos;
                sframe.position = Vector3.Lerp(sframe.position, sframe2.position, lerpValue);
                sframe.rotation = Quaternion.Lerp(sframe.rotation, sframe2.rotation, lerpValue);
                sframe.scale = Vector3.Lerp(sframe.scale, sframe2.scale, lerpValue);
            }

            // Apply trasformation
            m_position = sframe.position;
            m_rotation = sframe.rotation;
            m_scale = sframe.scale;
            if (m_onTransform != null) m_onTransform(this);
            m_entity.PositionComp.LocalMatrix = Matrix.CreateFromTransformScale(m_rotation, m_position, m_scale);
        }
Exemple #10
0
 /// <summary>
 /// Pause playback.
 /// </summary>
 public void Pause()
 {
     if (m_entity == null) return;
     if (m_playMode == Anima.Playback.HALT) return;
     m_playMode2 = m_playMode;
     m_playMode = Anima.Playback.HALT;
 }
Exemple #11
0
        /// <summary>
        /// Process the animation.
        /// </summary>
        /// <param name="elapsedTime">period elapsed since last call (in seconds).</param>
        /// <returns>true on success</returns>
        public void Update(double elapsedTime)
        {
            if (m_entity == null) return;

            float elapsed = (float)elapsedTime;
            if (elapsed == 0f || !m_enabled) return;

            // Apply root color
            if (!m_disableRootColor)
            {
                m_entity.Render.ColorMaskHsv = m_anima.Entity.Render.ColorMaskHsv;
            }

            // Apply animation
            if (m_playMode != Anima.Playback.HALT)
            {
                if (m_seq == null)
                {
                    m_playMode = Anima.Playback.HALT;
                    m_playMode2 = Anima.Playback.HALT;
                    return;
                }

                // Timelapse
                bool callLoop = false;
                m_cursorPos += elapsed * m_seq.FrameRate * m_speed;
                if (m_cursorPos < m_seq.FrameStart || m_cursorPos >= (m_seq.FrameEnd + 1f))
                {
                    if (m_playMode == Anima.Playback.ONCE)
                    {
                        m_playMode = Anima.Playback.HALT;
                        m_playMode2 = Anima.Playback.HALT;
                    }
                    else if (m_playMode == Anima.Playback.PINGPONG)
                    {
                        m_speed = -m_speed;
                    }
                    float newPos = (m_cursorPos - m_seq.FrameStart) % m_seq.FramePeriod;
                    if (newPos < 0f) newPos = m_seq.FramePeriod + newPos;
                    m_cursorPos = newPos + m_seq.FrameStart;
                    callLoop = true;
                }

                // Call callback
                if (callLoop && m_onComplete != null) m_onComplete(this);

                // Get keyframe and apply transformation if needed
                if (m_smoothAnim || ((int)m_cursorPos != m_lastCursorPos)) ProcAutoAnimation();
            }
        }
Exemple #12
0
 /// <summary>
 /// Resume playback.
 /// </summary>
 public void Resume()
 {
     if (m_entity == null) return;
     if (m_playMode != Anima.Playback.HALT) return;
     m_playMode = m_playMode2;
     if (m_playMode != Anima.Playback.HALT) ProcAutoAnimation();
 }
Exemple #13
0
 /// <summary>
 /// Stop playback.
 /// </summary>
 public void Stop()
 {
     if (m_entity == null) return;
     m_playMode = Anima.Playback.HALT;
     m_playMode2 = Anima.Playback.HALT;
 }
Exemple #14
0
 /// <summary>
 /// Start playback with normalized cursor.
 /// </summary>
 /// <param name="playMode">any of playback mode, enum of Anima.Playback.</param>
 /// <param name="cursorPos">starting cursor position (normalized between 0 to 1).</param>
 /// <remarks>cursor position will be clamped to animation range.</remarks>
 public void PlayNormal(Anima.Playback playMode, float cursorPos = 0f)
 {
     if (m_entity == null || m_seq == null) return;
     m_playMode = playMode;
     m_playMode2 = playMode;
     if (cursorPos < 0f) cursorPos = 0f;
     else if (cursorPos > 1f) cursorPos = 1f;
     m_cursorPos = cursorPos * m_seq.FramePeriod + m_seq.FrameStart;
     ProcAutoAnimation();
 }
Exemple #15
0
 /// <summary>
 /// Start playback.
 /// </summary>
 /// <param name="playMode">any of playback mode, enum of Anima.Playback.</param>
 /// <param name="cursorPos">starting cursor position (in keyframes).</param>
 /// <remarks>cursor position will be clamped to animation range.</remarks>
 public void Play(Anima.Playback playMode, float cursorPos = 0f)
 {
     if (m_entity == null || m_seq == null) return;
     m_playMode = playMode;
     m_playMode2 = playMode;
     if (cursorPos < m_seq.FrameStart) cursorPos = m_seq.FrameStart;
     else if (cursorPos > m_seq.FrameEnd) cursorPos = m_seq.FrameEnd;
     m_cursorPos = cursorPos;
     ProcAutoAnimation();
 }
Exemple #16
0
 /// <summary>
 /// Anima main class constructor.
 /// </summary>
 public AnimaPart(Anima anima, AnimaPart parent, MyEntity entity)
 {
     m_anima = anima;
     m_entity = entity;
     m_parent = parent;
     m_smoothAnim = false;
     m_enabled = true;
     m_visible = true;
     m_onTransform = null;
     m_onComplete = null;
     m_seq = null;
     m_playMode = Anima.Playback.HALT;
     m_playMode2 = Anima.Playback.HALT;
     m_cursorPos = 0f;
     m_speed = 1f;
     m_lastCursorPos = 0;
     m_disableRootColor = false;
     m_position = Vector3.Zero;
     m_rotation = Quaternion.Identity;
     m_scale = Vector3.One;
 }