Beispiel #1
0
        private void SampleAnimation()
        {
            //未开始采样
            if (m_bakeList.Count <= 0)
            {
                return;
            }
            if (null == m_workingInfo)
            {
                //采样完成
                if (m_workingIndex >= m_bakeList.Count)
                {
                    Save();
                    Reset();
                    return;
                }
                m_workingInfo = m_bakeList[m_workingIndex++];
                if (null != m_animator)
                {
                    m_animator.gameObject.SetActive(true);
                    m_animator.Update(0);
                    m_animator.Play(m_workingInfo.Clip.name.ToLower());
                    m_animator.Update(0);
                }
                return;
            }

            if (null != m_workingInfo)
            {
                if (m_workingInfo.CurFrame >= m_workingInfo.TotalFrameNum)
                {
                    m_workingInfo = null;
                    return;
                }

                if (m_workingInfo.CurFrame == 0)
                {
                    m_animator.Update(0);
                }
                else
                {
                    float time = 1.0f / m_workingInfo.TotalFrameNum * m_workingInfo.Clip.length;
                    if (null != m_animator)
                    {
                        m_animator.Update(time);
                    }
                }

                m_workingInfo.ClipData.Frames[m_workingInfo.CurFrame].BoneMatrix = CalculateSkinMatrix(m_bones, m_bindposes);


                m_workingInfo.CurFrame++;
            }
        }
Beispiel #2
0
 void Reset()
 {
     m_clipList.Clear();
     m_animationNameList.Clear();
     m_bakeList.Clear();
     m_fbx = null;
     if (null != m_generatedObject)
     {
         GameObject.DestroyImmediate(m_generatedObject);
         m_generatedObject = null;
     }
     m_animator    = null;
     m_workingInfo = null;
     m_bones       = null;
     m_bindposes   = null;
     if (null != m_skinData)
     {
         m_skinData = null;
     }
     m_workingIndex = 0;
 }
Beispiel #3
0
        private void SampleAllTroopAnimation()
        {
            if (m_fbxBatchList.Count <= 0)
            {
                return;
            }

            //采样下一个troop
            if (m_bakeList.Count <= 0)
            {
                //全部都完成了
                if (m_fbxBatchIndex >= m_fbxBatchList.Count)
                {
                    Debug.Log("导出完成");
                    m_fbxBatchIndex = 0;
                    m_fbxBatchList.Clear();
                    return;
                }
                m_fbx = m_fbxBatchList[m_fbxBatchIndex++];
                LoadSampleAnimationClip();
                if (!CheckAnimationNames())
                {
                    Debug.LogError(m_fbx.name + "存在命名不规范的动画文件,跳过导出。");
                    Reset();
                    return;
                }
                m_generatedObject = GameObject.Instantiate(m_fbx);
                Init();
                m_animator = m_generatedObject.GetComponent <Animator>();
                CreateAnimationController();
                GenerateBakeData();
            }

            if (null == m_workingInfo)
            {
                //采样完成
                if (m_workingIndex >= m_bakeList.Count)
                {
                    Save();
                    Reset();
                    return;
                }
                m_workingInfo = m_bakeList[m_workingIndex++];
                if (null != m_animator)
                {
                    m_animator.gameObject.SetActive(true);
                    m_animator.Update(0);
                    m_animator.Play(m_workingInfo.Clip.name.ToLower());
                    m_animator.Update(0);
                }
                return;
            }

            if (null != m_workingInfo)
            {
                if (m_workingInfo.CurFrame >= m_workingInfo.TotalFrameNum)
                {
                    m_workingInfo = null;
                    return;
                }

                if (m_workingInfo.CurFrame == 0)
                {
                    m_animator.Update(0);
                }
                else
                {
                    float time = 1.0f / m_workingInfo.TotalFrameNum * m_workingInfo.Clip.length;
                    if (null != m_animator)
                    {
                        m_animator.Update(time);
                    }
                }

                m_workingInfo.ClipData.Frames[m_workingInfo.CurFrame].BoneMatrix = CalculateSkinMatrix(m_bones, m_bindposes);

                m_workingInfo.CurFrame++;
            }
        }