Example #1
0
        private void panel1_MouseClick(object sender, MouseEventArgs e)
        {
            if (Program.Viewer.CurrentModel != null)
            {
                MaterialAnimationClip clip = Program.Viewer.CurrentModel.GetData().MaterialAnimationClip;

                if (clip != null)
                {
                    float total = clip.Duration;

                    float step    = total / 50.0f;
                    float stepLen = panel1.Width / 50.0f;



                    for (int i = 0; i < clip.Keyframes.Count; i++)
                    {
                        float  time = clip.Keyframes[i].Time;
                        PointF pa   = new PointF(Time2TimeLineX(time, total), 15);

                        System.Drawing.RectangleF rect = new System.Drawing.RectangleF(pa.X, pa.Y, stepLen, panel1.Height);

                        int x = e.X;
                        int y = e.Y;

                        if (x > rect.Left && x < rect.Right && y > rect.Top && y < rect.Bottom)
                        {
                            SelectKeyFrame(i, clip.Keyframes[i]);
                            return;
                        }
                    }
                }
            }
            SelectKeyFrame(-1, new MaterialAnimationKeyFrame());
        }
Example #2
0
        private void button9_Click(object sender, EventArgs e)
        {
            if (selectedKeyFrame != -1)
            {
                if (Program.Viewer.CurrentModel != null)
                {
                    MaterialAnimationClip clip = Program.Viewer.CurrentModel.GetData().MaterialAnimationClip;

                    if (clip != null)
                    {
                        List <MaterialAnimationKeyFrame> kfs = clip.Keyframes;

                        float time = float.Parse(textBox4.Text);
                        kfs[selectedKeyFrame] = new MaterialAnimationKeyFrame(time, int.Parse(textBox5.Text));


                        for (int i = 0; i < kfs.Count; i++)
                        {
                            if (kfs[i].Time > time)
                            {
                                time = kfs[i].Time;
                            }
                        }
                        clip.SetDuration(time);
                    }
                    Program.Viewer.CurrentModel.PlayAnimation();
                }
                panel1.Invalidate();
            }
        }
Example #3
0
        private void panel1_Paint(object sender, PaintEventArgs e)
        {
            if (Program.Viewer.CurrentModel != null)
            {
                MaterialAnimationClip clip = Program.Viewer.CurrentModel.GetData().MaterialAnimationClip;

                if (clip != null)
                {
                    Graphics g = e.Graphics;
                    g.Clear(Color.White);

                    float total = clip.Duration;

                    float step = total / 50.0f;

                    float stepLen = panel1.Width / 50.0f;

                    for (int i = 0; i < 50; i++)
                    {
                        PointF pa = new PointF(Time2TimeLineX(i * step, total), 0);
                        PointF pb = new PointF(Time2TimeLineX(i * step, total), panel1.Height);
                        g.DrawLine(Pens.Black, pa, pb);
                    }

                    for (int i = 0; i < clip.Keyframes.Count; i++)
                    {
                        float time = clip.Keyframes[i].Time;
                        g.DrawString(TimeSpan.FromSeconds(time).ToString(),
                                     new System.Drawing.Font("S", 8), Brushes.Black, new PointF(Time2TimeLineX(time, total), 0));
                    }

                    g.DrawString(TimeSpan.FromSeconds(total).ToString(),
                                 new System.Drawing.Font("S", 8), Brushes.Black, new PointF(panel1.Width - 25, 0));

                    for (int i = 0; i < clip.Keyframes.Count; i++)
                    {
                        float  time = clip.Keyframes[i].Time;
                        PointF pa   = new PointF(Time2TimeLineX(time, total), 15);
                        //PointF pd = new PointF(Time2TimeLineX(time, total) + stepLen, panel1.Height);

                        System.Drawing.RectangleF rect = new System.Drawing.RectangleF(pa.X, pa.Y, stepLen, panel1.Height);
                        g.FillRectangle(Brushes.Red, rect);
                    }
                }
            }
        }
Example #4
0
        private void button8_Click(object sender, EventArgs e)
        {
            if (Program.Viewer.CurrentModel != null)
            {
                MaterialAnimationClip clip = Program.Viewer.CurrentModel.GetData().MaterialAnimationClip;

                if (clip != null)
                {
                    if (clip.Keyframes.Count <= 2)
                    {
                        Program.Viewer.CurrentModel.GetData().SetMaterialAnimationClip(null);
                    }
                    else
                    {
                        clip.Keyframes.RemoveAt(selectedKeyFrame);
                    }
                }
                Program.Viewer.CurrentModel.ReloadMaterialAnimation();
                Program.Viewer.CurrentModel.PlayAnimation();
            }
            panel1.Invalidate();
        }
Example #5
0
        private void button7_Click(object sender, EventArgs e)
        {
            if (Program.Viewer.CurrentModel != null)
            {
                MaterialAnimationClip clip = Program.Viewer.CurrentModel.GetData().MaterialAnimationClip;

                if (clip != null)
                {
                    List <MaterialAnimationKeyFrame> kfs = clip.Keyframes;

                    float time = kfs[kfs.Count - 1].Time + 0.5f;
                    int   mid  = kfs[kfs.Count - 1].MaterialIndex + 1;
                    kfs.Add(new MaterialAnimationKeyFrame(time, mid));


                    for (int i = 0; i < kfs.Count; i++)
                    {
                        if (kfs[i].Time > time)
                        {
                            time = kfs[i].Time;
                        }
                    }
                    clip.SetDuration(time);
                }
                else
                {
                    List <MaterialAnimationKeyFrame> kfs = new List <MaterialAnimationKeyFrame>();
                    kfs.Add(new MaterialAnimationKeyFrame(0, 0));
                    kfs.Add(new MaterialAnimationKeyFrame(1, 1));

                    clip = new MaterialAnimationClip(1, kfs);
                    Program.Viewer.CurrentModel.GetData().SetMaterialAnimationClip(clip);
                }
                Program.Viewer.CurrentModel.ReloadMaterialAnimation();
                Program.Viewer.CurrentModel.PlayAnimation();
            }
            panel1.Invalidate();
        }